Skip to content

Commit 8277d73

Browse files
author
git apple-llvm automerger
committed
Merge commit 'd41f263a5bcf' from swift/release/5.9 into stable/20221013
2 parents 8ef0b2a + d41f263 commit 8277d73

16 files changed

+326
-12
lines changed

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2459,7 +2459,11 @@ void CGDebugInfo::completeClass(const RecordDecl *RD) {
24592459
auto I = TypeCache.find(TyPtr);
24602460
if (I != TypeCache.end() && !cast<llvm::DIType>(I->second)->isForwardDecl())
24612461
return;
2462-
llvm::DIType *Res = CreateTypeDefinition(Ty->castAs<RecordType>());
2462+
2463+
// We want the canonical definition of the structure to not
2464+
// be the typedef. Since that would lead to circular typedef
2465+
// metadata.
2466+
auto [Res, PrefRes] = CreateTypeDefinition(Ty->castAs<RecordType>());
24632467
assert(!Res->isForwardDecl());
24642468
TypeCache[TyPtr].reset(Res);
24652469
}
@@ -2570,10 +2574,25 @@ llvm::DIType *CGDebugInfo::CreateType(const RecordType *Ty) {
25702574
return T;
25712575
}
25722576

2573-
return CreateTypeDefinition(Ty);
2577+
auto [Def, Pref] = CreateTypeDefinition(Ty);
2578+
2579+
return Pref ? Pref : Def;
25742580
}
25752581

2576-
llvm::DIType *CGDebugInfo::CreateTypeDefinition(const RecordType *Ty) {
2582+
llvm::DIType *CGDebugInfo::GetPreferredNameType(const CXXRecordDecl *RD,
2583+
llvm::DIFile *Unit) {
2584+
if (!RD)
2585+
return nullptr;
2586+
2587+
auto const *PNA = RD->getAttr<PreferredNameAttr>();
2588+
if (!PNA)
2589+
return nullptr;
2590+
2591+
return getOrCreateType(PNA->getTypedefType(), Unit);
2592+
}
2593+
2594+
std::pair<llvm::DIType *, llvm::DIType *>
2595+
CGDebugInfo::CreateTypeDefinition(const RecordType *Ty) {
25772596
RecordDecl *RD = Ty->getDecl();
25782597

25792598
// Get overall information about the record type for the debug info.
@@ -2589,7 +2608,7 @@ llvm::DIType *CGDebugInfo::CreateTypeDefinition(const RecordType *Ty) {
25892608

25902609
const RecordDecl *D = RD->getDefinition();
25912610
if (!D || !D->isCompleteDefinition())
2592-
return FwdDecl;
2611+
return {FwdDecl, nullptr};
25932612

25942613
if (const auto *CXXDecl = dyn_cast<CXXRecordDecl>(RD))
25952614
CollectContainingType(CXXDecl, FwdDecl);
@@ -2628,7 +2647,12 @@ llvm::DIType *CGDebugInfo::CreateTypeDefinition(const RecordType *Ty) {
26282647
llvm::MDNode::replaceWithPermanent(llvm::TempDICompositeType(FwdDecl));
26292648

26302649
RegionMap[Ty->getDecl()].reset(FwdDecl);
2631-
return FwdDecl;
2650+
2651+
if (CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::LLDB)
2652+
if (auto *PrefDI = GetPreferredNameType(CXXDecl, DefUnit))
2653+
return {FwdDecl, PrefDI};
2654+
2655+
return {FwdDecl, nullptr};
26322656
}
26332657

26342658
llvm::DIType *CGDebugInfo::CreateType(const ObjCObjectType *Ty,
@@ -3653,7 +3677,7 @@ llvm::DICompositeType *CGDebugInfo::CreateLimitedType(const RecordType *Ty) {
36533677
void CGDebugInfo::CollectContainingType(const CXXRecordDecl *RD,
36543678
llvm::DICompositeType *RealDecl) {
36553679
// A class's primary base or the class itself contains the vtable.
3656-
llvm::DICompositeType *ContainingType = nullptr;
3680+
llvm::DIType *ContainingType = nullptr;
36573681
const ASTRecordLayout &RL = CGM.getContext().getASTRecordLayout(RD);
36583682
if (const CXXRecordDecl *PBase = RL.getPrimaryBase()) {
36593683
// Seek non-virtual primary base root.
@@ -3665,9 +3689,8 @@ void CGDebugInfo::CollectContainingType(const CXXRecordDecl *RD,
36653689
else
36663690
break;
36673691
}
3668-
ContainingType = cast<llvm::DICompositeType>(
3669-
getOrCreateType(QualType(PBase->getTypeForDecl(), 0),
3670-
getOrCreateFile(RD->getLocation())));
3692+
ContainingType = getOrCreateType(QualType(PBase->getTypeForDecl(), 0),
3693+
getOrCreateFile(RD->getLocation()));
36713694
} else if (RD->isDynamicClass())
36723695
ContainingType = RealDecl;
36733696

clang/lib/CodeGen/CGDebugInfo.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,15 @@ class CGDebugInfo {
190190
llvm::DIType *CreateType(const FunctionType *Ty, llvm::DIFile *F);
191191
/// Get structure or union type.
192192
llvm::DIType *CreateType(const RecordType *Tyg);
193-
llvm::DIType *CreateTypeDefinition(const RecordType *Ty);
193+
194+
/// Create definition for the specified 'Ty'.
195+
///
196+
/// \returns A pair of 'llvm::DIType's. The first is the definition
197+
/// of the 'Ty'. The second is the type specified by the preferred_name
198+
/// attribute on 'Ty', which can be a nullptr if no such attribute
199+
/// exists.
200+
std::pair<llvm::DIType *, llvm::DIType *>
201+
CreateTypeDefinition(const RecordType *Ty);
194202
llvm::DICompositeType *CreateLimitedType(const RecordType *Ty);
195203
void CollectContainingType(const CXXRecordDecl *RD,
196204
llvm::DICompositeType *CT);
@@ -274,6 +282,12 @@ class CGDebugInfo {
274282
llvm::DenseSet<CanonicalDeclPtr<const CXXRecordDecl>> &SeenTypes,
275283
llvm::DINode::DIFlags StartingFlags);
276284

285+
/// Helper function that returns the llvm::DIType that the
286+
/// PreferredNameAttr attribute on \ref RD refers to. If no such
287+
/// attribute exists, returns nullptr.
288+
llvm::DIType *GetPreferredNameType(const CXXRecordDecl *RD,
289+
llvm::DIFile *Unit);
290+
277291
struct TemplateArgs {
278292
const TemplateParameterList *TList;
279293
llvm::ArrayRef<TemplateArgument> Args;
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// RUN: %clang_cc1 -triple x86_64-unk-unk -o - -emit-llvm -debug-info-kind=standalone -debugger-tuning=lldb %s | FileCheck %s --check-prefixes=COMMON,LLDB
2+
// RUN: %clang_cc1 -triple x86_64-unk-unk -o - -emit-llvm -debug-info-kind=standalone -debugger-tuning=gdb %s | FileCheck %s --check-prefixes=COMMON,GDB
3+
4+
template <typename T>
5+
struct Foo;
6+
7+
typedef Foo<int> BarIntBase;
8+
typedef BarIntBase BarIntTmp;
9+
typedef BarIntTmp BarInt;
10+
11+
template <typename T>
12+
using BarBase = Foo<T>;
13+
14+
template <typename T>
15+
using BarTmp = BarBase<T>;
16+
17+
template <typename T>
18+
using Bar = BarTmp<T>;
19+
20+
template <typename T>
21+
struct [[clang::preferred_name(BarInt),
22+
clang::preferred_name(Bar<char>)]] Foo{
23+
};
24+
25+
int main() {
26+
Foo<int> varInt;
27+
28+
// COMMON: !DILocalVariable(name: "varInt", scope: ![[#]], file: ![[#]], line: [[#]], type: ![[BAR_INT_TY:[0-9]+]])
29+
// LLDB: ![[BAR_INT_TY]] = !DIDerivedType(tag: DW_TAG_typedef, name: "BarInt", file: ![[#]], line: [[#]], baseType: ![[BAR_INT_TMP:[0-9]+]])
30+
// LLDB: ![[BAR_INT_TMP]] = !DIDerivedType(tag: DW_TAG_typedef, name: "BarIntTmp", file: ![[#]], line: [[#]], baseType: ![[BAR_INT_BASE:[0-9]+]])
31+
// LLDB: ![[BAR_INT_BASE]] = !DIDerivedType(tag: DW_TAG_typedef, name: "BarIntBase", file: ![[#]], line: [[#]], baseType: ![[FOO_INT:[0-9]+]])
32+
// LLDB: ![[FOO_INT]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo<int>", file: ![[#]], line: [[#]], size: [[#]]
33+
// GDB: ![[BAR_INT_TY]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo<int>", file: ![[#]], line: [[#]], size: [[#]]
34+
35+
Foo<char> varChar;
36+
37+
// COMMON: !DILocalVariable(name: "varChar", scope: ![[#]], file: ![[#]], line: [[#]], type: ![[BAR_CHAR_TY:[0-9]+]])
38+
// LLDB: ![[BAR_CHAR_TY]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Bar<char>", file: ![[#]], line: [[#]], baseType: ![[BAR_CHAR_TMP:[0-9]+]])
39+
// LLDB: ![[BAR_CHAR_TMP]] = !DIDerivedType(tag: DW_TAG_typedef, name: "BarTmp<char>", file: ![[#]], line: [[#]], baseType: ![[BAR_CHAR_BASE:[0-9]+]])
40+
// LLDB: ![[BAR_CHAR_BASE]] = !DIDerivedType(tag: DW_TAG_typedef, name: "BarBase<char>", file: ![[#]], line: [[#]], baseType: ![[FOO_CHAR:[0-9]+]])
41+
// LLDB: ![[FOO_CHAR]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo<char>"
42+
// GDB: ![[BAR_CHAR_TY]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo<char>"
43+
44+
Foo<Foo<int>> varFooInt;
45+
46+
// COMMON: !DILocalVariable(name: "varFooInt", scope: ![[#]], file: ![[#]], line: [[#]], type: ![[FOO_BAR_INT_TY:[0-9]+]])
47+
// COMMON: ![[FOO_BAR_INT_TY]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo<Foo<int> >"
48+
// COMMON-SAME: templateParams: ![[PARAM:[0-9]+]]
49+
// COMMON: ![[PARAM]] = !{![[TEMPL_TYPE_PARAM:[0-9]+]]}
50+
// GDB: ![[TEMPL_TYPE_PARAM]] = !DITemplateTypeParameter(name: "T", type: ![[BAR_INT_TY]])
51+
// LLDB: ![[TEMPL_TYPE_PARAM]] = !DITemplateTypeParameter(name: "T", type: ![[BAR_INT_TY]])
52+
53+
Foo<Foo<char>> varFooChar;
54+
55+
// COMMON: !DILocalVariable(name: "varFooChar", scope: ![[#]], file: ![[#]], line: [[#]], type: ![[FOO_BAR_CHAR_TY:[0-9]+]])
56+
// COMMON: ![[FOO_BAR_CHAR_TY]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo<Foo<char> >"
57+
// COMMON-SAME: templateParams: ![[CHAR_PARAM:[0-9]+]]
58+
// COMMON: ![[CHAR_PARAM]] = !{![[CHAR_TEMPL_TYPE_PARAM:[0-9]+]]}
59+
// GDB: ![[CHAR_TEMPL_TYPE_PARAM]] = !DITemplateTypeParameter(name: "T", type: ![[BAR_CHAR_TY]])
60+
// LLDB: ![[CHAR_TEMPL_TYPE_PARAM]] = !DITemplateTypeParameter(name: "T", type: ![[BAR_CHAR_TY]])
61+
62+
return 0;
63+
}
64+
65+

clang/test/CodeGen/preferred_name.cpp

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// RUN: %clang_cc1 -triple x86_64-unk-unk -o - -emit-llvm -debug-info-kind=standalone -debugger-tuning=lldb %s | FileCheck %s --check-prefixes=COMMON,LLDB
2+
// RUN: %clang_cc1 -triple x86_64-unk-unk -o - -emit-llvm -debug-info-kind=standalone -debugger-tuning=gdb %s | FileCheck %s --check-prefixes=COMMON,GDB
3+
4+
template <typename T>
5+
struct Foo;
6+
7+
typedef Foo<int> BarInt;
8+
typedef Foo<double> BarDouble;
9+
10+
template <typename T>
11+
using Bar = Foo<T>;
12+
13+
template <typename T>
14+
struct [[clang::preferred_name(BarInt),
15+
clang::preferred_name(BarDouble),
16+
clang::preferred_name(Bar<short>),
17+
clang::preferred_name(Bar<char>)]] Foo{
18+
};
19+
20+
int main() {
21+
Foo<int> varInt;
22+
23+
// COMMON: !DILocalVariable(name: "varInt", scope: ![[#]], file: ![[#]], line: [[#]], type: ![[BAR_INT_TY:[0-9]+]])
24+
// LLDB: ![[BAR_INT_TY]] = !DIDerivedType(tag: DW_TAG_typedef, name: "BarInt", file: ![[#]], line: [[#]], baseType: ![[BAR_INT_BASE:[0-9]+]])
25+
// LLDB: ![[BAR_INT_BASE]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo<int>", file: ![[#]], line: [[#]], size: [[#]]
26+
// GDB: ![[BAR_INT_TY]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo<int>", file: ![[#]], line: [[#]], size: [[#]]
27+
28+
Foo<double> varDouble;
29+
30+
// COMMON: !DILocalVariable(name: "varDouble", scope: ![[#]], file: ![[#]], line: [[#]], type: ![[BAR_DOUBLE_TY:[0-9]+]])
31+
// LLDB: ![[BAR_DOUBLE_TY]] = !DIDerivedType(tag: DW_TAG_typedef, name: "BarDouble", file: ![[#]], line: [[#]], baseType: ![[BAR_DOUBLE_BASE:[0-9]+]])
32+
// LLDB: ![[BAR_DOUBLE_BASE]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo<double>"
33+
// GDB: ![[BAR_DOUBLE_TY]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo<double>"
34+
35+
Foo<short> varShort;
36+
37+
// COMMON: !DILocalVariable(name: "varShort", scope: ![[#]], file: ![[#]], line: [[#]], type: ![[BAR_SHORT_TY:[0-9]+]])
38+
// LLDB: ![[BAR_SHORT_TY]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Bar<short>", file: ![[#]], line: [[#]], baseType: ![[BAR_SHORT_BASE:[0-9]+]])
39+
// LLDB: ![[BAR_SHORT_BASE]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo<short>"
40+
// GDB: ![[BAR_SHORT_TY]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo<short>"
41+
42+
Foo<char> varChar;
43+
44+
// COMMON: !DILocalVariable(name: "varChar", scope: ![[#]], file: ![[#]], line: [[#]], type: ![[BAR_CHAR_TY:[0-9]+]])
45+
// LLDB: ![[BAR_CHAR_TY]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Bar<char>", file: ![[#]], line: [[#]], baseType: ![[BAR_CHAR_BASE:[0-9]+]])
46+
// LLDB: ![[BAR_CHAR_BASE]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo<char>"
47+
// GDB: ![[BAR_CHAR_TY]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo<char>"
48+
49+
Foo<Foo<int>> varFooInt;
50+
51+
// COMMON: !DILocalVariable(name: "varFooInt", scope: ![[#]], file: ![[#]], line: [[#]], type: ![[FOO_BAR_INT_TY:[0-9]+]])
52+
// COMMON: ![[FOO_BAR_INT_TY]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo<Foo<int> >"
53+
// COMMON-SAME: templateParams: ![[PARAM:[0-9]+]]
54+
// COMMON: ![[PARAM]] = !{![[TEMPL_TYPE_PARAM:[0-9]+]]}
55+
// GDB: ![[TEMPL_TYPE_PARAM]] = !DITemplateTypeParameter(name: "T", type: ![[BAR_INT_TY]])
56+
// LLDB: ![[TEMPL_TYPE_PARAM]] = !DITemplateTypeParameter(name: "T", type: ![[BAR_INT_TY]])
57+
58+
BarInt barInt;
59+
60+
// LLDB: !DILocalVariable(name: "barInt", scope: ![[#]], file: ![[#]], line: [[#]], type: ![[BAR_INT_TY]])
61+
// GDB: !DILocalVariable(name: "barInt", scope: ![[#]], file: ![[#]], line: [[#]], type: ![[BAR_INT_TYPEDEF:[0-9]+]])
62+
// GDB: ![[BAR_INT_TYPEDEF]] = !DIDerivedType(tag: DW_TAG_typedef, name: "BarInt"
63+
64+
BarDouble barDouble;
65+
66+
// LLDB: !DILocalVariable(name: "barDouble", scope: ![[#]], file: ![[#]], line: [[#]], type: ![[BAR_DOUBLE_TY]])
67+
// GDB: !DILocalVariable(name: "barDouble", scope: ![[#]], file: ![[#]], line: [[#]], type: ![[BAR_DOUBLE_TYPEDEF:[0-9]+]])
68+
// GDB: ![[BAR_DOUBLE_TYPEDEF]] = !DIDerivedType(tag: DW_TAG_typedef, name: "BarDouble"
69+
70+
Bar<short> barShort;
71+
72+
// LLDB: !DILocalVariable(name: "barShort", scope: ![[#]], file: ![[#]], line: [[#]], type: ![[BAR_SHORT_TY_2:[0-9]+]])
73+
// GDB: !DILocalVariable(name: "barShort", scope: ![[#]], file: ![[#]], line: [[#]], type: ![[BAR_SHORT_TYPEDEF:[0-9]+]])
74+
// GDB: ![[BAR_SHORT_TYPEDEF]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Bar<short>"
75+
76+
Bar<char> barChar;
77+
78+
// LLDB: ![[BAR_SHORT_TY_2]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Bar<short>", file: ![[#]], line: [[#]], baseType: ![[BAR_SHORT_TY]])
79+
80+
// LLDB: !DILocalVariable(name: "barChar", scope: ![[#]], file: ![[#]], line: [[#]], type: ![[BAR_CHAR_TY_2:[0-9]+]])
81+
// GDB: !DILocalVariable(name: "barChar", scope: ![[#]], file: ![[#]], line: [[#]], type: ![[BAR_CHAR_TYPEDEF:[0-9]+]])
82+
// GDB: ![[BAR_CHAR_TYPEDEF]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Bar<char>"
83+
84+
// LLDB: ![[BAR_CHAR_TY_2]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Bar<char>", file: ![[#]], line: [[#]], baseType: ![[BAR_CHAR_TY]])
85+
86+
return 0;
87+
}
88+
89+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
template<typename T> struct Foo;
2+
3+
template<typename T>
4+
using Bar = Foo<T>;
5+
6+
template<typename T> struct [[clang::preferred_name(Bar<T>)]] Foo {};
7+
8+
template <typename T> struct Baz { Foo<char> member; };
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module PreferredNameModule {
2+
header "gmodules-preferred-name-alias.h"
3+
export *
4+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
template<typename T> struct Foo;
2+
3+
typedef Foo<char> Bar;
4+
5+
template<typename T> struct [[clang::preferred_name(Bar)]] Foo {};
6+
7+
template <typename T> struct Baz { Foo<char> member; };
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module PreferredNameModule {
2+
header "gmodules-preferred-name-typedef.h"
3+
export *
4+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: rm -rf %t
2+
// RUN: %clang_cc1 -std=c++11 -dwarf-ext-refs -fmodule-format=obj \
3+
// RUN: -fmodule-map-file=%S/Inputs/gmodules-preferred-name-alias.modulemap \
4+
// RUN: -fmodules-cache-path=%t -debug-info-kind=standalone -debugger-tuning=lldb \
5+
// RUN: -fmodules -mllvm -debug-only=pchcontainer -x c++ \
6+
// RUN: -I %S/Inputs %s &> %t.ll
7+
// RUN: cat %t.ll | FileCheck %s
8+
9+
#include "gmodules-preferred-name-alias.h"
10+
11+
// CHECK: ![[#]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Bar<char>", scope: ![[#]], file: ![[#]], line: [[#]], baseType: ![[PREF_BASE:[0-9]+]])
12+
// CHECK: ![[PREF_BASE]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo<char>"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: rm -rf %t
2+
// RUN: %clang_cc1 -std=c++11 -dwarf-ext-refs -fmodule-format=obj \
3+
// RUN: -fmodule-map-file=%S/Inputs/gmodules-preferred-name-typedef.modulemap \
4+
// RUN: -fmodules-cache-path=%t -debug-info-kind=standalone -debugger-tuning=lldb \
5+
// RUN: -fmodules -mllvm -debug-only=pchcontainer -x c++ \
6+
// RUN: -I %S/Inputs %s &> %t.ll
7+
// RUN: cat %t.ll | FileCheck %s
8+
9+
#include "gmodules-preferred-name-typedef.h"
10+
11+
// CHECK: ![[#]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Bar", scope: ![[#]], file: ![[#]], line: [[#]], baseType: ![[PREF_BASE:[0-9]+]])
12+
// CHECK: ![[PREF_BASE]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo<char>"

lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/shared_ptr/TestDataFormatterLibcxxSharedPtr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def test_shared_ptr_variables(self):
6060

6161
valobj = self.expect_var_path(
6262
"sp_str",
63-
type="std::shared_ptr<std::basic_string<char> >",
63+
type="std::shared_ptr<std::string>",
6464
children=[ValueCheck(name="__ptr_", summary='"hello"')],
6565
)
6666
self.assertRegex(valobj.summary, r'^"hello"( strong=1)? weak=1$')

lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/unique_ptr/TestDataFormatterLibcxxUniquePtr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def test_unique_ptr_variables(self):
6060

6161
valobj = self.expect_var_path(
6262
"up_str",
63-
type="std::unique_ptr<std::basic_string<char> >",
63+
type="std::unique_ptr<std::string>",
6464
summary='"hello"',
6565
children=[ValueCheck(name="__value_", summary='"hello"')],
6666
)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CXX_SOURCES := main.cpp
2+
CXXFLAGS_EXTRAS := -std=c++20 -glldb
3+
include Makefile.rules
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""
2+
Test formatting of types annotated with
3+
[[clang::preferred_name]] attributes.
4+
"""
5+
6+
import lldb
7+
import lldbsuite.test.lldbutil as lldbutil
8+
from lldbsuite.test.lldbtest import *
9+
from lldbsuite.test import decorators
10+
11+
12+
class TestPreferredName(TestBase):
13+
14+
def test_frame_var(self):
15+
self.build()
16+
lldbutil.run_to_source_breakpoint(self, "return", lldb.SBFileSpec("main.cpp"))
17+
18+
self.expect("frame variable barInt", substrs=["BarInt"])
19+
self.expect("frame variable barDouble", substrs=["BarDouble"])
20+
self.expect("frame variable barShort", substrs=["Bar<short>"])
21+
self.expect("frame variable barChar", substrs=["Bar<char>"])
22+
23+
self.expect("frame variable varInt", substrs=["BarInt"])
24+
self.expect("frame variable varDouble", substrs=["BarDouble"])
25+
self.expect("frame variable varShort", substrs=["Bar<short>"])
26+
self.expect("frame variable varChar", substrs=["Bar<char>"])
27+
self.expect("frame variable varFooInt", substrs=["Foo<BarInt>"])
28+
29+
def test_expr(self):
30+
self.build()
31+
lldbutil.run_to_source_breakpoint(self, "return", lldb.SBFileSpec("main.cpp"))
32+
33+
self.expect_expr("barInt", result_type="BarInt")
34+
self.expect_expr("barDouble", result_type="BarDouble")
35+
self.expect_expr("barShort", result_type="Bar<short>")
36+
self.expect_expr("barChar", result_type="Bar<char>")
37+
38+
self.expect_expr("varInt", result_type="BarInt")
39+
self.expect_expr("varDouble", result_type="BarDouble")
40+
self.expect_expr("varShort", result_type="Bar<short>")
41+
self.expect_expr("varChar", result_type="Bar<char>")
42+
self.expect_expr("varFooInt", result_type="Foo<BarInt>")

0 commit comments

Comments
 (0)