jdenny created this revision. jdenny added reviewers: erichkeane, aaron.ballman. Herald added a project: clang.
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 <https://reviews.llvm.org/D67368>, which caused `AsmLabelAttr`'s spelling index to be set to `SpellingNotCalculated`. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D70349 Files: clang/lib/Sema/SemaDecl.cpp clang/test/AST/ast-print-attr.c Index: clang/test/AST/ast-print-attr.c =================================================================== --- clang/test/AST/ast-print-attr.c +++ clang/test/AST/ast-print-attr.c @@ -10,3 +10,8 @@ // FIXME: Too many parens here! // CHECK: using C = int ((*))() __attribute__((cdecl)); using C = int (*)() [[gnu::cdecl]]; + +// CHECK: int fun_asm() asm(""); +int fun_asm() asm(""); +// CHECK: int var_asm asm(""); +int var_asm asm(""); Index: clang/lib/Sema/SemaDecl.cpp =================================================================== --- clang/lib/Sema/SemaDecl.cpp +++ clang/lib/Sema/SemaDecl.cpp @@ -7017,8 +7017,9 @@ } } - NewVD->addAttr(::new (Context) AsmLabelAttr( - Context, SE->getStrTokenLoc(0), Label, /*IsLiteralLabel=*/true)); + NewVD->addAttr(AsmLabelAttr::Create(Context, Label, + /*IsLiteralLabel=*/true, + SE->getStrTokenLoc(0))); } else if (!ExtnameUndeclaredIdentifiers.empty()) { llvm::DenseMap<IdentifierInfo*,AsmLabelAttr*>::iterator I = ExtnameUndeclaredIdentifiers.find(NewVD->getIdentifier()); @@ -8921,9 +8922,9 @@ if (Expr *E = (Expr*) D.getAsmLabel()) { // The parser guarantees this is a string. StringLiteral *SE = cast<StringLiteral>(E); - NewFD->addAttr(::new (Context) - AsmLabelAttr(Context, SE->getStrTokenLoc(0), - SE->getString(), /*IsLiteralLabel=*/true)); + NewFD->addAttr(AsmLabelAttr::Create(Context, SE->getString(), + /*IsLiteralLabel=*/true, + SE->getStrTokenLoc(0))); } else if (!ExtnameUndeclaredIdentifiers.empty()) { llvm::DenseMap<IdentifierInfo*,AsmLabelAttr*>::iterator I = ExtnameUndeclaredIdentifiers.find(NewFD->getIdentifier());
Index: clang/test/AST/ast-print-attr.c =================================================================== --- clang/test/AST/ast-print-attr.c +++ clang/test/AST/ast-print-attr.c @@ -10,3 +10,8 @@ // FIXME: Too many parens here! // CHECK: using C = int ((*))() __attribute__((cdecl)); using C = int (*)() [[gnu::cdecl]]; + +// CHECK: int fun_asm() asm(""); +int fun_asm() asm(""); +// CHECK: int var_asm asm(""); +int var_asm asm(""); Index: clang/lib/Sema/SemaDecl.cpp =================================================================== --- clang/lib/Sema/SemaDecl.cpp +++ clang/lib/Sema/SemaDecl.cpp @@ -7017,8 +7017,9 @@ } } - NewVD->addAttr(::new (Context) AsmLabelAttr( - Context, SE->getStrTokenLoc(0), Label, /*IsLiteralLabel=*/true)); + NewVD->addAttr(AsmLabelAttr::Create(Context, Label, + /*IsLiteralLabel=*/true, + SE->getStrTokenLoc(0))); } else if (!ExtnameUndeclaredIdentifiers.empty()) { llvm::DenseMap<IdentifierInfo*,AsmLabelAttr*>::iterator I = ExtnameUndeclaredIdentifiers.find(NewVD->getIdentifier()); @@ -8921,9 +8922,9 @@ if (Expr *E = (Expr*) D.getAsmLabel()) { // The parser guarantees this is a string. StringLiteral *SE = cast<StringLiteral>(E); - NewFD->addAttr(::new (Context) - AsmLabelAttr(Context, SE->getStrTokenLoc(0), - SE->getString(), /*IsLiteralLabel=*/true)); + NewFD->addAttr(AsmLabelAttr::Create(Context, SE->getString(), + /*IsLiteralLabel=*/true, + SE->getStrTokenLoc(0))); } else if (!ExtnameUndeclaredIdentifiers.empty()) { llvm::DenseMap<IdentifierInfo*,AsmLabelAttr*>::iterator I = ExtnameUndeclaredIdentifiers.find(NewFD->getIdentifier());
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits