From b6d4d51f8f5aab311df34c753b925760578729bd Mon Sep 17 00:00:00 2001 From: Richard Sandiford Date: Tue, 11 Apr 2023 16:11:32 +0100 Subject: [PATCH] [clang] Specify attribute syntax & spelling with a single argument When constructing an attribute, the syntactic form was specified using two arguments: an attribute-independent syntax type and an attribute-specific spelling index. This patch replaces them with a single argument. In most cases, that's done using a new Form class that combines the syntax and spelling into a single object. This has the minor benefit of removing a couple of constructors. But the main purpose is to allow additional information to be stored as well, beyond just the syntax and spelling enums. In the case of the attribute-specific Create and CreateImplicit functions, the patch instead uses the attribute-specific spelling enum. This helps to ensure that the syntax and spelling are consistent with each other and with the Attr.td definition. If a Create or CreateImplicit caller specified a syntax and a spelling, the patch drops the syntax argument and keeps the spelling. If the caller instead specified only a syntax (so that the spelling was SpellingNotCalculated), the patch simply drops the syntax argument. There were two cases of the latter: TargetVersion and Weak. TargetVersionAttrs were created with GNU syntax, which matches their definition in Attr.td, but which is also the default. WeakAttrs were created with Pragma syntax, which does not match their definition in Attr.td. Dropping the argument switches them to AS_GNU too (to match [GCC<"weak">]). Differential Revision: https://reviews.llvm.org/D148102 --- clang/include/clang/Basic/AttributeCommonInfo.h | 58 ++++++++------- clang/include/clang/Parse/Parser.h | 18 ++--- clang/include/clang/Sema/ParsedAttr.h | 85 ++++++++++------------ clang/lib/AST/ASTImporter.cpp | 3 +- clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp | 2 +- clang/lib/Parse/ParseDecl.cpp | 96 +++++++++++-------------- clang/lib/Sema/HLSLExternalSemaSource.cpp | 4 +- clang/lib/Sema/SemaAttr.cpp | 1 - clang/lib/Sema/SemaDecl.cpp | 33 ++++----- clang/lib/Sema/SemaDeclAttr.cpp | 6 +- clang/lib/Sema/SemaDeclCXX.cpp | 7 +- clang/lib/Sema/SemaObjCProperty.cpp | 6 +- clang/lib/Sema/SemaOpenMP.cpp | 21 ++---- clang/lib/Sema/SemaType.cpp | 3 +- clang/lib/Serialization/ASTReaderDecl.cpp | 7 +- clang/utils/TableGen/ClangAttrEmitter.cpp | 46 ++++++++---- 16 files changed, 192 insertions(+), 204 deletions(-) diff --git a/clang/include/clang/Basic/AttributeCommonInfo.h b/clang/include/clang/Basic/AttributeCommonInfo.h index f38f968..7925b9c 100644 --- a/clang/include/clang/Basic/AttributeCommonInfo.h +++ b/clang/include/clang/Basic/AttributeCommonInfo.h @@ -80,50 +80,58 @@ protected: static constexpr unsigned SpellingNotCalculated = 0xf; public: - AttributeCommonInfo(const IdentifierInfo *AttrName, - const IdentifierInfo *ScopeName, SourceRange AttrRange, - SourceLocation ScopeLoc, Syntax SyntaxUsed) - : AttrName(AttrName), ScopeName(ScopeName), AttrRange(AttrRange), - ScopeLoc(ScopeLoc), - AttrKind(getParsedKind(AttrName, ScopeName, SyntaxUsed)), - SyntaxUsed(SyntaxUsed), SpellingIndex(SpellingNotCalculated) {} + /// Combines information about the source-code form of an attribute, + /// including its syntax and spelling. + class Form { + public: + constexpr Form(Syntax SyntaxUsed, + unsigned SpellingIndex = SpellingNotCalculated) + : SyntaxUsed(SyntaxUsed), SpellingIndex(SpellingIndex) {} + + Syntax getSyntax() const { return Syntax(SyntaxUsed); } + unsigned getSpellingIndex() const { return SpellingIndex; } + + private: + unsigned SyntaxUsed : 4; + unsigned SpellingIndex : 4; + }; AttributeCommonInfo(const IdentifierInfo *AttrName, const IdentifierInfo *ScopeName, SourceRange AttrRange, - SourceLocation ScopeLoc, Kind AttrKind, Syntax SyntaxUsed) + SourceLocation ScopeLoc, Form FormUsed) : AttrName(AttrName), ScopeName(ScopeName), AttrRange(AttrRange), - ScopeLoc(ScopeLoc), AttrKind(AttrKind), SyntaxUsed(SyntaxUsed), - SpellingIndex(SpellingNotCalculated) {} + ScopeLoc(ScopeLoc), + AttrKind(getParsedKind(AttrName, ScopeName, FormUsed.getSyntax())), + SyntaxUsed(FormUsed.getSyntax()), + SpellingIndex(FormUsed.getSpellingIndex()) {} AttributeCommonInfo(const IdentifierInfo *AttrName, const IdentifierInfo *ScopeName, SourceRange AttrRange, - SourceLocation ScopeLoc, Kind AttrKind, Syntax SyntaxUsed, - unsigned Spelling) + SourceLocation ScopeLoc, Kind AttrKind, Form FormUsed) : AttrName(AttrName), ScopeName(ScopeName), AttrRange(AttrRange), - ScopeLoc(ScopeLoc), AttrKind(AttrKind), SyntaxUsed(SyntaxUsed), - SpellingIndex(Spelling) {} + ScopeLoc(ScopeLoc), AttrKind(AttrKind), + SyntaxUsed(FormUsed.getSyntax()), + SpellingIndex(FormUsed.getSpellingIndex()) {} AttributeCommonInfo(const IdentifierInfo *AttrName, SourceRange AttrRange, - Syntax SyntaxUsed) + Form FormUsed) : AttrName(AttrName), ScopeName(nullptr), AttrRange(AttrRange), - ScopeLoc(), AttrKind(getParsedKind(AttrName, ScopeName, SyntaxUsed)), - SyntaxUsed(SyntaxUsed), SpellingIndex(SpellingNotCalculated) {} - - AttributeCommonInfo(SourceRange AttrRange, Kind K, Syntax SyntaxUsed) - : AttrName(nullptr), ScopeName(nullptr), AttrRange(AttrRange), ScopeLoc(), - AttrKind(K), SyntaxUsed(SyntaxUsed), - SpellingIndex(SpellingNotCalculated) {} + ScopeLoc(), + AttrKind(getParsedKind(AttrName, ScopeName, FormUsed.getSyntax())), + SyntaxUsed(FormUsed.getSyntax()), + SpellingIndex(FormUsed.getSpellingIndex()) {} - AttributeCommonInfo(SourceRange AttrRange, Kind K, Syntax SyntaxUsed, - unsigned Spelling) + AttributeCommonInfo(SourceRange AttrRange, Kind K, Form FormUsed) : AttrName(nullptr), ScopeName(nullptr), AttrRange(AttrRange), ScopeLoc(), - AttrKind(K), SyntaxUsed(SyntaxUsed), SpellingIndex(Spelling) {} + AttrKind(K), SyntaxUsed(FormUsed.getSyntax()), + SpellingIndex(FormUsed.getSpellingIndex()) {} AttributeCommonInfo(AttributeCommonInfo &&) = default; AttributeCommonInfo(const AttributeCommonInfo &) = default; Kind getParsedKind() const { return Kind(AttrKind); } Syntax getSyntax() const { return Syntax(SyntaxUsed); } + Form getForm() const { return Form(getSyntax(), SpellingIndex); } const IdentifierInfo *getAttrName() const { return AttrName; } SourceLocation getLoc() const { return AttrRange.getBegin(); } SourceRange getRange() const { return AttrRange; } diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h index 2174852..fc892d7 100644 --- a/clang/include/clang/Parse/Parser.h +++ b/clang/include/clang/Parse/Parser.h @@ -2762,7 +2762,7 @@ private: ParseAttributeArgsCommon(IdentifierInfo *AttrName, SourceLocation AttrNameLoc, ParsedAttributes &Attrs, SourceLocation *EndLoc, IdentifierInfo *ScopeName, SourceLocation ScopeLoc, - ParsedAttr::Syntax Syntax); + ParsedAttr::Form Form); enum ParseAttrKindMask { PAKM_GNU = 1 << 0, @@ -2823,14 +2823,14 @@ private: SourceLocation AttrNameLoc, ParsedAttributes &Attrs, SourceLocation *EndLoc, IdentifierInfo *ScopeName, SourceLocation ScopeLoc, - ParsedAttr::Syntax Syntax, Declarator *D); + ParsedAttr::Form Form, Declarator *D); IdentifierLoc *ParseIdentifierLoc(); unsigned ParseClangAttributeArgs(IdentifierInfo *AttrName, SourceLocation AttrNameLoc, ParsedAttributes &Attrs, SourceLocation *EndLoc, IdentifierInfo *ScopeName, SourceLocation ScopeLoc, - ParsedAttr::Syntax Syntax); + ParsedAttr::Form Form); void ReplayOpenMPAttributeTokens(CachedTokens &OpenMPTokens) { // If parsing the attributes found an OpenMP directive, emit those tokens @@ -2949,7 +2949,7 @@ private: SourceLocation *endLoc, IdentifierInfo *ScopeName, SourceLocation ScopeLoc, - ParsedAttr::Syntax Syntax); + ParsedAttr::Form Form); std::optional ParseAvailabilitySpec(); ExprResult ParseAvailabilityCheckExpr(SourceLocation StartLoc); @@ -2960,7 +2960,7 @@ private: SourceLocation *EndLoc, IdentifierInfo *ScopeName, SourceLocation ScopeLoc, - ParsedAttr::Syntax Syntax); + ParsedAttr::Form Form); void ParseObjCBridgeRelatedAttribute(IdentifierInfo &ObjCBridgeRelated, SourceLocation ObjCBridgeRelatedLoc, @@ -2968,7 +2968,7 @@ private: SourceLocation *EndLoc, IdentifierInfo *ScopeName, SourceLocation ScopeLoc, - ParsedAttr::Syntax Syntax); + ParsedAttr::Form Form); void ParseSwiftNewTypeAttribute(IdentifierInfo &AttrName, SourceLocation AttrNameLoc, @@ -2976,7 +2976,7 @@ private: SourceLocation *EndLoc, IdentifierInfo *ScopeName, SourceLocation ScopeLoc, - ParsedAttr::Syntax Syntax); + ParsedAttr::Form Form); void ParseTypeTagForDatatypeAttribute(IdentifierInfo &AttrName, SourceLocation AttrNameLoc, @@ -2984,14 +2984,14 @@ private: SourceLocation *EndLoc, IdentifierInfo *ScopeName, SourceLocation ScopeLoc, - ParsedAttr::Syntax Syntax); + ParsedAttr::Form Form); void ParseAttributeWithTypeArg(IdentifierInfo &AttrName, SourceLocation AttrNameLoc, ParsedAttributes &Attrs, IdentifierInfo *ScopeName, SourceLocation ScopeLoc, - ParsedAttr::Syntax Syntax); + ParsedAttr::Form Form); void ParseTypeofSpecifier(DeclSpec &DS); SourceLocation ParseDecltypeSpecifier(DeclSpec &DS); diff --git a/clang/include/clang/Sema/ParsedAttr.h b/clang/include/clang/Sema/ParsedAttr.h index 5f45668..345c3c8 100644 --- a/clang/include/clang/Sema/ParsedAttr.h +++ b/clang/include/clang/Sema/ParsedAttr.h @@ -204,10 +204,9 @@ private: /// Constructor for attributes with expression arguments. ParsedAttr(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, - ArgsUnion *args, unsigned numArgs, Syntax syntaxUsed, + ArgsUnion *args, unsigned numArgs, Form formUsed, SourceLocation ellipsisLoc) - : AttributeCommonInfo(attrName, scopeName, attrRange, scopeLoc, - syntaxUsed), + : AttributeCommonInfo(attrName, scopeName, attrRange, scopeLoc, formUsed), EllipsisLoc(ellipsisLoc), NumArgs(numArgs), Invalid(false), UsedAsTypeAttr(false), IsAvailability(false), IsTypeTagForDatatype(false), IsProperty(false), HasParsedType(false), @@ -223,10 +222,9 @@ private: IdentifierLoc *Parm, const AvailabilityChange &introduced, const AvailabilityChange &deprecated, const AvailabilityChange &obsoleted, SourceLocation unavailable, - const Expr *messageExpr, Syntax syntaxUsed, SourceLocation strict, + const Expr *messageExpr, Form formUsed, SourceLocation strict, const Expr *replacementExpr) - : AttributeCommonInfo(attrName, scopeName, attrRange, scopeLoc, - syntaxUsed), + : AttributeCommonInfo(attrName, scopeName, attrRange, scopeLoc, formUsed), NumArgs(1), Invalid(false), UsedAsTypeAttr(false), IsAvailability(true), IsTypeTagForDatatype(false), IsProperty(false), HasParsedType(false), HasProcessingCache(false), IsPragmaClangAttribute(false), @@ -242,9 +240,8 @@ private: ParsedAttr(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, IdentifierLoc *Parm1, IdentifierLoc *Parm2, IdentifierLoc *Parm3, - Syntax syntaxUsed) - : AttributeCommonInfo(attrName, scopeName, attrRange, scopeLoc, - syntaxUsed), + Form formUsed) + : AttributeCommonInfo(attrName, scopeName, attrRange, scopeLoc, formUsed), NumArgs(3), Invalid(false), UsedAsTypeAttr(false), IsAvailability(false), IsTypeTagForDatatype(false), IsProperty(false), HasParsedType(false), HasProcessingCache(false), @@ -259,9 +256,8 @@ private: ParsedAttr(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, IdentifierLoc *ArgKind, ParsedType matchingCType, - bool layoutCompatible, bool mustBeNull, Syntax syntaxUsed) - : AttributeCommonInfo(attrName, scopeName, attrRange, scopeLoc, - syntaxUsed), + bool layoutCompatible, bool mustBeNull, Form formUsed) + : AttributeCommonInfo(attrName, scopeName, attrRange, scopeLoc, formUsed), NumArgs(1), Invalid(false), UsedAsTypeAttr(false), IsAvailability(false), IsTypeTagForDatatype(true), IsProperty(false), HasParsedType(false), HasProcessingCache(false), @@ -277,9 +273,8 @@ private: /// Constructor for attributes with a single type argument. ParsedAttr(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, - ParsedType typeArg, Syntax syntaxUsed) - : AttributeCommonInfo(attrName, scopeName, attrRange, scopeLoc, - syntaxUsed), + ParsedType typeArg, Form formUsed) + : AttributeCommonInfo(attrName, scopeName, attrRange, scopeLoc, formUsed), NumArgs(0), Invalid(false), UsedAsTypeAttr(false), IsAvailability(false), IsTypeTagForDatatype(false), IsProperty(false), HasParsedType(true), HasProcessingCache(false), @@ -290,10 +285,8 @@ private: /// Constructor for microsoft __declspec(property) attribute. ParsedAttr(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, - IdentifierInfo *getterId, IdentifierInfo *setterId, - Syntax syntaxUsed) - : AttributeCommonInfo(attrName, scopeName, attrRange, scopeLoc, - syntaxUsed), + IdentifierInfo *getterId, IdentifierInfo *setterId, Form formUsed) + : AttributeCommonInfo(attrName, scopeName, attrRange, scopeLoc, formUsed), NumArgs(0), Invalid(false), UsedAsTypeAttr(false), IsAvailability(false), IsTypeTagForDatatype(false), IsProperty(true), HasParsedType(false), HasProcessingCache(false), @@ -724,8 +717,7 @@ public: ParsedAttr *create(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, - ArgsUnion *args, unsigned numArgs, - ParsedAttr::Syntax syntax, + ArgsUnion *args, unsigned numArgs, ParsedAttr::Form form, SourceLocation ellipsisLoc = SourceLocation()) { size_t temp = ParsedAttr::totalSizeToAlloc(numArgs, 0, 0, 0, 0)); return add(new (memory) ParsedAttr(attrName, attrRange, scopeName, scopeLoc, - args, numArgs, syntax, ellipsisLoc)); + args, numArgs, form, ellipsisLoc)); } ParsedAttr *create(IdentifierInfo *attrName, SourceRange attrRange, @@ -747,24 +739,24 @@ public: const AvailabilityChange &deprecated, const AvailabilityChange &obsoleted, SourceLocation unavailable, const Expr *MessageExpr, - ParsedAttr::Syntax syntax, SourceLocation strict, + ParsedAttr::Form form, SourceLocation strict, const Expr *ReplacementExpr) { void *memory = allocate(AttributeFactory::AvailabilityAllocSize); return add(new (memory) ParsedAttr( attrName, attrRange, scopeName, scopeLoc, Param, introduced, deprecated, - obsoleted, unavailable, MessageExpr, syntax, strict, ReplacementExpr)); + obsoleted, unavailable, MessageExpr, form, strict, ReplacementExpr)); } ParsedAttr *create(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, IdentifierLoc *Param1, IdentifierLoc *Param2, - IdentifierLoc *Param3, ParsedAttr::Syntax syntax) { + IdentifierLoc *Param3, ParsedAttr::Form form) { void *memory = allocate( ParsedAttr::totalSizeToAlloc(3, 0, 0, 0, 0)); return add(new (memory) ParsedAttr(attrName, attrRange, scopeName, scopeLoc, - Param1, Param2, Param3, syntax)); + Param1, Param2, Param3, form)); } ParsedAttr * @@ -772,34 +764,34 @@ public: IdentifierInfo *scopeName, SourceLocation scopeLoc, IdentifierLoc *argumentKind, ParsedType matchingCType, bool layoutCompatible, - bool mustBeNull, ParsedAttr::Syntax syntax) { + bool mustBeNull, ParsedAttr::Form form) { void *memory = allocate(AttributeFactory::TypeTagForDatatypeAllocSize); return add(new (memory) ParsedAttr(attrName, attrRange, scopeName, scopeLoc, argumentKind, matchingCType, - layoutCompatible, mustBeNull, syntax)); + layoutCompatible, mustBeNull, form)); } ParsedAttr *createTypeAttribute(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, ParsedType typeArg, - ParsedAttr::Syntax syntaxUsed) { + ParsedAttr::Form formUsed) { void *memory = allocate( ParsedAttr::totalSizeToAlloc(0, 0, 0, 1, 0)); return add(new (memory) ParsedAttr(attrName, attrRange, scopeName, scopeLoc, - typeArg, syntaxUsed)); + typeArg, formUsed)); } ParsedAttr * createPropertyAttribute(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, IdentifierInfo *getterId, IdentifierInfo *setterId, - ParsedAttr::Syntax syntaxUsed) { + ParsedAttr::Form formUsed) { void *memory = allocate(AttributeFactory::PropertyAllocSize); return add(new (memory) ParsedAttr(attrName, attrRange, scopeName, scopeLoc, - getterId, setterId, syntaxUsed)); + getterId, setterId, formUsed)); } }; @@ -949,11 +941,10 @@ public: /// Add attribute with expression arguments. ParsedAttr *addNew(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, - ArgsUnion *args, unsigned numArgs, - ParsedAttr::Syntax syntax, + ArgsUnion *args, unsigned numArgs, ParsedAttr::Form form, SourceLocation ellipsisLoc = SourceLocation()) { ParsedAttr *attr = pool.create(attrName, attrRange, scopeName, scopeLoc, - args, numArgs, syntax, ellipsisLoc); + args, numArgs, form, ellipsisLoc); addAtEnd(attr); return attr; } @@ -965,11 +956,11 @@ public: const AvailabilityChange &deprecated, const AvailabilityChange &obsoleted, SourceLocation unavailable, const Expr *MessageExpr, - ParsedAttr::Syntax syntax, SourceLocation strict, + ParsedAttr::Form form, SourceLocation strict, const Expr *ReplacementExpr) { ParsedAttr *attr = pool.create( attrName, attrRange, scopeName, scopeLoc, Param, introduced, deprecated, - obsoleted, unavailable, MessageExpr, syntax, strict, ReplacementExpr); + obsoleted, unavailable, MessageExpr, form, strict, ReplacementExpr); addAtEnd(attr); return attr; } @@ -978,9 +969,9 @@ public: ParsedAttr *addNew(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, IdentifierLoc *Param1, IdentifierLoc *Param2, - IdentifierLoc *Param3, ParsedAttr::Syntax syntax) { + IdentifierLoc *Param3, ParsedAttr::Form form) { ParsedAttr *attr = pool.create(attrName, attrRange, scopeName, scopeLoc, - Param1, Param2, Param3, syntax); + Param1, Param2, Param3, form); addAtEnd(attr); return attr; } @@ -991,10 +982,10 @@ public: IdentifierInfo *scopeName, SourceLocation scopeLoc, IdentifierLoc *argumentKind, ParsedType matchingCType, bool layoutCompatible, - bool mustBeNull, ParsedAttr::Syntax syntax) { + bool mustBeNull, ParsedAttr::Form form) { ParsedAttr *attr = pool.createTypeTagForDatatype( attrName, attrRange, scopeName, scopeLoc, argumentKind, matchingCType, - layoutCompatible, mustBeNull, syntax); + layoutCompatible, mustBeNull, form); addAtEnd(attr); return attr; } @@ -1002,10 +993,9 @@ public: /// Add an attribute with a single type argument. ParsedAttr *addNewTypeAttr(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, - ParsedType typeArg, - ParsedAttr::Syntax syntaxUsed) { + ParsedType typeArg, ParsedAttr::Form formUsed) { ParsedAttr *attr = pool.createTypeAttribute(attrName, attrRange, scopeName, - scopeLoc, typeArg, syntaxUsed); + scopeLoc, typeArg, formUsed); addAtEnd(attr); return attr; } @@ -1015,10 +1005,9 @@ public: addNewPropertyAttr(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, IdentifierInfo *getterId, IdentifierInfo *setterId, - ParsedAttr::Syntax syntaxUsed) { - ParsedAttr *attr = - pool.createPropertyAttribute(attrName, attrRange, scopeName, scopeLoc, - getterId, setterId, syntaxUsed); + ParsedAttr::Form formUsed) { + ParsedAttr *attr = pool.createPropertyAttribute( + attrName, attrRange, scopeName, scopeLoc, getterId, setterId, formUsed); addAtEnd(attr); return attr; } diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index 320c302..10392d2 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -8815,8 +8815,7 @@ public: return; AttributeCommonInfo ToI(ToAttrName, ToScopeName, ToAttrRange, ToScopeLoc, - FromAttr->getParsedKind(), FromAttr->getSyntax(), - FromAttr->getAttributeSpellingListIndex()); + FromAttr->getParsedKind(), FromAttr->getForm()); // The "SemanticSpelling" is not needed to be passed to the constructor. // That value is recalculated from the SpellingListIndex if needed. ToAttr = T::Create(Importer.getToContext(), diff --git a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp index 4ac28ee..33898c5 100644 --- a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp @@ -190,7 +190,7 @@ static RecordDecl *buildRecordForGlobalizedVars( IntegerLiteral::Create(C, Align, C.getIntTypeForBitwidth(32, /*Signed=*/0), SourceLocation()), - {}, AttributeCommonInfo::AS_GNU, AlignedAttr::GNU_aligned)); + {}, AlignedAttr::GNU_aligned)); } GlobalizedRD->addDecl(Field); MappedDeclsFields.try_emplace(VD, Field); diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index 450c703..e754081 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -347,7 +347,7 @@ void Parser::ParseAttributeWithTypeArg(IdentifierInfo &AttrName, ParsedAttributes &Attrs, IdentifierInfo *ScopeName, SourceLocation ScopeLoc, - ParsedAttr::Syntax Syntax) { + ParsedAttr::Form Form) { BalancedDelimiterTracker Parens(*this, tok::l_paren); Parens.consumeOpen(); @@ -364,16 +364,16 @@ void Parser::ParseAttributeWithTypeArg(IdentifierInfo &AttrName, if (T.isUsable()) Attrs.addNewTypeAttr(&AttrName, SourceRange(AttrNameLoc, Parens.getCloseLocation()), - ScopeName, ScopeLoc, T.get(), Syntax); + ScopeName, ScopeLoc, T.get(), Form); else Attrs.addNew(&AttrName, SourceRange(AttrNameLoc, Parens.getCloseLocation()), - ScopeName, ScopeLoc, nullptr, 0, Syntax); + ScopeName, ScopeLoc, nullptr, 0, Form); } unsigned Parser::ParseAttributeArgsCommon( IdentifierInfo *AttrName, SourceLocation AttrNameLoc, ParsedAttributes &Attrs, SourceLocation *EndLoc, IdentifierInfo *ScopeName, - SourceLocation ScopeLoc, ParsedAttr::Syntax Syntax) { + SourceLocation ScopeLoc, ParsedAttr::Form Form) { // Ignore the left paren location for now. ConsumeParen(); @@ -392,7 +392,7 @@ unsigned Parser::ParseAttributeArgsCommon( bool IsIdentifierArg = AttributeHasVariadicIdentifierArg || attributeHasIdentifierArg(*AttrName); ParsedAttr::Kind AttrKind = - ParsedAttr::getParsedKind(AttrName, ScopeName, Syntax); + ParsedAttr::getParsedKind(AttrName, ScopeName, Form.getSyntax()); // If we don't know how to parse this attribute, but this is the only // token in this argument, assume it's meant to be an identifier. @@ -493,10 +493,10 @@ unsigned Parser::ParseAttributeArgsCommon( if (AttributeIsTypeArgAttr && !TheParsedType.get().isNull()) { Attrs.addNewTypeAttr(AttrName, SourceRange(AttrNameLoc, RParen), - ScopeName, ScopeLoc, TheParsedType, Syntax); + ScopeName, ScopeLoc, TheParsedType, Form); } else { Attrs.addNew(AttrName, SourceRange(AttrLoc, RParen), ScopeName, ScopeLoc, - ArgExprs.data(), ArgExprs.size(), Syntax); + ArgExprs.data(), ArgExprs.size(), Form); } } @@ -511,36 +511,36 @@ unsigned Parser::ParseAttributeArgsCommon( void Parser::ParseGNUAttributeArgs( IdentifierInfo *AttrName, SourceLocation AttrNameLoc, ParsedAttributes &Attrs, SourceLocation *EndLoc, IdentifierInfo *ScopeName, - SourceLocation ScopeLoc, ParsedAttr::Syntax Syntax, Declarator *D) { + SourceLocation ScopeLoc, ParsedAttr::Form Form, Declarator *D) { assert(Tok.is(tok::l_paren) && "Attribute arg list not starting with '('"); ParsedAttr::Kind AttrKind = - ParsedAttr::getParsedKind(AttrName, ScopeName, Syntax); + ParsedAttr::getParsedKind(AttrName, ScopeName, Form.getSyntax()); if (AttrKind == ParsedAttr::AT_Availability) { ParseAvailabilityAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName, - ScopeLoc, Syntax); + ScopeLoc, Form); return; } else if (AttrKind == ParsedAttr::AT_ExternalSourceSymbol) { ParseExternalSourceSymbolAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, - ScopeName, ScopeLoc, Syntax); + ScopeName, ScopeLoc, Form); return; } else if (AttrKind == ParsedAttr::AT_ObjCBridgeRelated) { ParseObjCBridgeRelatedAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, - ScopeName, ScopeLoc, Syntax); + ScopeName, ScopeLoc, Form); return; } else if (AttrKind == ParsedAttr::AT_SwiftNewType) { ParseSwiftNewTypeAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName, - ScopeLoc, Syntax); + ScopeLoc, Form); return; } else if (AttrKind == ParsedAttr::AT_TypeTagForDatatype) { ParseTypeTagForDatatypeAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, - ScopeName, ScopeLoc, Syntax); + ScopeName, ScopeLoc, Form); return; } else if (attributeIsTypeArgAttr(*AttrName)) { ParseAttributeWithTypeArg(*AttrName, AttrNameLoc, Attrs, ScopeName, - ScopeLoc, Syntax); + ScopeLoc, Form); return; } @@ -560,41 +560,41 @@ void Parser::ParseGNUAttributeArgs( } ParseAttributeArgsCommon(AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName, - ScopeLoc, Syntax); + ScopeLoc, Form); } unsigned Parser::ParseClangAttributeArgs( IdentifierInfo *AttrName, SourceLocation AttrNameLoc, ParsedAttributes &Attrs, SourceLocation *EndLoc, IdentifierInfo *ScopeName, - SourceLocation ScopeLoc, ParsedAttr::Syntax Syntax) { + SourceLocation ScopeLoc, ParsedAttr::Form Form) { assert(Tok.is(tok::l_paren) && "Attribute arg list not starting with '('"); ParsedAttr::Kind AttrKind = - ParsedAttr::getParsedKind(AttrName, ScopeName, Syntax); + ParsedAttr::getParsedKind(AttrName, ScopeName, Form.getSyntax()); switch (AttrKind) { default: return ParseAttributeArgsCommon(AttrName, AttrNameLoc, Attrs, EndLoc, - ScopeName, ScopeLoc, Syntax); + ScopeName, ScopeLoc, Form); case ParsedAttr::AT_ExternalSourceSymbol: ParseExternalSourceSymbolAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, - ScopeName, ScopeLoc, Syntax); + ScopeName, ScopeLoc, Form); break; case ParsedAttr::AT_Availability: ParseAvailabilityAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName, - ScopeLoc, Syntax); + ScopeLoc, Form); break; case ParsedAttr::AT_ObjCBridgeRelated: ParseObjCBridgeRelatedAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, - ScopeName, ScopeLoc, Syntax); + ScopeName, ScopeLoc, Form); break; case ParsedAttr::AT_SwiftNewType: ParseSwiftNewTypeAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName, - ScopeLoc, Syntax); + ScopeLoc, Form); break; case ParsedAttr::AT_TypeTagForDatatype: ParseTypeTagForDatatypeAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, - ScopeName, ScopeLoc, Syntax); + ScopeName, ScopeLoc, Form); break; } return !Attrs.empty() ? Attrs.begin()->getNumArgs() : 0; @@ -1122,13 +1122,10 @@ VersionTuple Parser::ParseVersionTuple(SourceRange &Range) { /// 'replacement' '=' /// opt-message: /// 'message' '=' -void Parser::ParseAvailabilityAttribute(IdentifierInfo &Availability, - SourceLocation AvailabilityLoc, - ParsedAttributes &attrs, - SourceLocation *endLoc, - IdentifierInfo *ScopeName, - SourceLocation ScopeLoc, - ParsedAttr::Syntax Syntax) { +void Parser::ParseAvailabilityAttribute( + IdentifierInfo &Availability, SourceLocation AvailabilityLoc, + ParsedAttributes &attrs, SourceLocation *endLoc, IdentifierInfo *ScopeName, + SourceLocation ScopeLoc, ParsedAttr::Form Form) { enum { Introduced, Deprecated, Obsoleted, Unknown }; AvailabilityChange Changes[Unknown]; ExprResult MessageExpr, ReplacementExpr; @@ -1334,14 +1331,10 @@ void Parser::ParseAvailabilityAttribute(IdentifierInfo &Availability, // Record this attribute attrs.addNew(&Availability, - SourceRange(AvailabilityLoc, T.getCloseLocation()), - ScopeName, ScopeLoc, - Platform, - Changes[Introduced], - Changes[Deprecated], - Changes[Obsoleted], - UnavailableLoc, MessageExpr.get(), - Syntax, StrictLoc, ReplacementExpr.get()); + SourceRange(AvailabilityLoc, T.getCloseLocation()), ScopeName, + ScopeLoc, Platform, Changes[Introduced], Changes[Deprecated], + Changes[Obsoleted], UnavailableLoc, MessageExpr.get(), Form, + StrictLoc, ReplacementExpr.get()); } /// Parse the contents of the "external_source_symbol" attribute. @@ -1361,7 +1354,7 @@ void Parser::ParseAvailabilityAttribute(IdentifierInfo &Availability, void Parser::ParseExternalSourceSymbolAttribute( IdentifierInfo &ExternalSourceSymbol, SourceLocation Loc, ParsedAttributes &Attrs, SourceLocation *EndLoc, IdentifierInfo *ScopeName, - SourceLocation ScopeLoc, ParsedAttr::Syntax Syntax) { + SourceLocation ScopeLoc, ParsedAttr::Form Form) { // Opening '('. BalancedDelimiterTracker T(*this, tok::l_paren); if (T.expectAndConsume()) @@ -1473,7 +1466,7 @@ void Parser::ParseExternalSourceSymbolAttribute( ArgsUnion Args[] = {Language.get(), DefinedInExpr.get(), GeneratedDeclaration, USR.get()}; Attrs.addNew(&ExternalSourceSymbol, SourceRange(Loc, T.getCloseLocation()), - ScopeName, ScopeLoc, Args, std::size(Args), Syntax); + ScopeName, ScopeLoc, Args, std::size(Args), Form); } /// Parse the contents of the "objc_bridge_related" attribute. @@ -1490,7 +1483,7 @@ void Parser::ParseExternalSourceSymbolAttribute( void Parser::ParseObjCBridgeRelatedAttribute( IdentifierInfo &ObjCBridgeRelated, SourceLocation ObjCBridgeRelatedLoc, ParsedAttributes &Attrs, SourceLocation *EndLoc, IdentifierInfo *ScopeName, - SourceLocation ScopeLoc, ParsedAttr::Syntax Syntax) { + SourceLocation ScopeLoc, ParsedAttr::Form Form) { // Opening '('. BalancedDelimiterTracker T(*this, tok::l_paren); if (T.consumeOpen()) { @@ -1553,13 +1546,13 @@ void Parser::ParseObjCBridgeRelatedAttribute( Attrs.addNew(&ObjCBridgeRelated, SourceRange(ObjCBridgeRelatedLoc, T.getCloseLocation()), ScopeName, ScopeLoc, RelatedClass, ClassMethod, InstanceMethod, - Syntax); + Form); } void Parser::ParseSwiftNewTypeAttribute( IdentifierInfo &AttrName, SourceLocation AttrNameLoc, ParsedAttributes &Attrs, SourceLocation *EndLoc, IdentifierInfo *ScopeName, - SourceLocation ScopeLoc, ParsedAttr::Syntax Syntax) { + SourceLocation ScopeLoc, ParsedAttr::Form Form) { BalancedDelimiterTracker T(*this, tok::l_paren); // Opening '(' @@ -1594,16 +1587,13 @@ void Parser::ParseSwiftNewTypeAttribute( ArgsUnion Args[] = {SwiftType}; Attrs.addNew(&AttrName, SourceRange(AttrNameLoc, T.getCloseLocation()), - ScopeName, ScopeLoc, Args, std::size(Args), Syntax); + ScopeName, ScopeLoc, Args, std::size(Args), Form); } -void Parser::ParseTypeTagForDatatypeAttribute(IdentifierInfo &AttrName, - SourceLocation AttrNameLoc, - ParsedAttributes &Attrs, - SourceLocation *EndLoc, - IdentifierInfo *ScopeName, - SourceLocation ScopeLoc, - ParsedAttr::Syntax Syntax) { +void Parser::ParseTypeTagForDatatypeAttribute( + IdentifierInfo &AttrName, SourceLocation AttrNameLoc, + ParsedAttributes &Attrs, SourceLocation *EndLoc, IdentifierInfo *ScopeName, + SourceLocation ScopeLoc, ParsedAttr::Form Form) { assert(Tok.is(tok::l_paren) && "Attribute arg list not starting with '('"); BalancedDelimiterTracker T(*this, tok::l_paren); @@ -1652,7 +1642,7 @@ void Parser::ParseTypeTagForDatatypeAttribute(IdentifierInfo &AttrName, if (!T.consumeClose()) { Attrs.addNewTypeTagForDatatype(&AttrName, AttrNameLoc, ScopeName, ScopeLoc, ArgumentKind, MatchingCType.get(), - LayoutCompatible, MustBeNull, Syntax); + LayoutCompatible, MustBeNull, Form); } if (EndLoc) diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp b/clang/lib/Sema/HLSLExternalSemaSource.cpp index 3ff4e75..f29f92a 100644 --- a/clang/lib/Sema/HLSLExternalSemaSource.cpp +++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp @@ -71,7 +71,6 @@ struct BuiltinTypeDeclBuilder { // Don't let anyone derive from built-in types. Record->addAttr(FinalAttr::CreateImplicit(AST, SourceRange(), - AttributeCommonInfo::AS_Keyword, FinalAttr::Keyword_final)); } @@ -286,8 +285,7 @@ struct BuiltinTypeDeclBuilder { MethodDecl->setLexicalDeclContext(Record); MethodDecl->setAccess(AccessSpecifier::AS_public); MethodDecl->addAttr(AlwaysInlineAttr::CreateImplicit( - AST, SourceRange(), AttributeCommonInfo::AS_Keyword, - AlwaysInlineAttr::CXX11_clang_always_inline)); + AST, SourceRange(), AlwaysInlineAttr::CXX11_clang_always_inline)); Record->addDecl(MethodDecl); return *this; diff --git a/clang/lib/Sema/SemaAttr.cpp b/clang/lib/Sema/SemaAttr.cpp index 5080b22..46915c8 100644 --- a/clang/lib/Sema/SemaAttr.cpp +++ b/clang/lib/Sema/SemaAttr.cpp @@ -845,7 +845,6 @@ void Sema::ActOnPragmaUnused(const Token &IdTok, Scope *curScope, Diag(PragmaLoc, diag::warn_used_but_marked_unused) << Name; VD->addAttr(UnusedAttr::CreateImplicit(Context, IdTok.getLocation(), - AttributeCommonInfo::AS_Pragma, UnusedAttr::GNU_unused)); } diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 409c716..714456d 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -7781,9 +7781,9 @@ NamedDecl *Sema::ActOnVariableDeclarator( Diag(D.getDeclSpec().getConstexprSpecLoc(), diag::err_constinit_local_variable); else - NewVD->addAttr(ConstInitAttr::Create( - Context, D.getDeclSpec().getConstexprSpecLoc(), - AttributeCommonInfo::AS_Keyword, ConstInitAttr::Keyword_constinit)); + NewVD->addAttr( + ConstInitAttr::Create(Context, D.getDeclSpec().getConstexprSpecLoc(), + ConstInitAttr::Keyword_constinit)); break; } @@ -10148,8 +10148,7 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC, !NewFD->hasAttr()) { NewFD->addAttr(SectionAttr::CreateImplicit( Context, CodeSegStack.CurrentValue->getString(), - CodeSegStack.CurrentPragmaLocation, AttributeCommonInfo::AS_Pragma, - SectionAttr::Declspec_allocate)); + CodeSegStack.CurrentPragmaLocation, SectionAttr::Declspec_allocate)); if (UnifySection(CodeSegStack.CurrentValue->getString(), ASTContext::PSF_Implicit | ASTContext::PSF_Execute | ASTContext::PSF_Read, @@ -10795,8 +10794,7 @@ Attr *Sema::getImplicitCodeSegOrSectionAttrForFunction(const FunctionDecl *FD, CodeSegStack.CurrentValue) return SectionAttr::CreateImplicit( getASTContext(), CodeSegStack.CurrentValue->getString(), - CodeSegStack.CurrentPragmaLocation, AttributeCommonInfo::AS_Pragma, - SectionAttr::Declspec_allocate); + CodeSegStack.CurrentPragmaLocation, SectionAttr::Declspec_allocate); return nullptr; } @@ -11337,8 +11335,7 @@ static bool CheckMultiVersionAdditionalDecl( if (NewMVKind == MultiVersionKind::None && OldMVKind == MultiVersionKind::TargetVersion) { NewFD->addAttr(TargetVersionAttr::CreateImplicit( - S.Context, "default", NewFD->getSourceRange(), - AttributeCommonInfo::AS_GNU)); + S.Context, "default", NewFD->getSourceRange())); NewFD->setIsMultiVersion(); NewMVKind = MultiVersionKind::TargetVersion; if (!NewTVA) { @@ -11555,8 +11552,7 @@ static bool CheckMultiVersionFunction(Sema &S, FunctionDecl *NewFD, const auto *OldTVA = OldFD->getAttr(); if (OldTVA) { NewFD->addAttr(TargetVersionAttr::CreateImplicit( - S.Context, "default", NewFD->getSourceRange(), - AttributeCommonInfo::AS_GNU)); + S.Context, "default", NewFD->getSourceRange())); NewFD->setIsMultiVersion(); OldFD->setIsMultiVersion(); OldDecl = OldFD; @@ -14196,9 +14192,9 @@ void Sema::CheckCompleteVariableDeclaration(VarDecl *var) { } else if (Stack->CurrentValue) { SectionFlags |= ASTContext::PSF_Implicit; auto SectionName = Stack->CurrentValue->getString(); - var->addAttr(SectionAttr::CreateImplicit( - Context, SectionName, Stack->CurrentPragmaLocation, - AttributeCommonInfo::AS_Pragma, SectionAttr::Declspec_allocate)); + var->addAttr(SectionAttr::CreateImplicit(Context, SectionName, + Stack->CurrentPragmaLocation, + SectionAttr::Declspec_allocate)); if (UnifySection(SectionName, SectionFlags, var)) var->dropAttr(); } @@ -17665,9 +17661,10 @@ void Sema::ActOnStartCXXMemberDeclarations(Scope *S, Decl *TagD, Record->markAbstract(); if (FinalLoc.isValid()) { - Record->addAttr(FinalAttr::Create( - Context, FinalLoc, AttributeCommonInfo::AS_Keyword, - static_cast(IsFinalSpelledSealed))); + Record->addAttr(FinalAttr::Create(Context, FinalLoc, + IsFinalSpelledSealed + ? FinalAttr::Keyword_sealed + : FinalAttr::Keyword_final)); } // C++ [class]p2: // [...] The class-name is also inserted into the scope of the @@ -19890,7 +19887,7 @@ void Sema::ActOnPragmaWeakID(IdentifierInfo* Name, Decl *PrevDecl = LookupSingleName(TUScope, Name, NameLoc, LookupOrdinaryName); if (PrevDecl) { - PrevDecl->addAttr(WeakAttr::CreateImplicit(Context, PragmaLoc, AttributeCommonInfo::AS_Pragma)); + PrevDecl->addAttr(WeakAttr::CreateImplicit(Context, PragmaLoc)); } else { (void)WeakUndeclaredIdentifiers[Name].insert(WeakInfo(nullptr, NameLoc)); } diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 5e98dca..27cfde2 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -9558,8 +9558,7 @@ void Sema::DeclApplyPragmaWeak(Scope *S, NamedDecl *ND, const WeakInfo &W) { NamedDecl *NewD = DeclClonePragmaWeak(ND, W.getAlias(), W.getLocation()); NewD->addAttr( AliasAttr::CreateImplicit(Context, NDId->getName(), W.getLocation())); - NewD->addAttr(WeakAttr::CreateImplicit(Context, W.getLocation(), - AttributeCommonInfo::AS_Pragma)); + NewD->addAttr(WeakAttr::CreateImplicit(Context, W.getLocation())); WeakTopLevelDecl.push_back(NewD); // FIXME: "hideous" code from Sema::LazilyCreateBuiltin // to insert Decl at TU scope, sorry. @@ -9570,8 +9569,7 @@ void Sema::DeclApplyPragmaWeak(Scope *S, NamedDecl *ND, const WeakInfo &W) { PushOnScopeChains(NewD, S); CurContext = SavedContext; } else { // just add weak to existing - ND->addAttr(WeakAttr::CreateImplicit(Context, W.getLocation(), - AttributeCommonInfo::AS_Pragma)); + ND->addAttr(WeakAttr::CreateImplicit(Context, W.getLocation())); } } diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 4580626..524f0a9 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -3569,9 +3569,10 @@ Sema::ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS, Declarator &D, if (VS.isOverrideSpecified()) Member->addAttr(OverrideAttr::Create(Context, VS.getOverrideLoc())); if (VS.isFinalSpecified()) - Member->addAttr(FinalAttr::Create( - Context, VS.getFinalLoc(), AttributeCommonInfo::AS_Keyword, - static_cast(VS.isFinalSpelledSealed()))); + Member->addAttr(FinalAttr::Create(Context, VS.getFinalLoc(), + VS.isFinalSpelledSealed() + ? FinalAttr::Keyword_sealed + : FinalAttr::Keyword_final)); if (VS.getLastLocation().isValid()) { // Update the end location of a method that has a virt-specifiers. diff --git a/clang/lib/Sema/SemaObjCProperty.cpp b/clang/lib/Sema/SemaObjCProperty.cpp index 584c4a3..3317bfc 100644 --- a/clang/lib/Sema/SemaObjCProperty.cpp +++ b/clang/lib/Sema/SemaObjCProperty.cpp @@ -2508,8 +2508,7 @@ void Sema::ProcessPropertyDecl(ObjCPropertyDecl *property) { if (const SectionAttr *SA = property->getAttr()) GetterMethod->addAttr(SectionAttr::CreateImplicit( - Context, SA->getName(), Loc, AttributeCommonInfo::AS_GNU, - SectionAttr::GNU_section)); + Context, SA->getName(), Loc, SectionAttr::GNU_section)); if (getLangOpts().ObjCAutoRefCount) CheckARCMethodDecl(GetterMethod); @@ -2581,8 +2580,7 @@ void Sema::ProcessPropertyDecl(ObjCPropertyDecl *property) { CD->addDecl(SetterMethod); if (const SectionAttr *SA = property->getAttr()) SetterMethod->addAttr(SectionAttr::CreateImplicit( - Context, SA->getName(), Loc, AttributeCommonInfo::AS_GNU, - SectionAttr::GNU_section)); + Context, SA->getName(), Loc, SectionAttr::GNU_section)); // It's possible for the user to have set a very odd custom // setter selector that causes it to have a method family. if (getLangOpts().ObjCAutoRefCount) diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index 08ca536..ff5c3cc 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -4227,8 +4227,7 @@ void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { // function directly. getCurCapturedRegion()->TheCapturedDecl->addAttr( AlwaysInlineAttr::CreateImplicit( - Context, {}, AttributeCommonInfo::AS_Keyword, - AlwaysInlineAttr::Keyword_forceinline)); + Context, {}, AlwaysInlineAttr::Keyword_forceinline)); Sema::CapturedParamNameType ParamsTarget[] = { std::make_pair(StringRef(), QualType()) // __context with shared vars }; @@ -4272,8 +4271,7 @@ void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { // function directly. getCurCapturedRegion()->TheCapturedDecl->addAttr( AlwaysInlineAttr::CreateImplicit( - Context, {}, AttributeCommonInfo::AS_Keyword, - AlwaysInlineAttr::Keyword_forceinline)); + Context, {}, AlwaysInlineAttr::Keyword_forceinline)); ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, std::make_pair(StringRef(), QualType()), /*OpenMPCaptureLevel=*/1); @@ -4333,8 +4331,7 @@ void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { // function directly. getCurCapturedRegion()->TheCapturedDecl->addAttr( AlwaysInlineAttr::CreateImplicit( - Context, {}, AttributeCommonInfo::AS_Keyword, - AlwaysInlineAttr::Keyword_forceinline)); + Context, {}, AlwaysInlineAttr::Keyword_forceinline)); break; } case OMPD_taskloop: @@ -4380,8 +4377,7 @@ void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { // function directly. getCurCapturedRegion()->TheCapturedDecl->addAttr( AlwaysInlineAttr::CreateImplicit( - Context, {}, AttributeCommonInfo::AS_Keyword, - AlwaysInlineAttr::Keyword_forceinline)); + Context, {}, AlwaysInlineAttr::Keyword_forceinline)); break; } case OMPD_parallel_masked_taskloop: @@ -4433,8 +4429,7 @@ void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { // function directly. getCurCapturedRegion()->TheCapturedDecl->addAttr( AlwaysInlineAttr::CreateImplicit( - Context, {}, AttributeCommonInfo::AS_Keyword, - AlwaysInlineAttr::Keyword_forceinline)); + Context, {}, AlwaysInlineAttr::Keyword_forceinline)); break; } case OMPD_distribute_parallel_for_simd: @@ -4480,8 +4475,7 @@ void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { // function directly. getCurCapturedRegion()->TheCapturedDecl->addAttr( AlwaysInlineAttr::CreateImplicit( - Context, {}, AttributeCommonInfo::AS_Keyword, - AlwaysInlineAttr::Keyword_forceinline)); + Context, {}, AlwaysInlineAttr::Keyword_forceinline)); Sema::CapturedParamNameType ParamsTarget[] = { std::make_pair(StringRef(), QualType()) // __context with shared vars }; @@ -4583,8 +4577,7 @@ void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { // function directly. getCurCapturedRegion()->TheCapturedDecl->addAttr( AlwaysInlineAttr::CreateImplicit( - Context, {}, AttributeCommonInfo::AS_Keyword, - AlwaysInlineAttr::Keyword_forceinline)); + Context, {}, AlwaysInlineAttr::Keyword_forceinline)); break; } case OMPD_threadprivate: diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index 99e7ccf..8a7c31a 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -8970,8 +8970,7 @@ static void assignInheritanceModel(Sema &S, CXXRecordDecl *RD) { ? S.ImplicitMSInheritanceAttrLoc : RD->getSourceRange(); RD->addAttr(MSInheritanceAttr::CreateImplicit( - S.getASTContext(), BestCase, Loc, AttributeCommonInfo::AS_Microsoft, - MSInheritanceAttr::Spelling(IM))); + S.getASTContext(), BestCase, Loc, MSInheritanceAttr::Spelling(IM))); S.Consumer.AssignInheritanceModel(RD); } } diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp index aa3b21c..c72761c 100644 --- a/clang/lib/Serialization/ASTReaderDecl.cpp +++ b/clang/lib/Serialization/ASTReaderDecl.cpp @@ -3092,9 +3092,10 @@ Attr *ASTRecordReader::readAttr() { unsigned Syntax = Record.readInt(); unsigned SpellingIndex = Record.readInt(); - AttributeCommonInfo Info(AttrName, ScopeName, AttrRange, ScopeLoc, - AttributeCommonInfo::Kind(ParsedKind), - AttributeCommonInfo::Syntax(Syntax), SpellingIndex); + AttributeCommonInfo Info( + AttrName, ScopeName, AttrRange, ScopeLoc, + AttributeCommonInfo::Kind(ParsedKind), + {AttributeCommonInfo::Syntax(Syntax), SpellingIndex}); #include "clang/Serialization/AttrPCHRead.inc" diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp b/clang/utils/TableGen/ClangAttrEmitter.cpp index cb9f582..177d72f 100644 --- a/clang/utils/TableGen/ClangAttrEmitter.cpp +++ b/clang/utils/TableGen/ClangAttrEmitter.cpp @@ -2378,6 +2378,13 @@ static void emitClangAttrAcceptsExprPack(RecordKeeper &Records, OS << "#endif // CLANG_ATTR_ACCEPTS_EXPR_PACK\n\n"; } +static void emitFormInitializer(raw_ostream &OS, + const FlattenedSpelling &Spelling, + StringRef SpellingIndex) { + OS << "{AttributeCommonInfo::AS_" << Spelling.variety() << ", " + << SpellingIndex << "}"; +} + static void emitAttributes(RecordKeeper &Records, raw_ostream &OS, bool Header) { std::vector Attrs = Records.getAllDerivedDefinitions("Attr"); @@ -2595,14 +2602,9 @@ static void emitAttributes(RecordKeeper &Records, raw_ostream &OS, if (Header) OS << " = {}"; if (Spellings.size() > 1) { - OS << ", AttributeCommonInfo::Syntax Syntax"; + OS << ", Spelling S"; if (Header) - OS << " = AttributeCommonInfo::AS_" << Spellings[0].variety(); - } - if (!ElideSpelling) { - OS << ", " << R.getName() << "Attr::Spelling S"; - if (Header) - OS << " = static_cast(SpellingNotCalculated)"; + OS << " = " << SemanticToSyntacticMap[0]; } OS << ")"; if (Header) { @@ -2618,15 +2620,31 @@ static void emitAttributes(RecordKeeper &Records, raw_ostream &OS, else OS << "NoSemaHandlerAttribute"; - if (Spellings.size() == 0) + if (Spellings.size() == 0) { OS << ", AttributeCommonInfo::AS_Implicit"; - else if (Spellings.size() == 1) - OS << ", AttributeCommonInfo::AS_" << Spellings[0].variety(); - else - OS << ", Syntax"; + } else if (Spellings.size() == 1) { + OS << ", "; + emitFormInitializer(OS, Spellings[0], "0"); + } else { + OS << ", (\n"; + std::set Uniques; + unsigned Idx = 0; + for (auto I = Spellings.begin(), E = Spellings.end(); I != E; + ++I, ++Idx) { + const FlattenedSpelling &S = *I; + const auto &Name = SemanticToSyntacticMap[Idx]; + if (Uniques.insert(Name).second) { + OS << " S == " << Name << " ? AttributeCommonInfo::Form"; + emitFormInitializer(OS, S, Name); + OS << " :\n"; + } + } + OS << " (llvm_unreachable(\"Unknown attribute spelling!\"), " + << " AttributeCommonInfo::Form"; + emitFormInitializer(OS, Spellings[0], "0"); + OS << "))"; + } - if (!ElideSpelling) - OS << ", S"; OS << ");\n"; OS << " return Create"; if (Implicit) -- 2.7.4