Skip to content

Commit cd8f348

Browse files
authored
[clang][Attr] Remove 'literal label' form of AsmLabelAttr (#151858)
This was added purely for the needs of LLDB. However, starting with #151355 and #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 #149827).
1 parent 872da99 commit cd8f348

File tree

5 files changed

+15
-35
lines changed

5 files changed

+15
-35
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,22 +1059,13 @@ def AVRSignal : InheritableAttr, TargetSpecificAttr<TargetAVR> {
10591059
def AsmLabel : InheritableAttr {
10601060
let Spellings = [CustomKeyword<"asm">, CustomKeyword<"__asm__">];
10611061
let Args = [
1062-
// Label specifies the mangled name for the decl.
1063-
StringArgument<"Label">,
1064-
1065-
// IsLiteralLabel specifies whether the label is literal (i.e. suppresses
1066-
// the global C symbol prefix) or not. If not, the mangle-suppression prefix
1067-
// ('\01') is omitted from the decl name at the LLVM IR level.
1068-
//
1069-
// Non-literal labels are used by some external AST sources like LLDB.
1070-
BoolArgument<"IsLiteralLabel", /*optional=*/0, /*fake=*/1>
1071-
];
1062+
// Label specifies the mangled name for the decl.
1063+
StringArgument<"Label">, ];
10721064
let SemaHandler = 0;
10731065
let Documentation = [AsmLabelDocs];
1074-
let AdditionalMembers =
1075-
[{
1066+
let AdditionalMembers = [{
10761067
bool isEquivalent(AsmLabelAttr *Other) const {
1077-
return getLabel() == Other->getLabel() && getIsLiteralLabel() == Other->getIsLiteralLabel();
1068+
return getLabel() == Other->getLabel();
10781069
}
10791070
}];
10801071
}

clang/lib/AST/Mangle.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,9 @@ void MangleContext::mangleName(GlobalDecl GD, raw_ostream &Out) {
161161
if (const AsmLabelAttr *ALA = D->getAttr<AsmLabelAttr>()) {
162162
// If we have an asm name, then we use it as the mangling.
163163

164-
// If the label isn't literal, or if this is an alias for an LLVM intrinsic,
164+
// If the label is an alias for an LLVM intrinsic,
165165
// do not add a "\01" prefix.
166-
if (!ALA->getIsLiteralLabel() || ALA->getLabel().starts_with("llvm.")) {
166+
if (ALA->getLabel().starts_with("llvm.")) {
167167
Out << ALA->getLabel();
168168
return;
169169
}

clang/lib/Sema/SemaDecl.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8113,9 +8113,7 @@ NamedDecl *Sema::ActOnVariableDeclarator(
81138113
}
81148114
}
81158115

8116-
NewVD->addAttr(AsmLabelAttr::Create(Context, Label,
8117-
/*IsLiteralLabel=*/true,
8118-
SE->getStrTokenLoc(0)));
8116+
NewVD->addAttr(AsmLabelAttr::Create(Context, Label, SE->getStrTokenLoc(0)));
81198117
} else if (!ExtnameUndeclaredIdentifiers.empty()) {
81208118
llvm::DenseMap<IdentifierInfo*,AsmLabelAttr*>::iterator I =
81218119
ExtnameUndeclaredIdentifiers.find(NewVD->getIdentifier());
@@ -10345,9 +10343,8 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC,
1034510343
if (Expr *E = D.getAsmLabel()) {
1034610344
// The parser guarantees this is a string.
1034710345
StringLiteral *SE = cast<StringLiteral>(E);
10348-
NewFD->addAttr(AsmLabelAttr::Create(Context, SE->getString(),
10349-
/*IsLiteralLabel=*/true,
10350-
SE->getStrTokenLoc(0)));
10346+
NewFD->addAttr(
10347+
AsmLabelAttr::Create(Context, SE->getString(), SE->getStrTokenLoc(0)));
1035110348
} else if (!ExtnameUndeclaredIdentifiers.empty()) {
1035210349
llvm::DenseMap<IdentifierInfo*,AsmLabelAttr*>::iterator I =
1035310350
ExtnameUndeclaredIdentifiers.find(NewFD->getIdentifier());
@@ -20598,8 +20595,8 @@ void Sema::ActOnPragmaRedefineExtname(IdentifierInfo* Name,
2059820595
LookupOrdinaryName);
2059920596
AttributeCommonInfo Info(AliasName, SourceRange(AliasNameLoc),
2060020597
AttributeCommonInfo::Form::Pragma());
20601-
AsmLabelAttr *Attr = AsmLabelAttr::CreateImplicit(
20602-
Context, AliasName->getName(), /*IsLiteralLabel=*/true, Info);
20598+
AsmLabelAttr *Attr =
20599+
AsmLabelAttr::CreateImplicit(Context, AliasName->getName(), Info);
2060320600

2060420601
// If a declaration that:
2060520602
// 1) declares a function or a variable

clang/unittests/AST/DeclTest.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ TEST(Decl, AsmLabelAttr) {
7474
StringRef Code = R"(
7575
struct S {
7676
void f() {}
77-
void g() {}
7877
};
7978
)";
8079
auto AST =
@@ -87,26 +86,20 @@ TEST(Decl, AsmLabelAttr) {
8786
const auto *DeclS =
8887
selectFirst<CXXRecordDecl>("d", match(cxxRecordDecl().bind("d"), Ctx));
8988
NamedDecl *DeclF = *DeclS->method_begin();
90-
NamedDecl *DeclG = *(++DeclS->method_begin());
9189

92-
// Attach asm labels to the decls: one literal, and one not.
93-
DeclF->addAttr(AsmLabelAttr::Create(Ctx, "foo", /*LiteralLabel=*/true));
94-
DeclG->addAttr(AsmLabelAttr::Create(Ctx, "goo", /*LiteralLabel=*/false));
90+
DeclF->addAttr(AsmLabelAttr::Create(Ctx, "foo"));
9591

9692
// Mangle the decl names.
9793
std::string MangleF, MangleG;
9894
std::unique_ptr<ItaniumMangleContext> MC(
9995
ItaniumMangleContext::create(Ctx, Diags));
10096
{
10197
llvm::raw_string_ostream OS_F(MangleF);
102-
llvm::raw_string_ostream OS_G(MangleG);
10398
MC->mangleName(DeclF, OS_F);
104-
MC->mangleName(DeclG, OS_G);
10599
}
106100

107101
ASSERT_EQ(MangleF, "\x01"
108102
"foo");
109-
ASSERT_EQ(MangleG, "goo");
110103
}
111104

112105
TEST(Decl, MangleDependentSizedArray) {

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2184,8 +2184,7 @@ FunctionDecl *TypeSystemClang::CreateFunctionDeclaration(
21842184
// This is done separately for member functions in
21852185
// AddMethodToCXXRecordType.
21862186
if (!asm_label.empty())
2187-
func_decl->addAttr(clang::AsmLabelAttr::CreateImplicit(ast, asm_label,
2188-
/*literal=*/true));
2187+
func_decl->addAttr(clang::AsmLabelAttr::CreateImplicit(ast, asm_label));
21892188

21902189
SetOwningModule(func_decl, owning_module);
21912190
decl_ctx->addDecl(func_decl);
@@ -7824,8 +7823,8 @@ clang::CXXMethodDecl *TypeSystemClang::AddMethodToCXXRecordType(
78247823
cxx_method_decl->addAttr(clang::UsedAttr::CreateImplicit(getASTContext()));
78257824

78267825
if (!asm_label.empty())
7827-
cxx_method_decl->addAttr(clang::AsmLabelAttr::CreateImplicit(
7828-
getASTContext(), asm_label, /*literal=*/true));
7826+
cxx_method_decl->addAttr(
7827+
clang::AsmLabelAttr::CreateImplicit(getASTContext(), asm_label));
78297828

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

0 commit comments

Comments
 (0)