Skip to content

Commit aba003f

Browse files
committed
[lldb][TypeSystemClang] Make AsmLabel parameter a llvm::StringRef (llvm#151355)
Split out from llvm#148877 This patch prepares `TypeSystemClang` APIs to take `AsmLabel`s which concatenated strings (hence `std::string`) instead of a plain `const char*`. (cherry picked from commit 7410f6d)
1 parent 6ad1930 commit aba003f

File tree

8 files changed

+47
-39
lines changed

8 files changed

+47
-39
lines changed

lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1990,7 +1990,7 @@ void ClangExpressionDeclMap::AddContextClassType(NameSearchContext &context,
19901990
const bool is_artificial = false;
19911991

19921992
CXXMethodDecl *method_decl = m_clang_ast_context->AddMethodToCXXRecordType(
1993-
copied_clang_type.GetOpaqueQualType(), "$__lldb_expr", nullptr,
1993+
copied_clang_type.GetOpaqueQualType(), "$__lldb_expr", /*asm_label=*/{},
19941994
method_type, lldb::eAccessPublic, is_virtual, is_static, is_inline,
19951995
is_explicit, is_attr_used, is_artificial);
19961996

lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,14 @@ static unsigned GetCXXMethodCVQuals(const DWARFDIE &subprogram,
254254
return cv_quals;
255255
}
256256

257+
static std::string MakeLLDBFuncAsmLabel(const DWARFDIE &die) {
258+
char const *name = die.GetMangledName(/*substitute_name_allowed*/ false);
259+
if (!name)
260+
return {};
261+
262+
return name;
263+
}
264+
257265
TypeSP DWARFASTParserClang::ParseTypeFromClangModule(const SymbolContext &sc,
258266
const DWARFDIE &die,
259267
Log *log) {
@@ -1319,7 +1327,7 @@ std::pair<bool, TypeSP> DWARFASTParserClang::ParseCXXMethod(
13191327

13201328
clang::CXXMethodDecl *cxx_method_decl = m_ast.AddMethodToCXXRecordType(
13211329
class_opaque_type.GetOpaqueQualType(), attrs.name.GetCString(),
1322-
attrs.mangled_name, clang_type, accessibility, attrs.is_virtual,
1330+
MakeLLDBFuncAsmLabel(die), clang_type, accessibility, attrs.is_virtual,
13231331
is_static, attrs.is_inline, attrs.is_explicit, is_attr_used,
13241332
attrs.is_artificial);
13251333

@@ -1472,7 +1480,7 @@ DWARFASTParserClang::ParseSubroutine(const DWARFDIE &die,
14721480
ignore_containing_context ? m_ast.GetTranslationUnitDecl()
14731481
: containing_decl_ctx,
14741482
GetOwningClangModule(die), name, clang_type, attrs.storage,
1475-
attrs.is_inline);
1483+
attrs.is_inline, MakeLLDBFuncAsmLabel(die));
14761484
std::free(name_buf);
14771485

14781486
if (has_template_params) {
@@ -1482,7 +1490,7 @@ DWARFASTParserClang::ParseSubroutine(const DWARFDIE &die,
14821490
ignore_containing_context ? m_ast.GetTranslationUnitDecl()
14831491
: containing_decl_ctx,
14841492
GetOwningClangModule(die), attrs.name.GetStringRef(), clang_type,
1485-
attrs.storage, attrs.is_inline);
1493+
attrs.storage, attrs.is_inline, /*asm_label=*/{});
14861494
clang::FunctionTemplateDecl *func_template_decl =
14871495
m_ast.CreateFunctionTemplateDecl(
14881496
containing_decl_ctx, GetOwningClangModule(die),
@@ -1494,20 +1502,6 @@ DWARFASTParserClang::ParseSubroutine(const DWARFDIE &die,
14941502
lldbassert(function_decl);
14951503

14961504
if (function_decl) {
1497-
// Attach an asm(<mangled_name>) label to the FunctionDecl.
1498-
// This ensures that clang::CodeGen emits function calls
1499-
// using symbols that are mangled according to the DW_AT_linkage_name.
1500-
// If we didn't do this, the external symbols wouldn't exactly
1501-
// match the mangled name LLDB knows about and the IRExecutionUnit
1502-
// would have to fall back to searching object files for
1503-
// approximately matching function names. The motivating
1504-
// example is generating calls to ABI-tagged template functions.
1505-
// This is done separately for member functions in
1506-
// AddMethodToCXXRecordType.
1507-
if (attrs.mangled_name)
1508-
function_decl->addAttr(clang::AsmLabelAttr::CreateImplicit(
1509-
m_ast.getASTContext(), attrs.mangled_name, /*literal=*/false));
1510-
15111505
LinkDeclContextToDIE(function_decl, die);
15121506

15131507
const clang::FunctionProtoType *function_prototype(

lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ struct CreateMethodDecl : public TypeVisitorCallbacks {
8888
MethodOptions::CompilerGenerated;
8989
function_decl = m_clang.AddMethodToCXXRecordType(
9090
parent_ty, proc_name,
91-
/*mangled_name=*/nullptr, func_ct, /*access=*/access_type,
91+
/*asm_label=*/{}, func_ct, /*access=*/access_type,
9292
/*is_virtual=*/is_virtual, /*is_static=*/is_static,
9393
/*is_inline=*/false, /*is_explicit=*/false,
9494
/*is_attr_used=*/false, /*is_artificial=*/is_artificial);
@@ -903,7 +903,7 @@ PdbAstBuilder::CreateFunctionDecl(PdbCompilandSymId func_id,
903903
if (!function_decl) {
904904
function_decl = m_clang.AddMethodToCXXRecordType(
905905
parent_opaque_ty, func_name,
906-
/*mangled_name=*/nullptr, func_ct,
906+
/*asm_label=*/{}, func_ct,
907907
/*access=*/lldb::AccessType::eAccessPublic,
908908
/*is_virtual=*/false, /*is_static=*/false,
909909
/*is_inline=*/false, /*is_explicit=*/false,
@@ -913,7 +913,7 @@ PdbAstBuilder::CreateFunctionDecl(PdbCompilandSymId func_id,
913913
} else {
914914
function_decl = m_clang.CreateFunctionDeclaration(
915915
parent, OptionalClangModuleID(), func_name, func_ct, func_storage,
916-
is_inline);
916+
is_inline, /*asm_label=*/{});
917917
CreateFunctionParameters(func_id, *function_decl, param_count);
918918
}
919919
return function_decl;

lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,8 @@ void UdtRecordCompleter::AddMethod(llvm::StringRef name, TypeIndex type_idx,
111111
bool is_artificial = (options & MethodOptions::CompilerGenerated) ==
112112
MethodOptions::CompilerGenerated;
113113
m_ast_builder.clang().AddMethodToCXXRecordType(
114-
derived_opaque_ty, name.data(), nullptr, method_ct,
115-
access_type, attrs.isVirtual(), attrs.isStatic(), false, false, false,
116-
is_artificial);
114+
derived_opaque_ty, name.data(), /*asm_label=*/{}, method_ct, access_type,
115+
attrs.isVirtual(), attrs.isStatic(), false, false, false, is_artificial);
117116

118117
m_cxx_record_map[derived_opaque_ty].insert({name, method_ct});
119118
}

lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,8 @@ PDBASTParser::GetDeclForSymbol(const llvm::pdb::PDBSymbol &symbol) {
954954

955955
auto decl = m_ast.CreateFunctionDeclaration(
956956
decl_context, OptionalClangModuleID(), name,
957-
type->GetForwardCompilerType(), storage, func->hasInlineAttribute());
957+
type->GetForwardCompilerType(), storage, func->hasInlineAttribute(),
958+
/*asm_label=*/{});
958959

959960
std::vector<clang::ParmVarDecl *> params;
960961
if (std::unique_ptr<PDBSymbolTypeFunctionSig> sig = func->getSignature()) {
@@ -1446,7 +1447,7 @@ PDBASTParser::AddRecordMethod(lldb_private::SymbolFile &symbol_file,
14461447
// TODO: get mangled name for the method.
14471448
return m_ast.AddMethodToCXXRecordType(
14481449
record_type.GetOpaqueQualType(), name.c_str(),
1449-
/*mangled_name*/ nullptr, method_comp_type, access, method.isVirtual(),
1450+
/*asm_label=*/{}, method_comp_type, access, method.isVirtual(),
14501451
method.isStatic(), method.hasInlineAttribute(),
14511452
/*is_explicit*/ false, // FIXME: Need this field in CodeView.
14521453
/*is_attr_used*/ false,

lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2185,7 +2185,7 @@ std::string TypeSystemClang::GetTypeNameForDecl(const NamedDecl *named_decl,
21852185
FunctionDecl *TypeSystemClang::CreateFunctionDeclaration(
21862186
clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module,
21872187
llvm::StringRef name, const CompilerType &function_clang_type,
2188-
clang::StorageClass storage, bool is_inline) {
2188+
clang::StorageClass storage, bool is_inline, llvm::StringRef asm_label) {
21892189
FunctionDecl *func_decl = nullptr;
21902190
ASTContext &ast = getASTContext();
21912191
if (!decl_ctx)
@@ -2206,6 +2206,21 @@ FunctionDecl *TypeSystemClang::CreateFunctionDeclaration(
22062206
func_decl->setConstexprKind(isConstexprSpecified
22072207
? ConstexprSpecKind::Constexpr
22082208
: ConstexprSpecKind::Unspecified);
2209+
2210+
// Attach an asm(<mangled_name>) label to the FunctionDecl.
2211+
// This ensures that clang::CodeGen emits function calls
2212+
// using symbols that are mangled according to the DW_AT_linkage_name.
2213+
// If we didn't do this, the external symbols wouldn't exactly
2214+
// match the mangled name LLDB knows about and the IRExecutionUnit
2215+
// would have to fall back to searching object files for
2216+
// approximately matching function names. The motivating
2217+
// example is generating calls to ABI-tagged template functions.
2218+
// This is done separately for member functions in
2219+
// AddMethodToCXXRecordType.
2220+
if (!asm_label.empty())
2221+
func_decl->addAttr(clang::AsmLabelAttr::CreateImplicit(ast, asm_label,
2222+
/*literal=*/true));
2223+
22092224
SetOwningModule(func_decl, owning_module);
22102225
decl_ctx->addDecl(func_decl);
22112226

@@ -7799,7 +7814,7 @@ TypeSystemClang::CreateParameterDeclarations(
77997814

78007815
clang::CXXMethodDecl *TypeSystemClang::AddMethodToCXXRecordType(
78017816
lldb::opaque_compiler_type_t type, llvm::StringRef name,
7802-
const char *mangled_name, const CompilerType &method_clang_type,
7817+
llvm::StringRef asm_label, const CompilerType &method_clang_type,
78037818
lldb::AccessType access, bool is_virtual, bool is_static, bool is_inline,
78047819
bool is_explicit, bool is_attr_used, bool is_artificial) {
78057820
if (!type || !method_clang_type.IsValid() || name.empty())
@@ -7934,10 +7949,9 @@ clang::CXXMethodDecl *TypeSystemClang::AddMethodToCXXRecordType(
79347949
if (is_attr_used)
79357950
cxx_method_decl->addAttr(clang::UsedAttr::CreateImplicit(getASTContext()));
79367951

7937-
if (mangled_name != nullptr) {
7952+
if (!asm_label.empty())
79387953
cxx_method_decl->addAttr(clang::AsmLabelAttr::CreateImplicit(
7939-
getASTContext(), mangled_name, /*literal=*/false));
7940-
}
7954+
getASTContext(), asm_label, /*literal=*/true));
79417955

79427956
// Parameters on member function declarations in DWARF generally don't
79437957
// have names, so we omit them when creating the ParmVarDecls.

lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ class TypeSystemClang : public TypeSystem {
514514
clang::FunctionDecl *CreateFunctionDeclaration(
515515
clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module,
516516
llvm::StringRef name, const CompilerType &function_Type,
517-
clang::StorageClass storage, bool is_inline);
517+
clang::StorageClass storage, bool is_inline, llvm::StringRef asm_label);
518518

519519
CompilerType
520520
CreateFunctionType(const CompilerType &result_type,
@@ -1080,7 +1080,7 @@ class TypeSystemClang : public TypeSystem {
10801080

10811081
clang::CXXMethodDecl *AddMethodToCXXRecordType(
10821082
lldb::opaque_compiler_type_t type, llvm::StringRef name,
1083-
const char *mangled_name, const CompilerType &method_type,
1083+
llvm::StringRef asm_label, const CompilerType &method_type,
10841084
lldb::AccessType access, bool is_virtual, bool is_static, bool is_inline,
10851085
bool is_explicit, bool is_attr_used, bool is_artificial);
10861086

lldb/unittests/Symbol/TestTypeSystemClang.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ TEST_F(TestTypeSystemClang, TestFunctionTemplateConstruction) {
869869
CompilerType clang_type = m_ast->CreateFunctionType(int_type, {}, false, 0U);
870870
FunctionDecl *func = m_ast->CreateFunctionDeclaration(
871871
TU, OptionalClangModuleID(), "foo", clang_type, StorageClass::SC_None,
872-
false);
872+
false, /*asm_label=*/{});
873873
TypeSystemClang::TemplateParameterInfos empty_params;
874874

875875
// Create the actual function template.
@@ -900,7 +900,7 @@ TEST_F(TestTypeSystemClang, TestFunctionTemplateInRecordConstruction) {
900900
// 2. It is mirroring the behavior of DWARFASTParserClang::ParseSubroutine.
901901
FunctionDecl *func = m_ast->CreateFunctionDeclaration(
902902
TU, OptionalClangModuleID(), "foo", clang_type, StorageClass::SC_None,
903-
false);
903+
false, /*asm_label=*/{});
904904
TypeSystemClang::TemplateParameterInfos empty_params;
905905

906906
// Create the actual function template.
@@ -938,7 +938,7 @@ TEST_F(TestTypeSystemClang, TestDeletingImplicitCopyCstrDueToMoveCStr) {
938938
bool is_attr_used = false;
939939
bool is_artificial = false;
940940
m_ast->AddMethodToCXXRecordType(
941-
t.GetOpaqueQualType(), class_name, nullptr, function_type,
941+
t.GetOpaqueQualType(), class_name, /*asm_label=*/{}, function_type,
942942
lldb::AccessType::eAccessPublic, is_virtual, is_static, is_inline,
943943
is_explicit, is_attr_used, is_artificial);
944944

@@ -975,7 +975,7 @@ TEST_F(TestTypeSystemClang, TestNotDeletingUserCopyCstrDueToMoveCStr) {
975975
CompilerType function_type = m_ast->CreateFunctionType(
976976
return_type, args, /*variadic=*/false, /*quals*/ 0U);
977977
m_ast->AddMethodToCXXRecordType(
978-
t.GetOpaqueQualType(), class_name, nullptr, function_type,
978+
t.GetOpaqueQualType(), class_name, /*asm_label=*/{}, function_type,
979979
lldb::AccessType::eAccessPublic, is_virtual, is_static, is_inline,
980980
is_explicit, is_attr_used, is_artificial);
981981
}
@@ -987,7 +987,7 @@ TEST_F(TestTypeSystemClang, TestNotDeletingUserCopyCstrDueToMoveCStr) {
987987
m_ast->CreateFunctionType(return_type, args,
988988
/*variadic=*/false, /*quals*/ 0U);
989989
m_ast->AddMethodToCXXRecordType(
990-
t.GetOpaqueQualType(), class_name, nullptr, function_type,
990+
t.GetOpaqueQualType(), class_name, /*asm_label=*/{}, function_type,
991991
lldb::AccessType::eAccessPublic, is_virtual, is_static, is_inline,
992992
is_explicit, is_attr_used, is_artificial);
993993
}
@@ -1098,7 +1098,7 @@ TEST_F(TestTypeSystemClang, AddMethodToCXXRecordType_ParmVarDecls) {
10981098
m_ast->CreateFunctionType(return_type, param_types,
10991099
/*variadic=*/false, /*quals*/ 0U);
11001100
m_ast->AddMethodToCXXRecordType(
1101-
t.GetOpaqueQualType(), "myFunc", nullptr, function_type,
1101+
t.GetOpaqueQualType(), "myFunc", /*asm_label=*/{}, function_type,
11021102
lldb::AccessType::eAccessPublic, is_virtual, is_static, is_inline,
11031103
is_explicit, is_attr_used, is_artificial);
11041104

0 commit comments

Comments
 (0)