Skip to content

Commit c85fa79

Browse files
committed
[Attr] Fix -ast-print for asm attribute
Without this fix, the tests introduced here produce the following assert fail: ``` clang: /home/jdenny/llvm/clang/include/clang/Basic/AttributeCommonInfo.h:163: unsigned int clang::AttributeCommonInfo::getAttributeSpellingListIndex() const: Assertion `(isAttributeSpellingListCalculated() || AttrName) && "Spelling cannot be found"' failed. ``` The bug was introduced by D67368, which caused `AsmLabelAttr`'s spelling index to be set to `SpellingNotCalculated`. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D70349
1 parent 015b2e6 commit c85fa79

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

clang/lib/Sema/SemaDecl.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7019,8 +7019,9 @@ NamedDecl *Sema::ActOnVariableDeclarator(
70197019
}
70207020
}
70217021

7022-
NewVD->addAttr(::new (Context) AsmLabelAttr(
7023-
Context, SE->getStrTokenLoc(0), Label, /*IsLiteralLabel=*/true));
7022+
NewVD->addAttr(AsmLabelAttr::Create(Context, Label,
7023+
/*IsLiteralLabel=*/true,
7024+
SE->getStrTokenLoc(0)));
70247025
} else if (!ExtnameUndeclaredIdentifiers.empty()) {
70257026
llvm::DenseMap<IdentifierInfo*,AsmLabelAttr*>::iterator I =
70267027
ExtnameUndeclaredIdentifiers.find(NewVD->getIdentifier());
@@ -8923,9 +8924,9 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC,
89238924
if (Expr *E = (Expr*) D.getAsmLabel()) {
89248925
// The parser guarantees this is a string.
89258926
StringLiteral *SE = cast<StringLiteral>(E);
8926-
NewFD->addAttr(::new (Context)
8927-
AsmLabelAttr(Context, SE->getStrTokenLoc(0),
8928-
SE->getString(), /*IsLiteralLabel=*/true));
8927+
NewFD->addAttr(AsmLabelAttr::Create(Context, SE->getString(),
8928+
/*IsLiteralLabel=*/true,
8929+
SE->getStrTokenLoc(0)));
89298930
} else if (!ExtnameUndeclaredIdentifiers.empty()) {
89308931
llvm::DenseMap<IdentifierInfo*,AsmLabelAttr*>::iterator I =
89318932
ExtnameUndeclaredIdentifiers.find(NewFD->getIdentifier());

clang/test/AST/ast-print-attr.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,8 @@ using B = int ** __ptr32 *[3];
1010
// FIXME: Too many parens here!
1111
// CHECK: using C = int ((*))() __attribute__((cdecl));
1212
using C = int (*)() [[gnu::cdecl]];
13+
14+
// CHECK: int fun_asm() asm("");
15+
int fun_asm() asm("");
16+
// CHECK: int var_asm asm("");
17+
int var_asm asm("");

0 commit comments

Comments
 (0)