Skip to content

Commit 0cfd822

Browse files
committed
[clang][Attr] Remove 'literal label' form of AsmLabelAttr (llvm#151858)
This was added purely for the needs of LLDB. However, starting with llvm#151355 and llvm#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 llvm#149827). (cherry picked from commit cd8f348)
1 parent 330359f commit 0cfd822

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
@@ -1084,22 +1084,13 @@ def AVRSignal : InheritableAttr, TargetSpecificAttr<TargetAVR> {
10841084
def AsmLabel : InheritableAttr {
10851085
let Spellings = [CustomKeyword<"asm">, CustomKeyword<"__asm__">];
10861086
let Args = [
1087-
// Label specifies the mangled name for the decl.
1088-
StringArgument<"Label">,
1089-
1090-
// IsLiteralLabel specifies whether the label is literal (i.e. suppresses
1091-
// the global C symbol prefix) or not. If not, the mangle-suppression prefix
1092-
// ('\01') is omitted from the decl name at the LLVM IR level.
1093-
//
1094-
// Non-literal labels are used by some external AST sources like LLDB.
1095-
BoolArgument<"IsLiteralLabel", /*optional=*/0, /*fake=*/1>
1096-
];
1087+
// Label specifies the mangled name for the decl.
1088+
StringArgument<"Label">, ];
10971089
let SemaHandler = 0;
10981090
let Documentation = [AsmLabelDocs];
1099-
let AdditionalMembers =
1100-
[{
1091+
let AdditionalMembers = [{
11011092
bool isEquivalent(AsmLabelAttr *Other) const {
1102-
return getLabel() == Other->getLabel() && getIsLiteralLabel() == Other->getIsLiteralLabel();
1093+
return getLabel() == Other->getLabel();
11031094
}
11041095
}];
11051096
}

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
@@ -8951,9 +8951,7 @@ NamedDecl *Sema::ActOnVariableDeclarator(
89518951
}
89528952
}
89538953

8954-
NewVD->addAttr(AsmLabelAttr::Create(Context, Label,
8955-
/*IsLiteralLabel=*/true,
8956-
SE->getStrTokenLoc(0)));
8954+
NewVD->addAttr(AsmLabelAttr::Create(Context, Label, SE->getStrTokenLoc(0)));
89578955
} else if (!ExtnameUndeclaredIdentifiers.empty()) {
89588956
llvm::DenseMap<IdentifierInfo*,AsmLabelAttr*>::iterator I =
89598957
ExtnameUndeclaredIdentifiers.find(NewVD->getIdentifier());
@@ -11254,9 +11252,8 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC,
1125411252
if (Expr *E = D.getAsmLabel()) {
1125511253
// The parser guarantees this is a string.
1125611254
StringLiteral *SE = cast<StringLiteral>(E);
11257-
NewFD->addAttr(AsmLabelAttr::Create(Context, SE->getString(),
11258-
/*IsLiteralLabel=*/true,
11259-
SE->getStrTokenLoc(0)));
11255+
NewFD->addAttr(
11256+
AsmLabelAttr::Create(Context, SE->getString(), SE->getStrTokenLoc(0)));
1126011257
} else if (!ExtnameUndeclaredIdentifiers.empty()) {
1126111258
llvm::DenseMap<IdentifierInfo*,AsmLabelAttr*>::iterator I =
1126211259
ExtnameUndeclaredIdentifiers.find(NewFD->getIdentifier());
@@ -21737,8 +21734,8 @@ void Sema::ActOnPragmaRedefineExtname(IdentifierInfo* Name,
2173721734
LookupOrdinaryName);
2173821735
AttributeCommonInfo Info(AliasName, SourceRange(AliasNameLoc),
2173921736
AttributeCommonInfo::Form::Pragma());
21740-
AsmLabelAttr *Attr = AsmLabelAttr::CreateImplicit(
21741-
Context, AliasName->getName(), /*IsLiteralLabel=*/true, Info);
21737+
AsmLabelAttr *Attr =
21738+
AsmLabelAttr::CreateImplicit(Context, AliasName->getName(), Info);
2174221739

2174321740
// If a declaration that:
2174421741
// 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
@@ -131,7 +131,6 @@ TEST(Decl, AsmLabelAttr) {
131131
StringRef Code = R"(
132132
struct S {
133133
void f() {}
134-
void g() {}
135134
};
136135
)";
137136
auto AST =
@@ -144,26 +143,20 @@ TEST(Decl, AsmLabelAttr) {
144143
const auto *DeclS =
145144
selectFirst<CXXRecordDecl>("d", match(cxxRecordDecl().bind("d"), Ctx));
146145
NamedDecl *DeclF = *DeclS->method_begin();
147-
NamedDecl *DeclG = *(++DeclS->method_begin());
148146

149-
// Attach asm labels to the decls: one literal, and one not.
150-
DeclF->addAttr(AsmLabelAttr::Create(Ctx, "foo", /*LiteralLabel=*/true));
151-
DeclG->addAttr(AsmLabelAttr::Create(Ctx, "goo", /*LiteralLabel=*/false));
147+
DeclF->addAttr(AsmLabelAttr::Create(Ctx, "foo"));
152148

153149
// Mangle the decl names.
154150
std::string MangleF, MangleG;
155151
std::unique_ptr<ItaniumMangleContext> MC(
156152
ItaniumMangleContext::create(Ctx, Diags));
157153
{
158154
llvm::raw_string_ostream OS_F(MangleF);
159-
llvm::raw_string_ostream OS_G(MangleG);
160155
MC->mangleName(DeclF, OS_F);
161-
MC->mangleName(DeclG, OS_G);
162156
}
163157

164158
ASSERT_EQ(MangleF, "\x01"
165159
"foo");
166-
ASSERT_EQ(MangleG, "goo");
167160
}
168161

169162
TEST(Decl, MangleDependentSizedArray) {

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2219,8 +2219,7 @@ FunctionDecl *TypeSystemClang::CreateFunctionDeclaration(
22192219
// This is done separately for member functions in
22202220
// AddMethodToCXXRecordType.
22212221
if (!asm_label.empty())
2222-
func_decl->addAttr(clang::AsmLabelAttr::CreateImplicit(ast, asm_label,
2223-
/*literal=*/true));
2222+
func_decl->addAttr(clang::AsmLabelAttr::CreateImplicit(ast, asm_label));
22242223

22252224
SetOwningModule(func_decl, owning_module);
22262225
decl_ctx->addDecl(func_decl);
@@ -7951,8 +7950,8 @@ clang::CXXMethodDecl *TypeSystemClang::AddMethodToCXXRecordType(
79517950
cxx_method_decl->addAttr(clang::UsedAttr::CreateImplicit(getASTContext()));
79527951

79537952
if (!asm_label.empty())
7954-
cxx_method_decl->addAttr(clang::AsmLabelAttr::CreateImplicit(
7955-
getASTContext(), asm_label, /*literal=*/true));
7953+
cxx_method_decl->addAttr(
7954+
clang::AsmLabelAttr::CreateImplicit(getASTContext(), asm_label));
79567955

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

0 commit comments

Comments
 (0)