Author: Michael Buch Date: 2025-08-04T14:34:45+01:00 New Revision: cd8f348c69345755f559049f415ce8b6c0d6edc1
URL: https://github.com/llvm/llvm-project/commit/cd8f348c69345755f559049f415ce8b6c0d6edc1 DIFF: https://github.com/llvm/llvm-project/commit/cd8f348c69345755f559049f415ce8b6c0d6edc1.diff LOG: [clang][Attr] Remove 'literal label' form of AsmLabelAttr (#151858) This was added purely for the needs of LLDB. However, starting with https://github.com/llvm/llvm-project/pull/151355 and https://github.com/llvm/llvm-project/pull/148877 we no longer create literal AsmLabels in LLDB either. So this is unused and we can get rid of it. In the near future LLDB will want to add special support for mangling `AsmLabel`s (specifically https://github.com/llvm/llvm-project/pull/149827). Added: Modified: clang/include/clang/Basic/Attr.td clang/lib/AST/Mangle.cpp clang/lib/Sema/SemaDecl.cpp clang/unittests/AST/DeclTest.cpp lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp Removed: ################################################################################ diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 17cae80816e9e..63fa6aa508827 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -1059,22 +1059,13 @@ def AVRSignal : InheritableAttr, TargetSpecificAttr<TargetAVR> { def AsmLabel : InheritableAttr { let Spellings = [CustomKeyword<"asm">, CustomKeyword<"__asm__">]; let Args = [ - // Label specifies the mangled name for the decl. - StringArgument<"Label">, - - // IsLiteralLabel specifies whether the label is literal (i.e. suppresses - // the global C symbol prefix) or not. If not, the mangle-suppression prefix - // ('\01') is omitted from the decl name at the LLVM IR level. - // - // Non-literal labels are used by some external AST sources like LLDB. - BoolArgument<"IsLiteralLabel", /*optional=*/0, /*fake=*/1> - ]; + // Label specifies the mangled name for the decl. + StringArgument<"Label">, ]; let SemaHandler = 0; let Documentation = [AsmLabelDocs]; - let AdditionalMembers = -[{ + let AdditionalMembers = [{ bool isEquivalent(AsmLabelAttr *Other) const { - return getLabel() == Other->getLabel() && getIsLiteralLabel() == Other->getIsLiteralLabel(); + return getLabel() == Other->getLabel(); } }]; } diff --git a/clang/lib/AST/Mangle.cpp b/clang/lib/AST/Mangle.cpp index 9652fdbc4e125..0bfb51c11f0a5 100644 --- a/clang/lib/AST/Mangle.cpp +++ b/clang/lib/AST/Mangle.cpp @@ -161,9 +161,9 @@ void MangleContext::mangleName(GlobalDecl GD, raw_ostream &Out) { if (const AsmLabelAttr *ALA = D->getAttr<AsmLabelAttr>()) { // If we have an asm name, then we use it as the mangling. - // If the label isn't literal, or if this is an alias for an LLVM intrinsic, + // If the label is an alias for an LLVM intrinsic, // do not add a "\01" prefix. - if (!ALA->getIsLiteralLabel() || ALA->getLabel().starts_with("llvm.")) { + if (ALA->getLabel().starts_with("llvm.")) { Out << ALA->getLabel(); return; } diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 3eaf2eb52ff9d..3562c6ec68552 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -8113,9 +8113,7 @@ NamedDecl *Sema::ActOnVariableDeclarator( } } - NewVD->addAttr(AsmLabelAttr::Create(Context, Label, - /*IsLiteralLabel=*/true, - SE->getStrTokenLoc(0))); + NewVD->addAttr(AsmLabelAttr::Create(Context, Label, SE->getStrTokenLoc(0))); } else if (!ExtnameUndeclaredIdentifiers.empty()) { llvm::DenseMap<IdentifierInfo*,AsmLabelAttr*>::iterator I = ExtnameUndeclaredIdentifiers.find(NewVD->getIdentifier()); @@ -10345,9 +10343,8 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC, if (Expr *E = D.getAsmLabel()) { // The parser guarantees this is a string. StringLiteral *SE = cast<StringLiteral>(E); - NewFD->addAttr(AsmLabelAttr::Create(Context, SE->getString(), - /*IsLiteralLabel=*/true, - SE->getStrTokenLoc(0))); + NewFD->addAttr( + AsmLabelAttr::Create(Context, SE->getString(), SE->getStrTokenLoc(0))); } else if (!ExtnameUndeclaredIdentifiers.empty()) { llvm::DenseMap<IdentifierInfo*,AsmLabelAttr*>::iterator I = ExtnameUndeclaredIdentifiers.find(NewFD->getIdentifier()); @@ -20598,8 +20595,8 @@ void Sema::ActOnPragmaRedefineExtname(IdentifierInfo* Name, LookupOrdinaryName); AttributeCommonInfo Info(AliasName, SourceRange(AliasNameLoc), AttributeCommonInfo::Form::Pragma()); - AsmLabelAttr *Attr = AsmLabelAttr::CreateImplicit( - Context, AliasName->getName(), /*IsLiteralLabel=*/true, Info); + AsmLabelAttr *Attr = + AsmLabelAttr::CreateImplicit(Context, AliasName->getName(), Info); // If a declaration that: // 1) declares a function or a variable diff --git a/clang/unittests/AST/DeclTest.cpp b/clang/unittests/AST/DeclTest.cpp index ed635da683aab..afaf413493299 100644 --- a/clang/unittests/AST/DeclTest.cpp +++ b/clang/unittests/AST/DeclTest.cpp @@ -74,7 +74,6 @@ TEST(Decl, AsmLabelAttr) { StringRef Code = R"( struct S { void f() {} - void g() {} }; )"; auto AST = @@ -87,11 +86,8 @@ TEST(Decl, AsmLabelAttr) { const auto *DeclS = selectFirst<CXXRecordDecl>("d", match(cxxRecordDecl().bind("d"), Ctx)); NamedDecl *DeclF = *DeclS->method_begin(); - NamedDecl *DeclG = *(++DeclS->method_begin()); - // Attach asm labels to the decls: one literal, and one not. - DeclF->addAttr(AsmLabelAttr::Create(Ctx, "foo", /*LiteralLabel=*/true)); - DeclG->addAttr(AsmLabelAttr::Create(Ctx, "goo", /*LiteralLabel=*/false)); + DeclF->addAttr(AsmLabelAttr::Create(Ctx, "foo")); // Mangle the decl names. std::string MangleF, MangleG; @@ -99,14 +95,11 @@ TEST(Decl, AsmLabelAttr) { ItaniumMangleContext::create(Ctx, Diags)); { llvm::raw_string_ostream OS_F(MangleF); - llvm::raw_string_ostream OS_G(MangleG); MC->mangleName(DeclF, OS_F); - MC->mangleName(DeclG, OS_G); } ASSERT_EQ(MangleF, "\x01" "foo"); - ASSERT_EQ(MangleG, "goo"); } TEST(Decl, MangleDependentSizedArray) { diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp index fedc500a17e40..6addf4fc9239e 100644 --- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp +++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp @@ -2184,8 +2184,7 @@ FunctionDecl *TypeSystemClang::CreateFunctionDeclaration( // This is done separately for member functions in // AddMethodToCXXRecordType. if (!asm_label.empty()) - func_decl->addAttr(clang::AsmLabelAttr::CreateImplicit(ast, asm_label, - /*literal=*/true)); + func_decl->addAttr(clang::AsmLabelAttr::CreateImplicit(ast, asm_label)); SetOwningModule(func_decl, owning_module); decl_ctx->addDecl(func_decl); @@ -7824,8 +7823,8 @@ clang::CXXMethodDecl *TypeSystemClang::AddMethodToCXXRecordType( cxx_method_decl->addAttr(clang::UsedAttr::CreateImplicit(getASTContext())); if (!asm_label.empty()) - cxx_method_decl->addAttr(clang::AsmLabelAttr::CreateImplicit( - getASTContext(), asm_label, /*literal=*/true)); + cxx_method_decl->addAttr( + clang::AsmLabelAttr::CreateImplicit(getASTContext(), asm_label)); // Parameters on member function declarations in DWARF generally don't // have names, so we omit them when creating the ParmVarDecls. _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits