Skip to content

[clang][Attr] Remove 'literal label' form of AsmLabelAttr #151858

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions clang/include/clang/Basic/Attr.td
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}];
}
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/AST/Mangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
13 changes: 5 additions & 8 deletions clang/lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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
Expand Down
9 changes: 1 addition & 8 deletions clang/unittests/AST/DeclTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ TEST(Decl, AsmLabelAttr) {
StringRef Code = R"(
struct S {
void f() {}
void g() {}
};
)";
auto AST =
Expand All @@ -87,26 +86,20 @@ 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;
std::unique_ptr<ItaniumMangleContext> MC(
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) {
Expand Down
7 changes: 3 additions & 4 deletions lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2183,8 +2183,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);
Expand Down Expand Up @@ -7823,8 +7822,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.
Expand Down
Loading