Skip to content

Commit 4ea540e

Browse files
Michael137krishna2803
authored andcommitted
[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*`.
1 parent 4a42397 commit 4ea540e

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
@@ -1991,7 +1991,7 @@ void ClangExpressionDeclMap::AddContextClassType(NameSearchContext &context,
19911991
const bool is_artificial = false;
19921992

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

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

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,14 @@ static unsigned GetCXXMethodCVQuals(const DWARFDIE &subprogram,
249249
return cv_quals;
250250
}
251251

252+
static std::string MakeLLDBFuncAsmLabel(const DWARFDIE &die) {
253+
char const *name = die.GetMangledName(/*substitute_name_allowed*/ false);
254+
if (!name)
255+
return {};
256+
257+
return name;
258+
}
259+
252260
TypeSP DWARFASTParserClang::ParseTypeFromClangModule(const SymbolContext &sc,
253261
const DWARFDIE &die,
254262
Log *log) {
@@ -1231,7 +1239,7 @@ std::pair<bool, TypeSP> DWARFASTParserClang::ParseCXXMethod(
12311239

12321240
clang::CXXMethodDecl *cxx_method_decl = m_ast.AddMethodToCXXRecordType(
12331241
class_opaque_type.GetOpaqueQualType(), attrs.name.GetCString(),
1234-
attrs.mangled_name, clang_type, accessibility, attrs.is_virtual,
1242+
MakeLLDBFuncAsmLabel(die), clang_type, accessibility, attrs.is_virtual,
12351243
is_static, attrs.is_inline, attrs.is_explicit, is_attr_used,
12361244
attrs.is_artificial);
12371245

@@ -1384,7 +1392,7 @@ DWARFASTParserClang::ParseSubroutine(const DWARFDIE &die,
13841392
ignore_containing_context ? m_ast.GetTranslationUnitDecl()
13851393
: containing_decl_ctx,
13861394
GetOwningClangModule(die), name, clang_type, attrs.storage,
1387-
attrs.is_inline);
1395+
attrs.is_inline, MakeLLDBFuncAsmLabel(die));
13881396
std::free(name_buf);
13891397

13901398
if (has_template_params) {
@@ -1394,7 +1402,7 @@ DWARFASTParserClang::ParseSubroutine(const DWARFDIE &die,
13941402
ignore_containing_context ? m_ast.GetTranslationUnitDecl()
13951403
: containing_decl_ctx,
13961404
GetOwningClangModule(die), attrs.name.GetStringRef(), clang_type,
1397-
attrs.storage, attrs.is_inline);
1405+
attrs.storage, attrs.is_inline, /*asm_label=*/{});
13981406
clang::FunctionTemplateDecl *func_template_decl =
13991407
m_ast.CreateFunctionTemplateDecl(
14001408
containing_decl_ctx, GetOwningClangModule(die),
@@ -1406,20 +1414,6 @@ DWARFASTParserClang::ParseSubroutine(const DWARFDIE &die,
14061414
lldbassert(function_decl);
14071415

14081416
if (function_decl) {
1409-
// Attach an asm(<mangled_name>) label to the FunctionDecl.
1410-
// This ensures that clang::CodeGen emits function calls
1411-
// using symbols that are mangled according to the DW_AT_linkage_name.
1412-
// If we didn't do this, the external symbols wouldn't exactly
1413-
// match the mangled name LLDB knows about and the IRExecutionUnit
1414-
// would have to fall back to searching object files for
1415-
// approximately matching function names. The motivating
1416-
// example is generating calls to ABI-tagged template functions.
1417-
// This is done separately for member functions in
1418-
// AddMethodToCXXRecordType.
1419-
if (attrs.mangled_name)
1420-
function_decl->addAttr(clang::AsmLabelAttr::CreateImplicit(
1421-
m_ast.getASTContext(), attrs.mangled_name, /*literal=*/false));
1422-
14231417
LinkDeclContextToDIE(function_decl, die);
14241418

14251419
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
@@ -2137,7 +2137,7 @@ std::string TypeSystemClang::GetTypeNameForDecl(const NamedDecl *named_decl,
21372137
FunctionDecl *TypeSystemClang::CreateFunctionDeclaration(
21382138
clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module,
21392139
llvm::StringRef name, const CompilerType &function_clang_type,
2140-
clang::StorageClass storage, bool is_inline) {
2140+
clang::StorageClass storage, bool is_inline, llvm::StringRef asm_label) {
21412141
FunctionDecl *func_decl = nullptr;
21422142
ASTContext &ast = getASTContext();
21432143
if (!decl_ctx)
@@ -2158,6 +2158,21 @@ FunctionDecl *TypeSystemClang::CreateFunctionDeclaration(
21582158
func_decl->setConstexprKind(isConstexprSpecified
21592159
? ConstexprSpecKind::Constexpr
21602160
: ConstexprSpecKind::Unspecified);
2161+
2162+
// Attach an asm(<mangled_name>) label to the FunctionDecl.
2163+
// This ensures that clang::CodeGen emits function calls
2164+
// using symbols that are mangled according to the DW_AT_linkage_name.
2165+
// If we didn't do this, the external symbols wouldn't exactly
2166+
// match the mangled name LLDB knows about and the IRExecutionUnit
2167+
// would have to fall back to searching object files for
2168+
// approximately matching function names. The motivating
2169+
// example is generating calls to ABI-tagged template functions.
2170+
// This is done separately for member functions in
2171+
// AddMethodToCXXRecordType.
2172+
if (!asm_label.empty())
2173+
func_decl->addAttr(clang::AsmLabelAttr::CreateImplicit(ast, asm_label,
2174+
/*literal=*/true));
2175+
21612176
SetOwningModule(func_decl, owning_module);
21622177
decl_ctx->addDecl(func_decl);
21632178

@@ -7651,7 +7666,7 @@ TypeSystemClang::CreateParameterDeclarations(
76517666

76527667
clang::CXXMethodDecl *TypeSystemClang::AddMethodToCXXRecordType(
76537668
lldb::opaque_compiler_type_t type, llvm::StringRef name,
7654-
const char *mangled_name, const CompilerType &method_clang_type,
7669+
llvm::StringRef asm_label, const CompilerType &method_clang_type,
76557670
lldb::AccessType access, bool is_virtual, bool is_static, bool is_inline,
76567671
bool is_explicit, bool is_attr_used, bool is_artificial) {
76577672
if (!type || !method_clang_type.IsValid() || name.empty())
@@ -7784,10 +7799,9 @@ clang::CXXMethodDecl *TypeSystemClang::AddMethodToCXXRecordType(
77847799
if (is_attr_used)
77857800
cxx_method_decl->addAttr(clang::UsedAttr::CreateImplicit(getASTContext()));
77867801

7787-
if (mangled_name != nullptr) {
7802+
if (!asm_label.empty())
77887803
cxx_method_decl->addAttr(clang::AsmLabelAttr::CreateImplicit(
7789-
getASTContext(), mangled_name, /*literal=*/false));
7790-
}
7804+
getASTContext(), asm_label, /*literal=*/true));
77917805

77927806
// Parameters on member function declarations in DWARF generally don't
77937807
// 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
@@ -477,7 +477,7 @@ class TypeSystemClang : public TypeSystem {
477477
clang::FunctionDecl *CreateFunctionDeclaration(
478478
clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module,
479479
llvm::StringRef name, const CompilerType &function_Type,
480-
clang::StorageClass storage, bool is_inline);
480+
clang::StorageClass storage, bool is_inline, llvm::StringRef asm_label);
481481

482482
CompilerType
483483
CreateFunctionType(const CompilerType &result_type,
@@ -1001,7 +1001,7 @@ class TypeSystemClang : public TypeSystem {
10011001

10021002
clang::CXXMethodDecl *AddMethodToCXXRecordType(
10031003
lldb::opaque_compiler_type_t type, llvm::StringRef name,
1004-
const char *mangled_name, const CompilerType &method_type,
1004+
llvm::StringRef asm_label, const CompilerType &method_type,
10051005
lldb::AccessType access, bool is_virtual, bool is_static, bool is_inline,
10061006
bool is_explicit, bool is_attr_used, bool is_artificial);
10071007

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)