Index: cfe/trunk/include/clang/AST/Attr.h =================================================================== --- cfe/trunk/include/clang/AST/Attr.h +++ cfe/trunk/include/clang/AST/Attr.h @@ -19,6 +19,7 @@ #include "clang/AST/Expr.h" #include "clang/AST/Type.h" #include "clang/Basic/AttrKinds.h" +#include "clang/Basic/AttributeCommonInfo.h" #include "clang/Basic/LLVM.h" #include "clang/Basic/OpenMPKinds.h" #include "clang/Basic/Sanitizers.h" @@ -32,6 +33,7 @@ namespace clang { class ASTContext; + class AttributeCommonInfo; class IdentifierInfo; class ObjCInterfaceDecl; class Expr; @@ -40,84 +42,79 @@ class TypeSourceInfo; /// Attr - This represents one attribute. -class Attr { -private: - SourceRange Range; - unsigned AttrKind : 16; + class Attr : public AttributeCommonInfo { + private: + unsigned AttrKind : 16; + + protected: + /// An index into the spelling list of an + /// attribute defined in Attr.td file. + unsigned Inherited : 1; + unsigned IsPackExpansion : 1; + unsigned Implicit : 1; + // FIXME: These are properties of the attribute kind, not state for this + // instance of the attribute. + unsigned IsLateParsed : 1; + unsigned InheritEvenIfAlreadyPresent : 1; -protected: - /// An index into the spelling list of an - /// attribute defined in Attr.td file. - unsigned SpellingListIndex : 4; - unsigned Inherited : 1; - unsigned IsPackExpansion : 1; - unsigned Implicit : 1; - // FIXME: These are properties of the attribute kind, not state for this - // instance of the attribute. - unsigned IsLateParsed : 1; - unsigned InheritEvenIfAlreadyPresent : 1; - - void *operator new(size_t bytes) noexcept { - llvm_unreachable("Attrs cannot be allocated with regular 'new'."); - } - void operator delete(void *data) noexcept { - llvm_unreachable("Attrs cannot be released with regular 'delete'."); - } - -public: - // Forward so that the regular new and delete do not hide global ones. - void *operator new(size_t Bytes, ASTContext &C, - size_t Alignment = 8) noexcept { - return ::operator new(Bytes, C, Alignment); - } - void operator delete(void *Ptr, ASTContext &C, size_t Alignment) noexcept { - return ::operator delete(Ptr, C, Alignment); - } + void *operator new(size_t bytes) noexcept { + llvm_unreachable("Attrs cannot be allocated with regular 'new'."); + } + void operator delete(void *data) noexcept { + llvm_unreachable("Attrs cannot be released with regular 'delete'."); + } -protected: - Attr(attr::Kind AK, SourceRange R, unsigned SpellingListIndex, - bool IsLateParsed) - : Range(R), AttrKind(AK), SpellingListIndex(SpellingListIndex), - Inherited(false), IsPackExpansion(false), Implicit(false), - IsLateParsed(IsLateParsed), InheritEvenIfAlreadyPresent(false) {} + public: + // Forward so that the regular new and delete do not hide global ones. + void *operator new(size_t Bytes, ASTContext &C, + size_t Alignment = 8) noexcept { + return ::operator new(Bytes, C, Alignment); + } + void operator delete(void *Ptr, ASTContext &C, size_t Alignment) noexcept { + return ::operator delete(Ptr, C, Alignment); + } -public: + protected: + Attr(ASTContext &Context, const AttributeCommonInfo &CommonInfo, + attr::Kind AK, bool IsLateParsed) + : AttributeCommonInfo(CommonInfo), AttrKind(AK), Inherited(false), + IsPackExpansion(false), Implicit(false), IsLateParsed(IsLateParsed), + InheritEvenIfAlreadyPresent(false) {} - attr::Kind getKind() const { - return static_cast(AttrKind); - } + public: + attr::Kind getKind() const { return static_cast(AttrKind); } - unsigned getSpellingListIndex() const { return SpellingListIndex; } - const char *getSpelling() const; + unsigned getSpellingListIndex() const { + return getAttributeSpellingListIndex(); + } + const char *getSpelling() const; - SourceLocation getLocation() const { return Range.getBegin(); } - SourceRange getRange() const { return Range; } - void setRange(SourceRange R) { Range = R; } + SourceLocation getLocation() const { return getRange().getBegin(); } - bool isInherited() const { return Inherited; } + bool isInherited() const { return Inherited; } - /// Returns true if the attribute has been implicitly created instead - /// of explicitly written by the user. - bool isImplicit() const { return Implicit; } - void setImplicit(bool I) { Implicit = I; } + /// Returns true if the attribute has been implicitly created instead + /// of explicitly written by the user. + bool isImplicit() const { return Implicit; } + void setImplicit(bool I) { Implicit = I; } - void setPackExpansion(bool PE) { IsPackExpansion = PE; } - bool isPackExpansion() const { return IsPackExpansion; } + void setPackExpansion(bool PE) { IsPackExpansion = PE; } + bool isPackExpansion() const { return IsPackExpansion; } - // Clone this attribute. - Attr *clone(ASTContext &C) const; + // Clone this attribute. + Attr *clone(ASTContext &C) const; - bool isLateParsed() const { return IsLateParsed; } + bool isLateParsed() const { return IsLateParsed; } - // Pretty print this attribute. - void printPretty(raw_ostream &OS, const PrintingPolicy &Policy) const; -}; + // Pretty print this attribute. + void printPretty(raw_ostream &OS, const PrintingPolicy &Policy) const; + }; class TypeAttr : public Attr { protected: - TypeAttr(attr::Kind AK, SourceRange R, unsigned SpellingListIndex, - bool IsLateParsed) - : Attr(AK, R, SpellingListIndex, IsLateParsed) {} + TypeAttr(ASTContext &Context, const AttributeCommonInfo &CommonInfo, + attr::Kind AK, bool IsLateParsed) + : Attr(Context, CommonInfo, AK, IsLateParsed) {} public: static bool classof(const Attr *A) { @@ -128,9 +125,9 @@ class StmtAttr : public Attr { protected: - StmtAttr(attr::Kind AK, SourceRange R, unsigned SpellingListIndex, - bool IsLateParsed) - : Attr(AK, R, SpellingListIndex, IsLateParsed) {} + StmtAttr(ASTContext &Context, const AttributeCommonInfo &CommonInfo, + attr::Kind AK, bool IsLateParsed) + : Attr(Context, CommonInfo, AK, IsLateParsed) {} public: static bool classof(const Attr *A) { @@ -141,9 +138,10 @@ class InheritableAttr : public Attr { protected: - InheritableAttr(attr::Kind AK, SourceRange R, unsigned SpellingListIndex, - bool IsLateParsed, bool InheritEvenIfAlreadyPresent) - : Attr(AK, R, SpellingListIndex, IsLateParsed) { + InheritableAttr(ASTContext &Context, const AttributeCommonInfo &CommonInfo, + attr::Kind AK, bool IsLateParsed, + bool InheritEvenIfAlreadyPresent) + : Attr(Context, CommonInfo, AK, IsLateParsed) { this->InheritEvenIfAlreadyPresent = InheritEvenIfAlreadyPresent; } @@ -165,9 +163,10 @@ class InheritableParamAttr : public InheritableAttr { protected: - InheritableParamAttr(attr::Kind AK, SourceRange R, unsigned SpellingListIndex, + InheritableParamAttr(ASTContext &Context, + const AttributeCommonInfo &CommonInfo, attr::Kind AK, bool IsLateParsed, bool InheritEvenIfAlreadyPresent) - : InheritableAttr(AK, R, SpellingListIndex, IsLateParsed, + : InheritableAttr(Context, CommonInfo, AK, IsLateParsed, InheritEvenIfAlreadyPresent) {} public: @@ -182,11 +181,11 @@ /// for the parameter. class ParameterABIAttr : public InheritableParamAttr { protected: - ParameterABIAttr(attr::Kind AK, SourceRange R, - unsigned SpellingListIndex, bool IsLateParsed, + ParameterABIAttr(ASTContext &Context, const AttributeCommonInfo &CommonInfo, + attr::Kind AK, bool IsLateParsed, bool InheritEvenIfAlreadyPresent) - : InheritableParamAttr(AK, R, SpellingListIndex, IsLateParsed, - InheritEvenIfAlreadyPresent) {} + : InheritableParamAttr(Context, CommonInfo, AK, IsLateParsed, + InheritEvenIfAlreadyPresent) {} public: ParameterABI getABI() const { Index: cfe/trunk/include/clang/Basic/Attr.td =================================================================== --- cfe/trunk/include/clang/Basic/Attr.td +++ cfe/trunk/include/clang/Basic/Attr.td @@ -3042,7 +3042,7 @@ } void printPrettyPragma(raw_ostream &OS, const PrintingPolicy &Policy) const { - unsigned SpellingIndex = getSpellingListIndex(); + unsigned SpellingIndex = getAttributeSpellingListIndex(); // For "#pragma unroll" and "#pragma nounroll" the string "unroll" or // "nounroll" is already emitted as the pragma name. if (SpellingIndex == Pragma_nounroll || SpellingIndex == Pragma_nounroll_and_jam) @@ -3078,7 +3078,7 @@ // Return a string suitable for identifying this attribute in diagnostics. std::string getDiagnosticName(const PrintingPolicy &Policy) const { - unsigned SpellingIndex = getSpellingListIndex(); + unsigned SpellingIndex = getAttributeSpellingListIndex(); if (SpellingIndex == Pragma_nounroll) return "#pragma nounroll"; else if (SpellingIndex == Pragma_unroll) Index: cfe/trunk/include/clang/Basic/AttributeCommonInfo.h =================================================================== --- cfe/trunk/include/clang/Basic/AttributeCommonInfo.h +++ cfe/trunk/include/clang/Basic/AttributeCommonInfo.h @@ -0,0 +1,190 @@ +//======- AttributeCommonInfo.h - Base info about Attributes-----*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file defines the AttributeCommonInfo type, which is the base for a +// ParsedAttr and is used by Attr as a way to share info between the two. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_BASIC_ATTRIBUTECOMMONINFO_H +#define LLVM_CLANG_BASIC_ATTRIBUTECOMMONINFO_H +#include "clang/Basic/SourceLocation.h" + +namespace clang { +class IdentifierInfo; +class ASTRecordWriter; + +class AttributeCommonInfo { +public: + /// The style used to specify an attribute. + enum Syntax { + /// __attribute__((...)) + AS_GNU, + + /// [[...]] + AS_CXX11, + + /// [[...]] + AS_C2x, + + /// __declspec(...) + AS_Declspec, + + /// [uuid("...")] class Foo + AS_Microsoft, + + /// __ptr16, alignas(...), etc. + AS_Keyword, + + /// #pragma ... + AS_Pragma, + + // Note TableGen depends on the order above. Do not add or change the order + // without adding related code to TableGen/ClangAttrEmitter.cpp. + /// Context-sensitive version of a keyword attribute. + AS_ContextSensitiveKeyword, + }; + enum Kind { +#define PARSED_ATTR(NAME) AT_##NAME, +#include "clang/Sema/AttrParsedAttrList.inc" +#undef PARSED_ATTR + NoSemaHandlerAttribute, + IgnoredAttribute, + UnknownAttribute, + }; + +private: + const IdentifierInfo *AttrName = nullptr; + const IdentifierInfo *ScopeName = nullptr; + SourceRange AttrRange; + const SourceLocation ScopeLoc; + // Corresponds to the Kind enum. + unsigned AttrKind : 16; + /// Corresponds to the Syntax enum. + unsigned SyntaxUsed : 3; + unsigned SpellingIndex : 4; + +protected: + static constexpr unsigned SpellingNotCalculated = 0xf; + +public: + AttributeCommonInfo(SourceRange AttrRange) + : AttrRange(AttrRange), AttrKind(0), SyntaxUsed(0), + SpellingIndex(SpellingNotCalculated) {} + + AttributeCommonInfo(SourceLocation AttrLoc) + : AttrRange(AttrLoc), AttrKind(0), SyntaxUsed(0), + SpellingIndex(SpellingNotCalculated) {} + + 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) {} + + AttributeCommonInfo(const IdentifierInfo *AttrName, + const IdentifierInfo *ScopeName, SourceRange AttrRange, + SourceLocation ScopeLoc, Kind AttrKind, Syntax SyntaxUsed) + : AttrName(AttrName), ScopeName(ScopeName), AttrRange(AttrRange), + ScopeLoc(ScopeLoc), AttrKind(AttrKind), SyntaxUsed(SyntaxUsed), + SpellingIndex(SpellingNotCalculated) {} + + AttributeCommonInfo(const IdentifierInfo *AttrName, + const IdentifierInfo *ScopeName, SourceRange AttrRange, + SourceLocation ScopeLoc, Kind AttrKind, Syntax SyntaxUsed, + unsigned Spelling) + : AttrName(AttrName), ScopeName(ScopeName), AttrRange(AttrRange), + ScopeLoc(ScopeLoc), AttrKind(AttrKind), SyntaxUsed(SyntaxUsed), + SpellingIndex(Spelling) {} + + AttributeCommonInfo(const IdentifierInfo *AttrName, SourceRange AttrRange, + Syntax SyntaxUsed) + : 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) {} + + AttributeCommonInfo(SourceRange AttrRange, Kind K, Syntax SyntaxUsed, + unsigned Spelling) + : AttrName(nullptr), ScopeName(nullptr), AttrRange(AttrRange), ScopeLoc(), + AttrKind(K), SyntaxUsed(SyntaxUsed), SpellingIndex(Spelling) {} + + AttributeCommonInfo(AttributeCommonInfo &&) = default; + AttributeCommonInfo(const AttributeCommonInfo &) = default; + + Kind getParsedKind() const { return Kind(AttrKind); } + Syntax getSyntax() const { return Syntax(SyntaxUsed); } + const IdentifierInfo *getAttrName() const { return AttrName; } + SourceLocation getLoc() const { return AttrRange.getBegin(); } + SourceRange getRange() const { return AttrRange; } + void setRange(SourceRange R) { AttrRange = R; } + + bool hasScope() const { return ScopeName; } + const IdentifierInfo *getScopeName() const { return ScopeName; } + SourceLocation getScopeLoc() const { return ScopeLoc; } + + bool isDeclspecAttribute() const { return SyntaxUsed == AS_Declspec; } + bool isMicrosoftAttribute() const { return SyntaxUsed == AS_Microsoft; } + + bool isGNUScope() const; + + bool isAlignasAttribute() const { + // FIXME: Use a better mechanism to determine this. + return getParsedKind() == AT_Aligned && isKeywordAttribute(); + } + + bool isCXX11Attribute() const { + return SyntaxUsed == AS_CXX11 || isAlignasAttribute(); + } + + bool isC2xAttribute() const { return SyntaxUsed == AS_C2x; } + + bool isKeywordAttribute() const { + return SyntaxUsed == AS_Keyword || SyntaxUsed == AS_ContextSensitiveKeyword; + } + + bool isContextSensitiveKeywordAttribute() const { + return SyntaxUsed == AS_ContextSensitiveKeyword; + } + + unsigned getAttributeSpellingListIndex() const { + assert((isAttributeSpellingListCalculated() || AttrName) && + "Spelling cannot be found"); + return isAttributeSpellingListCalculated() + ? SpellingIndex + : calculateAttributeSpellingListIndex(); + } + void setAttributeSpellingListIndex(unsigned V) { SpellingIndex = V; } + + static Kind getParsedKind(const IdentifierInfo *Name, + const IdentifierInfo *Scope, Syntax SyntaxUsed); + +private: + /// Get an index into the attribute spelling list + /// defined in Attr.td. This index is used by an attribute + /// to pretty print itself. + unsigned calculateAttributeSpellingListIndex() const; + + friend class clang::ASTRecordWriter; + // Used exclusively by ASTDeclWriter to get the raw spelling list state. + unsigned getAttributeSpellingListIndexRaw() const { return SpellingIndex; } + +protected: + bool isAttributeSpellingListCalculated() const { + return SpellingIndex != SpellingNotCalculated; + } +}; +} // namespace clang + +#endif // LLVM_CLANG_BASIC_ATTRIBUTECOMMONINFO_H Index: cfe/trunk/include/clang/Lex/Preprocessor.h =================================================================== --- cfe/trunk/include/clang/Lex/Preprocessor.h +++ cfe/trunk/include/clang/Lex/Preprocessor.h @@ -371,9 +371,9 @@ /// it expects a '.' or ';'. bool ModuleImportExpectsIdentifier = false; - /// The source location of the currently-active + /// The identifier and source location of the currently-active /// \#pragma clang arc_cf_code_audited begin. - SourceLocation PragmaARCCFCodeAuditedLoc; + std::pair PragmaARCCFCodeAuditedInfo; /// The source location of the currently-active /// \#pragma clang assume_nonnull begin. @@ -1602,14 +1602,16 @@ /// arc_cf_code_audited begin. /// /// Returns an invalid location if there is no such pragma active. - SourceLocation getPragmaARCCFCodeAuditedLoc() const { - return PragmaARCCFCodeAuditedLoc; + std::pair + getPragmaARCCFCodeAuditedInfo() const { + return PragmaARCCFCodeAuditedInfo; } /// Set the location of the currently-active \#pragma clang /// arc_cf_code_audited begin. An invalid location ends the pragma. - void setPragmaARCCFCodeAuditedLoc(SourceLocation Loc) { - PragmaARCCFCodeAuditedLoc = Loc; + void setPragmaARCCFCodeAuditedInfo(IdentifierInfo *Ident, + SourceLocation Loc) { + PragmaARCCFCodeAuditedInfo = {Ident, Loc}; } /// The location of the currently-active \#pragma clang Index: cfe/trunk/include/clang/Sema/ParsedAttr.h =================================================================== --- cfe/trunk/include/clang/Sema/ParsedAttr.h +++ cfe/trunk/include/clang/Sema/ParsedAttr.h @@ -15,6 +15,7 @@ #define LLVM_CLANG_SEMA_ATTRIBUTELIST_H #include "clang/Basic/AttrSubjectMatchRules.h" +#include "clang/Basic/AttributeCommonInfo.h" #include "clang/Basic/Diagnostic.h" #include "clang/Basic/SourceLocation.h" #include "clang/Basic/TargetInfo.h" @@ -114,7 +115,8 @@ /// 4: __attribute__(( aligned(16) )). ParmName is unused, Args/Num used. /// class ParsedAttr final - : private llvm::TrailingObjects< + : public AttributeCommonInfo, + private llvm::TrailingObjects< ParsedAttr, ArgsUnion, detail::AvailabilityData, detail::TypeTagForDatatypeData, ParsedType, detail::PropertyData> { friend TrailingObjects; @@ -134,54 +136,15 @@ return IsProperty; } -public: - /// The style used to specify an attribute. - enum Syntax { - /// __attribute__((...)) - AS_GNU, - - /// [[...]] - AS_CXX11, - - /// [[...]] - AS_C2x, - - /// __declspec(...) - AS_Declspec, - - /// [uuid("...")] class Foo - AS_Microsoft, - - /// __ptr16, alignas(...), etc. - AS_Keyword, - - /// #pragma ... - AS_Pragma, - - // Note TableGen depends on the order above. Do not add or change the order - // without adding related code to TableGen/ClangAttrEmitter.cpp. - /// Context-sensitive version of a keyword attribute. - AS_ContextSensitiveKeyword, - }; - private: - IdentifierInfo *AttrName; - IdentifierInfo *ScopeName; IdentifierInfo *MacroII = nullptr; SourceLocation MacroExpansionLoc; - SourceRange AttrRange; - SourceLocation ScopeLoc; SourceLocation EllipsisLoc; - unsigned AttrKind : 16; - /// The number of expression arguments this attribute has. /// The expressions themselves are stored after the object. unsigned NumArgs : 16; - /// Corresponds to the Syntax enum. - unsigned SyntaxUsed : 3; - /// True if already diagnosed as invalid. mutable unsigned Invalid : 1; @@ -239,14 +202,14 @@ IdentifierInfo *scopeName, SourceLocation scopeLoc, ArgsUnion *args, unsigned numArgs, Syntax syntaxUsed, SourceLocation ellipsisLoc) - : AttrName(attrName), ScopeName(scopeName), AttrRange(attrRange), - ScopeLoc(scopeLoc), EllipsisLoc(ellipsisLoc), NumArgs(numArgs), - SyntaxUsed(syntaxUsed), Invalid(false), UsedAsTypeAttr(false), - IsAvailability(false), IsTypeTagForDatatype(false), IsProperty(false), - HasParsedType(false), HasProcessingCache(false), - IsPragmaClangAttribute(false) { - if (numArgs) memcpy(getArgsBuffer(), args, numArgs * sizeof(ArgsUnion)); - AttrKind = getKind(getName(), getScopeName(), syntaxUsed); + : AttributeCommonInfo(attrName, scopeName, attrRange, scopeLoc, + syntaxUsed), + EllipsisLoc(ellipsisLoc), NumArgs(numArgs), Invalid(false), + UsedAsTypeAttr(false), IsAvailability(false), + IsTypeTagForDatatype(false), IsProperty(false), HasParsedType(false), + HasProcessingCache(false), IsPragmaClangAttribute(false) { + if (numArgs) + memcpy(getArgsBuffer(), args, numArgs * sizeof(ArgsUnion)); } /// Constructor for availability attributes. @@ -257,9 +220,9 @@ const AvailabilityChange &obsoleted, SourceLocation unavailable, const Expr *messageExpr, Syntax syntaxUsed, SourceLocation strict, const Expr *replacementExpr) - : AttrName(attrName), ScopeName(scopeName), AttrRange(attrRange), - ScopeLoc(scopeLoc), NumArgs(1), SyntaxUsed(syntaxUsed), Invalid(false), - UsedAsTypeAttr(false), IsAvailability(true), + : AttributeCommonInfo(attrName, scopeName, attrRange, scopeLoc, + syntaxUsed), + NumArgs(1), Invalid(false), UsedAsTypeAttr(false), IsAvailability(true), IsTypeTagForDatatype(false), IsProperty(false), HasParsedType(false), HasProcessingCache(false), IsPragmaClangAttribute(false), UnavailableLoc(unavailable), MessageExpr(messageExpr) { @@ -267,7 +230,6 @@ memcpy(getArgsBuffer(), &PVal, sizeof(ArgsUnion)); new (getAvailabilityData()) detail::AvailabilityData( introduced, deprecated, obsoleted, strict, replacementExpr); - AttrKind = getKind(getName(), getScopeName(), syntaxUsed); } /// Constructor for objc_bridge_related attributes. @@ -275,16 +237,16 @@ IdentifierInfo *scopeName, SourceLocation scopeLoc, IdentifierLoc *Parm1, IdentifierLoc *Parm2, IdentifierLoc *Parm3, Syntax syntaxUsed) - : AttrName(attrName), ScopeName(scopeName), AttrRange(attrRange), - ScopeLoc(scopeLoc), NumArgs(3), SyntaxUsed(syntaxUsed), Invalid(false), - UsedAsTypeAttr(false), IsAvailability(false), - IsTypeTagForDatatype(false), IsProperty(false), HasParsedType(false), - HasProcessingCache(false), IsPragmaClangAttribute(false) { + : AttributeCommonInfo(attrName, scopeName, attrRange, scopeLoc, + syntaxUsed), + NumArgs(3), Invalid(false), UsedAsTypeAttr(false), + IsAvailability(false), IsTypeTagForDatatype(false), IsProperty(false), + HasParsedType(false), HasProcessingCache(false), + IsPragmaClangAttribute(false) { ArgsUnion *Args = getArgsBuffer(); Args[0] = Parm1; Args[1] = Parm2; Args[2] = Parm3; - AttrKind = getKind(getName(), getScopeName(), syntaxUsed); } /// Constructor for type_tag_for_datatype attribute. @@ -292,31 +254,31 @@ IdentifierInfo *scopeName, SourceLocation scopeLoc, IdentifierLoc *ArgKind, ParsedType matchingCType, bool layoutCompatible, bool mustBeNull, Syntax syntaxUsed) - : AttrName(attrName), ScopeName(scopeName), AttrRange(attrRange), - ScopeLoc(scopeLoc), NumArgs(1), SyntaxUsed(syntaxUsed), Invalid(false), - UsedAsTypeAttr(false), IsAvailability(false), - IsTypeTagForDatatype(true), IsProperty(false), HasParsedType(false), - HasProcessingCache(false), IsPragmaClangAttribute(false) { + : AttributeCommonInfo(attrName, scopeName, attrRange, scopeLoc, + syntaxUsed), + NumArgs(1), Invalid(false), UsedAsTypeAttr(false), + IsAvailability(false), IsTypeTagForDatatype(true), IsProperty(false), + HasParsedType(false), HasProcessingCache(false), + IsPragmaClangAttribute(false) { ArgsUnion PVal(ArgKind); memcpy(getArgsBuffer(), &PVal, sizeof(ArgsUnion)); detail::TypeTagForDatatypeData &ExtraData = getTypeTagForDatatypeDataSlot(); new (&ExtraData.MatchingCType) ParsedType(matchingCType); ExtraData.LayoutCompatible = layoutCompatible; ExtraData.MustBeNull = mustBeNull; - AttrKind = getKind(getName(), getScopeName(), syntaxUsed); } /// Constructor for attributes with a single type argument. ParsedAttr(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, ParsedType typeArg, Syntax syntaxUsed) - : AttrName(attrName), ScopeName(scopeName), AttrRange(attrRange), - ScopeLoc(scopeLoc), NumArgs(0), SyntaxUsed(syntaxUsed), Invalid(false), - UsedAsTypeAttr(false), IsAvailability(false), - IsTypeTagForDatatype(false), IsProperty(false), HasParsedType(true), - HasProcessingCache(false), IsPragmaClangAttribute(false) { + : AttributeCommonInfo(attrName, scopeName, attrRange, scopeLoc, + syntaxUsed), + NumArgs(0), Invalid(false), UsedAsTypeAttr(false), + IsAvailability(false), IsTypeTagForDatatype(false), IsProperty(false), + HasParsedType(true), HasProcessingCache(false), + IsPragmaClangAttribute(false) { new (&getTypeBuffer()) ParsedType(typeArg); - AttrKind = getKind(getName(), getScopeName(), syntaxUsed); } /// Constructor for microsoft __declspec(property) attribute. @@ -324,13 +286,13 @@ IdentifierInfo *scopeName, SourceLocation scopeLoc, IdentifierInfo *getterId, IdentifierInfo *setterId, Syntax syntaxUsed) - : AttrName(attrName), ScopeName(scopeName), AttrRange(attrRange), - ScopeLoc(scopeLoc), NumArgs(0), SyntaxUsed(syntaxUsed), Invalid(false), - UsedAsTypeAttr(false), IsAvailability(false), - IsTypeTagForDatatype(false), IsProperty(true), HasParsedType(false), - HasProcessingCache(false), IsPragmaClangAttribute(false) { + : AttributeCommonInfo(attrName, scopeName, attrRange, scopeLoc, + syntaxUsed), + NumArgs(0), Invalid(false), UsedAsTypeAttr(false), + IsAvailability(false), IsTypeTagForDatatype(false), IsProperty(true), + HasParsedType(false), HasProcessingCache(false), + IsPragmaClangAttribute(false) { new (&getPropertyDataBuffer()) detail::PropertyData(getterId, setterId); - AttrKind = getKind(getName(), getScopeName(), syntaxUsed); } /// Type tag information is stored immediately following the arguments, if @@ -372,27 +334,6 @@ void operator delete(void *) = delete; - enum Kind { - #define PARSED_ATTR(NAME) AT_##NAME, - #include "clang/Sema/AttrParsedAttrList.inc" - #undef PARSED_ATTR - IgnoredAttribute, - UnknownAttribute - }; - - IdentifierInfo *getName() const { return AttrName; } - SourceLocation getLoc() const { return AttrRange.getBegin(); } - SourceRange getRange() const { return AttrRange; } - - bool hasScope() const { return ScopeName; } - IdentifierInfo *getScopeName() const { return ScopeName; } - SourceLocation getScopeLoc() const { return ScopeLoc; } - - bool isGNUScope() const { - return ScopeName && - (ScopeName->isStr("gnu") || ScopeName->isStr("__gnu__")); - } - bool hasParsedType() const { return HasParsedType; } /// Is this the Microsoft __declspec(property) attribute? @@ -400,30 +341,6 @@ return IsProperty; } - bool isAlignasAttribute() const { - // FIXME: Use a better mechanism to determine this. - return getKind() == AT_Aligned && isKeywordAttribute(); - } - - bool isDeclspecAttribute() const { return SyntaxUsed == AS_Declspec; } - bool isMicrosoftAttribute() const { return SyntaxUsed == AS_Microsoft; } - - bool isCXX11Attribute() const { - return SyntaxUsed == AS_CXX11 || isAlignasAttribute(); - } - - bool isC2xAttribute() const { - return SyntaxUsed == AS_C2x; - } - - bool isKeywordAttribute() const { - return SyntaxUsed == AS_Keyword || SyntaxUsed == AS_ContextSensitiveKeyword; - } - - bool isContextSensitiveKeywordAttribute() const { - return SyntaxUsed == AS_ContextSensitiveKeyword; - } - bool isInvalid() const { return Invalid; } void setInvalid(bool b = true) const { Invalid = b; } @@ -450,10 +367,6 @@ bool isPackExpansion() const { return EllipsisLoc.isValid(); } SourceLocation getEllipsisLoc() const { return EllipsisLoc; } - Kind getKind() const { return Kind(AttrKind); } - static Kind getKind(const IdentifierInfo *Name, const IdentifierInfo *Scope, - Syntax SyntaxUsed); - /// getNumArgs - Return the number of actual arguments to this attribute. unsigned getNumArgs() const { return NumArgs; } @@ -480,54 +393,61 @@ } const AvailabilityChange &getAvailabilityIntroduced() const { - assert(getKind() == AT_Availability && "Not an availability attribute"); + assert(getParsedKind() == AT_Availability && + "Not an availability attribute"); return getAvailabilityData()->Changes[detail::IntroducedSlot]; } const AvailabilityChange &getAvailabilityDeprecated() const { - assert(getKind() == AT_Availability && "Not an availability attribute"); + assert(getParsedKind() == AT_Availability && + "Not an availability attribute"); return getAvailabilityData()->Changes[detail::DeprecatedSlot]; } const AvailabilityChange &getAvailabilityObsoleted() const { - assert(getKind() == AT_Availability && "Not an availability attribute"); + assert(getParsedKind() == AT_Availability && + "Not an availability attribute"); return getAvailabilityData()->Changes[detail::ObsoletedSlot]; } SourceLocation getStrictLoc() const { - assert(getKind() == AT_Availability && "Not an availability attribute"); + assert(getParsedKind() == AT_Availability && + "Not an availability attribute"); return getAvailabilityData()->StrictLoc; } SourceLocation getUnavailableLoc() const { - assert(getKind() == AT_Availability && "Not an availability attribute"); + assert(getParsedKind() == AT_Availability && + "Not an availability attribute"); return UnavailableLoc; } const Expr * getMessageExpr() const { - assert(getKind() == AT_Availability && "Not an availability attribute"); + assert(getParsedKind() == AT_Availability && + "Not an availability attribute"); return MessageExpr; } const Expr *getReplacementExpr() const { - assert(getKind() == AT_Availability && "Not an availability attribute"); + assert(getParsedKind() == AT_Availability && + "Not an availability attribute"); return getAvailabilityData()->Replacement; } const ParsedType &getMatchingCType() const { - assert(getKind() == AT_TypeTagForDatatype && + assert(getParsedKind() == AT_TypeTagForDatatype && "Not a type_tag_for_datatype attribute"); return getTypeTagForDatatypeDataSlot().MatchingCType; } bool getLayoutCompatible() const { - assert(getKind() == AT_TypeTagForDatatype && + assert(getParsedKind() == AT_TypeTagForDatatype && "Not a type_tag_for_datatype attribute"); return getTypeTagForDatatypeDataSlot().LayoutCompatible; } bool getMustBeNull() const { - assert(getKind() == AT_TypeTagForDatatype && + assert(getParsedKind() == AT_TypeTagForDatatype && "Not a type_tag_for_datatype attribute"); return getTypeTagForDatatypeDataSlot().MustBeNull; } @@ -570,11 +490,6 @@ return MacroExpansionLoc; } - /// Get an index into the attribute spelling list - /// defined in Attr.td. This index is used by an attribute - /// to pretty print itself. - unsigned getAttributeSpellingListIndex() const; - bool isTargetSpecificAttr() const; bool isTypeAttr() const; bool isStmtAttr() const; @@ -603,7 +518,7 @@ /// If this is an OpenCL addr space attribute returns its representation /// in LangAS, otherwise returns default addr space. LangAS asOpenCLLangAS() const { - switch (getKind()) { + switch (getParsedKind()) { case ParsedAttr::AT_OpenCLConstantAddressSpace: return LangAS::opencl_constant; case ParsedAttr::AT_OpenCLGlobalAddressSpace: @@ -618,6 +533,8 @@ return LangAS::Default; } } + + AttributeCommonInfo::Kind getKind() const { return getParsedKind(); } }; class AttributePool; @@ -889,8 +806,9 @@ } bool hasAttribute(ParsedAttr::Kind K) const { - return llvm::any_of( - AttrList, [K](const ParsedAttr *AL) { return AL->getKind() == K; }); + return llvm::any_of(AttrList, [K](const ParsedAttr *AL) { + return AL->getParsedKind() == K; + }); } private: @@ -1038,28 +956,28 @@ inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, const ParsedAttr &At) { - DB.AddTaggedVal(reinterpret_cast(At.getName()), + DB.AddTaggedVal(reinterpret_cast(At.getAttrName()), DiagnosticsEngine::ak_identifierinfo); return DB; } inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD, const ParsedAttr &At) { - PD.AddTaggedVal(reinterpret_cast(At.getName()), + PD.AddTaggedVal(reinterpret_cast(At.getAttrName()), DiagnosticsEngine::ak_identifierinfo); return PD; } inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, const ParsedAttr *At) { - DB.AddTaggedVal(reinterpret_cast(At->getName()), + DB.AddTaggedVal(reinterpret_cast(At->getAttrName()), DiagnosticsEngine::ak_identifierinfo); return DB; } inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD, const ParsedAttr *At) { - PD.AddTaggedVal(reinterpret_cast(At->getName()), + PD.AddTaggedVal(reinterpret_cast(At->getAttrName()), DiagnosticsEngine::ak_identifierinfo); return PD; } Index: cfe/trunk/include/clang/Sema/Sema.h =================================================================== --- cfe/trunk/include/clang/Sema/Sema.h +++ cfe/trunk/include/clang/Sema/Sema.h @@ -2665,48 +2665,44 @@ }; /// Attribute merging methods. Return true if a new attribute was added. - AvailabilityAttr *mergeAvailabilityAttr( - NamedDecl *D, SourceRange Range, IdentifierInfo *Platform, bool Implicit, - VersionTuple Introduced, VersionTuple Deprecated, VersionTuple Obsoleted, - bool IsUnavailable, StringRef Message, bool IsStrict, - StringRef Replacement, AvailabilityMergeKind AMK, int Priority, - unsigned AttrSpellingListIndex); - TypeVisibilityAttr *mergeTypeVisibilityAttr(Decl *D, SourceRange Range, - TypeVisibilityAttr::VisibilityType Vis, - unsigned AttrSpellingListIndex); - VisibilityAttr *mergeVisibilityAttr(Decl *D, SourceRange Range, - VisibilityAttr::VisibilityType Vis, - unsigned AttrSpellingListIndex); - UuidAttr *mergeUuidAttr(Decl *D, SourceRange Range, - unsigned AttrSpellingListIndex, StringRef Uuid); - DLLImportAttr *mergeDLLImportAttr(Decl *D, SourceRange Range, - unsigned AttrSpellingListIndex); - DLLExportAttr *mergeDLLExportAttr(Decl *D, SourceRange Range, - unsigned AttrSpellingListIndex); + AvailabilityAttr * + mergeAvailabilityAttr(NamedDecl *D, const AttributeCommonInfo &CI, + IdentifierInfo *Platform, bool Implicit, + VersionTuple Introduced, VersionTuple Deprecated, + VersionTuple Obsoleted, bool IsUnavailable, + StringRef Message, bool IsStrict, StringRef Replacement, + AvailabilityMergeKind AMK, int Priority); + TypeVisibilityAttr * + mergeTypeVisibilityAttr(Decl *D, const AttributeCommonInfo &CI, + TypeVisibilityAttr::VisibilityType Vis); + VisibilityAttr *mergeVisibilityAttr(Decl *D, const AttributeCommonInfo &CI, + VisibilityAttr::VisibilityType Vis); + UuidAttr *mergeUuidAttr(Decl *D, const AttributeCommonInfo &CI, + StringRef Uuid); + DLLImportAttr *mergeDLLImportAttr(Decl *D, const AttributeCommonInfo &CI); + DLLExportAttr *mergeDLLExportAttr(Decl *D, const AttributeCommonInfo &CI); MSInheritanceAttr * - mergeMSInheritanceAttr(Decl *D, SourceRange Range, bool BestCase, - unsigned AttrSpellingListIndex, + mergeMSInheritanceAttr(Decl *D, const AttributeCommonInfo &CI, bool BestCase, MSInheritanceAttr::Spelling SemanticSpelling); - FormatAttr *mergeFormatAttr(Decl *D, SourceRange Range, + FormatAttr *mergeFormatAttr(Decl *D, const AttributeCommonInfo &CI, IdentifierInfo *Format, int FormatIdx, - int FirstArg, unsigned AttrSpellingListIndex); - SectionAttr *mergeSectionAttr(Decl *D, SourceRange Range, StringRef Name, - unsigned AttrSpellingListIndex); - CodeSegAttr *mergeCodeSegAttr(Decl *D, SourceRange Range, StringRef Name, - unsigned AttrSpellingListIndex); - AlwaysInlineAttr *mergeAlwaysInlineAttr(Decl *D, SourceRange Range, - IdentifierInfo *Ident, - unsigned AttrSpellingListIndex); - MinSizeAttr *mergeMinSizeAttr(Decl *D, SourceRange Range, - unsigned AttrSpellingListIndex); + int FirstArg); + SectionAttr *mergeSectionAttr(Decl *D, const AttributeCommonInfo &CI, + StringRef Name); + CodeSegAttr *mergeCodeSegAttr(Decl *D, const AttributeCommonInfo &CI, + StringRef Name); + AlwaysInlineAttr *mergeAlwaysInlineAttr(Decl *D, + const AttributeCommonInfo &CI, + const IdentifierInfo *Ident); + MinSizeAttr *mergeMinSizeAttr(Decl *D, const AttributeCommonInfo &CI); NoSpeculativeLoadHardeningAttr * mergeNoSpeculativeLoadHardeningAttr(Decl *D, const NoSpeculativeLoadHardeningAttr &AL); SpeculativeLoadHardeningAttr * mergeSpeculativeLoadHardeningAttr(Decl *D, const SpeculativeLoadHardeningAttr &AL); - OptimizeNoneAttr *mergeOptimizeNoneAttr(Decl *D, SourceRange Range, - unsigned AttrSpellingListIndex); + OptimizeNoneAttr *mergeOptimizeNoneAttr(Decl *D, + const AttributeCommonInfo &CI); InternalLinkageAttr *mergeInternalLinkageAttr(Decl *D, const ParsedAttr &AL); InternalLinkageAttr *mergeInternalLinkageAttr(Decl *D, const InternalLinkageAttr &AL); @@ -8899,51 +8895,50 @@ void AddOptnoneAttributeIfNoConflicts(FunctionDecl *FD, SourceLocation Loc); /// AddAlignedAttr - Adds an aligned attribute to a particular declaration. - void AddAlignedAttr(SourceRange AttrRange, Decl *D, Expr *E, - unsigned SpellingListIndex, bool IsPackExpansion); - void AddAlignedAttr(SourceRange AttrRange, Decl *D, TypeSourceInfo *T, - unsigned SpellingListIndex, bool IsPackExpansion); + void AddAlignedAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E, + bool IsPackExpansion); + void AddAlignedAttr(Decl *D, const AttributeCommonInfo &CI, TypeSourceInfo *T, + bool IsPackExpansion); /// AddAssumeAlignedAttr - Adds an assume_aligned attribute to a particular /// declaration. - void AddAssumeAlignedAttr(SourceRange AttrRange, Decl *D, Expr *E, Expr *OE, - unsigned SpellingListIndex); + void AddAssumeAlignedAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E, + Expr *OE); /// AddAllocAlignAttr - Adds an alloc_align attribute to a particular /// declaration. - void AddAllocAlignAttr(SourceRange AttrRange, Decl *D, Expr *ParamExpr, - unsigned SpellingListIndex); + void AddAllocAlignAttr(Decl *D, const AttributeCommonInfo &CI, + Expr *ParamExpr); /// AddAlignValueAttr - Adds an align_value attribute to a particular /// declaration. - void AddAlignValueAttr(SourceRange AttrRange, Decl *D, Expr *E, - unsigned SpellingListIndex); + void AddAlignValueAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E); /// AddLaunchBoundsAttr - Adds a launch_bounds attribute to a particular /// declaration. - void AddLaunchBoundsAttr(SourceRange AttrRange, Decl *D, Expr *MaxThreads, - Expr *MinBlocks, unsigned SpellingListIndex); + void AddLaunchBoundsAttr(Decl *D, const AttributeCommonInfo &CI, + Expr *MaxThreads, Expr *MinBlocks); /// AddModeAttr - Adds a mode attribute to a particular declaration. - void AddModeAttr(SourceRange AttrRange, Decl *D, IdentifierInfo *Name, - unsigned SpellingListIndex, bool InInstantiation = false); + void AddModeAttr(Decl *D, const AttributeCommonInfo &CI, IdentifierInfo *Name, + bool InInstantiation = false); - void AddParameterABIAttr(SourceRange AttrRange, Decl *D, - ParameterABI ABI, unsigned SpellingListIndex); + void AddParameterABIAttr(Decl *D, const AttributeCommonInfo &CI, + ParameterABI ABI); enum class RetainOwnershipKind {NS, CF, OS}; - void AddXConsumedAttr(Decl *D, SourceRange SR, unsigned SpellingIndex, + void AddXConsumedAttr(Decl *D, const AttributeCommonInfo &CI, RetainOwnershipKind K, bool IsTemplateInstantiation); /// addAMDGPUFlatWorkGroupSizeAttr - Adds an amdgpu_flat_work_group_size /// attribute to a particular declaration. - void addAMDGPUFlatWorkGroupSizeAttr(SourceRange AttrRange, Decl *D, Expr *Min, - Expr *Max, unsigned SpellingListIndex); + void addAMDGPUFlatWorkGroupSizeAttr(Decl *D, const AttributeCommonInfo &CI, + Expr *Min, Expr *Max); /// addAMDGPUWavePersEUAttr - Adds an amdgpu_waves_per_eu attribute to a /// particular declaration. - void addAMDGPUWavesPerEUAttr(SourceRange AttrRange, Decl *D, Expr *Min, - Expr *Max, unsigned SpellingListIndex); + void addAMDGPUWavesPerEUAttr(Decl *D, const AttributeCommonInfo &CI, + Expr *Min, Expr *Max); bool checkNSReturnsRetainedReturnType(SourceLocation loc, QualType type); Index: cfe/trunk/include/clang/Serialization/ASTBitCodes.h =================================================================== --- cfe/trunk/include/clang/Serialization/ASTBitCodes.h +++ cfe/trunk/include/clang/Serialization/ASTBitCodes.h @@ -41,7 +41,7 @@ /// Version 4 of AST files also requires that the version control branch and /// revision match exactly, since there is no backward compatibility of /// AST files at this time. - const unsigned VERSION_MAJOR = 7; + const unsigned VERSION_MAJOR = 8; /// AST file minor version number supported by this version of /// Clang. Index: cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp =================================================================== --- cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp +++ cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp @@ -291,10 +291,11 @@ static_cast( GlobalMemoryAlignment))); Field->addAttr(AlignedAttr::CreateImplicit( - C, AlignedAttr::GNU_aligned, /*IsAlignmentExpr=*/true, + C, /*IsAlignmentExpr=*/true, IntegerLiteral::Create(C, Align, C.getIntTypeForBitwidth(32, /*Signed=*/0), - SourceLocation()))); + SourceLocation()), + {}, AttributeCommonInfo::AS_GNU, AlignedAttr::GNU_aligned)); } GlobalizedRD->addDecl(Field); MappedDeclsFields.try_emplace(VD, Field); Index: cfe/trunk/lib/Lex/PPDirectives.cpp =================================================================== --- cfe/trunk/lib/Lex/PPDirectives.cpp +++ cfe/trunk/lib/Lex/PPDirectives.cpp @@ -1870,12 +1870,12 @@ SourceLocation StartLoc = IsImportDecl ? IncludeTok.getLocation() : HashLoc; // Complain about attempts to #include files in an audit pragma. - if (PragmaARCCFCodeAuditedLoc.isValid()) { + if (PragmaARCCFCodeAuditedInfo.second.isValid()) { Diag(StartLoc, diag::err_pp_include_in_arc_cf_code_audited) << IsImportDecl; - Diag(PragmaARCCFCodeAuditedLoc, diag::note_pragma_entered_here); + Diag(PragmaARCCFCodeAuditedInfo.second, diag::note_pragma_entered_here); // Immediately leave the pragma. - PragmaARCCFCodeAuditedLoc = SourceLocation(); + PragmaARCCFCodeAuditedInfo = {nullptr, SourceLocation()}; } // Complain about attempts to #include files in an assume-nonnull pragma. Index: cfe/trunk/lib/Lex/PPLexerChange.cpp =================================================================== --- cfe/trunk/lib/Lex/PPLexerChange.cpp +++ cfe/trunk/lib/Lex/PPLexerChange.cpp @@ -376,12 +376,13 @@ // Complain about reaching a true EOF within arc_cf_code_audited. // We don't want to complain about reaching the end of a macro // instantiation or a _Pragma. - if (PragmaARCCFCodeAuditedLoc.isValid() && - !isEndOfMacro && !(CurLexer && CurLexer->Is_PragmaLexer)) { - Diag(PragmaARCCFCodeAuditedLoc, diag::err_pp_eof_in_arc_cf_code_audited); + if (PragmaARCCFCodeAuditedInfo.second.isValid() && !isEndOfMacro && + !(CurLexer && CurLexer->Is_PragmaLexer)) { + Diag(PragmaARCCFCodeAuditedInfo.second, + diag::err_pp_eof_in_arc_cf_code_audited); // Recover by leaving immediately. - PragmaARCCFCodeAuditedLoc = SourceLocation(); + PragmaARCCFCodeAuditedInfo = {nullptr, SourceLocation()}; } // Complain about reaching a true EOF within assume_nonnull. Index: cfe/trunk/lib/Lex/Pragma.cpp =================================================================== --- cfe/trunk/lib/Lex/Pragma.cpp +++ cfe/trunk/lib/Lex/Pragma.cpp @@ -1722,7 +1722,7 @@ PP.Diag(Tok, diag::ext_pp_extra_tokens_at_eol) << "pragma"; // The start location of the active audit. - SourceLocation BeginLoc = PP.getPragmaARCCFCodeAuditedLoc(); + SourceLocation BeginLoc = PP.getPragmaARCCFCodeAuditedInfo().second; // The start location we want after processing this. SourceLocation NewLoc; @@ -1743,7 +1743,7 @@ NewLoc = SourceLocation(); } - PP.setPragmaARCCFCodeAuditedLoc(NewLoc); + PP.setPragmaARCCFCodeAuditedInfo(NameTok.getIdentifierInfo(), NewLoc); } }; Index: cfe/trunk/lib/Parse/ParseDecl.cpp =================================================================== --- cfe/trunk/lib/Parse/ParseDecl.cpp +++ cfe/trunk/lib/Parse/ParseDecl.cpp @@ -347,7 +347,7 @@ bool IsIdentifierArg = attributeHasIdentifierArg(*AttrName) || attributeHasVariadicIdentifierArg(*AttrName); ParsedAttr::Kind AttrKind = - ParsedAttr::getKind(AttrName, ScopeName, Syntax); + ParsedAttr::getParsedKind(AttrName, ScopeName, Syntax); // 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. @@ -438,7 +438,7 @@ assert(Tok.is(tok::l_paren) && "Attribute arg list not starting with '('"); ParsedAttr::Kind AttrKind = - ParsedAttr::getKind(AttrName, ScopeName, Syntax); + ParsedAttr::getParsedKind(AttrName, ScopeName, Syntax); if (AttrKind == ParsedAttr::AT_Availability) { ParseAvailabilityAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName, @@ -488,7 +488,7 @@ assert(Tok.is(tok::l_paren) && "Attribute arg list not starting with '('"); ParsedAttr::Kind AttrKind = - ParsedAttr::getKind(AttrName, ScopeName, Syntax); + ParsedAttr::getParsedKind(AttrName, ScopeName, Syntax); switch (AttrKind) { default: @@ -1689,9 +1689,9 @@ if (!AL.isCXX11Attribute() && !AL.isC2xAttribute()) continue; if (AL.getKind() == ParsedAttr::UnknownAttribute) - Diag(AL.getLoc(), diag::warn_unknown_attribute_ignored) << AL.getName(); + Diag(AL.getLoc(), diag::warn_unknown_attribute_ignored) << AL; else { - Diag(AL.getLoc(), DiagID) << AL.getName(); + Diag(AL.getLoc(), DiagID) << AL; AL.setInvalid(); } } Index: cfe/trunk/lib/Parse/ParseDeclCXX.cpp =================================================================== --- cfe/trunk/lib/Parse/ParseDeclCXX.cpp +++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp @@ -3916,7 +3916,8 @@ static bool IsBuiltInOrStandardCXX11Attribute(IdentifierInfo *AttrName, IdentifierInfo *ScopeName) { - switch (ParsedAttr::getKind(AttrName, ScopeName, ParsedAttr::AS_CXX11)) { + switch ( + ParsedAttr::getParsedKind(AttrName, ScopeName, ParsedAttr::AS_CXX11)) { case ParsedAttr::AT_CarriesDependency: case ParsedAttr::AT_Deprecated: case ParsedAttr::AT_FallThrough: Index: cfe/trunk/lib/Parse/ParseExprCXX.cpp =================================================================== --- cfe/trunk/lib/Parse/ParseExprCXX.cpp +++ cfe/trunk/lib/Parse/ParseExprCXX.cpp @@ -1214,7 +1214,7 @@ A.getKind() == ParsedAttr::AT_CUDAHost || A.getKind() == ParsedAttr::AT_CUDAGlobal) Diag(A.getLoc(), diag::warn_cuda_attr_lambda_position) - << A.getName()->getName(); + << A.getAttrName()->getName(); }; // FIXME: Consider allowing this as an extension for GCC compatibiblity. Index: cfe/trunk/lib/Parse/ParsePragma.cpp =================================================================== --- cfe/trunk/lib/Parse/ParsePragma.cpp +++ cfe/trunk/lib/Parse/ParsePragma.cpp @@ -1468,9 +1468,9 @@ if (Tok.getIdentifierInfo()) { // If we suspect that this is an attribute suggest the use of // '__attribute__'. - if (ParsedAttr::getKind(Tok.getIdentifierInfo(), /*ScopeName=*/nullptr, - ParsedAttr::AS_GNU) != - ParsedAttr::UnknownAttribute) { + if (ParsedAttr::getParsedKind( + Tok.getIdentifierInfo(), /*ScopeName=*/nullptr, + ParsedAttr::AS_GNU) != ParsedAttr::UnknownAttribute) { SourceLocation InsertStartLoc = Tok.getLocation(); ConsumeToken(); if (Tok.is(tok::l_paren)) { @@ -1504,7 +1504,7 @@ ParsedAttr &Attribute = *Attrs.begin(); if (!Attribute.isSupportedByPragmaAttribute()) { Diag(PragmaLoc, diag::err_pragma_attribute_unsupported_attribute) - << Attribute.getName(); + << Attribute; SkipToEnd(); return; } Index: cfe/trunk/lib/Parse/Parser.cpp =================================================================== --- cfe/trunk/lib/Parse/Parser.cpp +++ cfe/trunk/lib/Parse/Parser.cpp @@ -1174,8 +1174,7 @@ if (Tok.isNot(tok::equal)) { for (const ParsedAttr &AL : D.getAttributes()) if (AL.isKnownToGCC() && !AL.isCXX11Attribute()) - Diag(AL.getLoc(), diag::warn_attribute_on_function_definition) - << AL.getName(); + Diag(AL.getLoc(), diag::warn_attribute_on_function_definition) << AL; } // In delayed template parsing mode, for function template we consume the Index: cfe/trunk/lib/Sema/ParsedAttr.cpp =================================================================== --- cfe/trunk/lib/Sema/ParsedAttr.cpp +++ cfe/trunk/lib/Sema/ParsedAttr.cpp @@ -134,9 +134,13 @@ return AttrName; } -ParsedAttr::Kind ParsedAttr::getKind(const IdentifierInfo *Name, - const IdentifierInfo *ScopeName, - Syntax SyntaxUsed) { +bool AttributeCommonInfo::isGNUScope() const { + return ScopeName && (ScopeName->isStr("gnu") || ScopeName->isStr("__gnu__")); +} +AttributeCommonInfo::Kind +AttributeCommonInfo::getParsedKind(const IdentifierInfo *Name, + const IdentifierInfo *ScopeName, + Syntax SyntaxUsed) { StringRef AttrName = Name->getName(); SmallString<64> FullName; @@ -154,16 +158,16 @@ return ::getAttrKind(FullName, SyntaxUsed); } -unsigned ParsedAttr::getAttributeSpellingListIndex() const { +unsigned AttributeCommonInfo::calculateAttributeSpellingListIndex() const { // Both variables will be used in tablegen generated // attribute spell list index matching code. - auto Syntax = static_cast(SyntaxUsed); + auto Syntax = static_cast(getSyntax()); StringRef Scope = - ScopeName ? normalizeAttrScopeName(ScopeName->getName(), Syntax) : ""; - StringRef Name = normalizeAttrName(AttrName->getName(), Scope, Syntax); + getScopeName() ? normalizeAttrScopeName(getScopeName()->getName(), Syntax) + : ""; + StringRef Name = normalizeAttrName(getAttrName()->getName(), Scope, Syntax); #include "clang/Sema/AttrSpellingListIndex.inc" - } struct ParsedAttrInfo { Index: cfe/trunk/lib/Sema/SemaAttr.cpp =================================================================== --- cfe/trunk/lib/Sema/SemaAttr.cpp +++ cfe/trunk/lib/Sema/SemaAttr.cpp @@ -571,12 +571,15 @@ if (VD->isUsed()) Diag(PragmaLoc, diag::warn_used_but_marked_unused) << Name; - VD->addAttr(UnusedAttr::CreateImplicit(Context, UnusedAttr::GNU_unused, - IdTok.getLocation())); + VD->addAttr(UnusedAttr::CreateImplicit(Context, IdTok.getLocation(), + AttributeCommonInfo::AS_Pragma, + UnusedAttr::GNU_unused)); } void Sema::AddCFAuditedAttribute(Decl *D) { - SourceLocation Loc = PP.getPragmaARCCFCodeAuditedLoc(); + IdentifierInfo *Ident; + SourceLocation Loc; + std::tie(Ident, Loc) = PP.getPragmaARCCFCodeAuditedInfo(); if (!Loc.isValid()) return; // Don't add a redundant or conflicting attribute. @@ -584,7 +587,9 @@ D->hasAttr()) return; - D->addAttr(CFAuditedTransferAttr::CreateImplicit(Context, Loc)); + AttributeCommonInfo Info(Ident, SourceRange(Loc), + AttributeCommonInfo::AS_Pragma); + D->addAttr(CFAuditedTransferAttr::CreateImplicit(Context, Info)); } namespace { @@ -735,7 +740,7 @@ if (!Rules.empty()) { auto Diagnostic = Diag(PragmaLoc, diag::err_pragma_attribute_invalid_matchers) - << Attribute.getName(); + << Attribute; SmallVector ExtraRules; for (const auto &Rule : Rules) { ExtraRules.push_back(attr::SubjectMatchRule(Rule.first)); Index: cfe/trunk/lib/Sema/SemaDecl.cpp =================================================================== --- cfe/trunk/lib/Sema/SemaDecl.cpp +++ cfe/trunk/lib/Sema/SemaDecl.cpp @@ -2474,43 +2474,33 @@ // previous decl", for example if the attribute needs to be consistent // between redeclarations, you need to call a custom merge function here. InheritableAttr *NewAttr = nullptr; - unsigned AttrSpellingListIndex = Attr->getSpellingListIndex(); if (const auto *AA = dyn_cast(Attr)) NewAttr = S.mergeAvailabilityAttr( - D, AA->getRange(), AA->getPlatform(), AA->isImplicit(), - AA->getIntroduced(), AA->getDeprecated(), AA->getObsoleted(), - AA->getUnavailable(), AA->getMessage(), AA->getStrict(), - AA->getReplacement(), AMK, AA->getPriority(), AttrSpellingListIndex); + D, *AA, AA->getPlatform(), AA->isImplicit(), AA->getIntroduced(), + AA->getDeprecated(), AA->getObsoleted(), AA->getUnavailable(), + AA->getMessage(), AA->getStrict(), AA->getReplacement(), AMK, + AA->getPriority()); else if (const auto *VA = dyn_cast(Attr)) - NewAttr = S.mergeVisibilityAttr(D, VA->getRange(), VA->getVisibility(), - AttrSpellingListIndex); + NewAttr = S.mergeVisibilityAttr(D, *VA, VA->getVisibility()); else if (const auto *VA = dyn_cast(Attr)) - NewAttr = S.mergeTypeVisibilityAttr(D, VA->getRange(), VA->getVisibility(), - AttrSpellingListIndex); + NewAttr = S.mergeTypeVisibilityAttr(D, *VA, VA->getVisibility()); else if (const auto *ImportA = dyn_cast(Attr)) - NewAttr = S.mergeDLLImportAttr(D, ImportA->getRange(), - AttrSpellingListIndex); + NewAttr = S.mergeDLLImportAttr(D, *ImportA); else if (const auto *ExportA = dyn_cast(Attr)) - NewAttr = S.mergeDLLExportAttr(D, ExportA->getRange(), - AttrSpellingListIndex); + NewAttr = S.mergeDLLExportAttr(D, *ExportA); else if (const auto *FA = dyn_cast(Attr)) - NewAttr = S.mergeFormatAttr(D, FA->getRange(), FA->getType(), - FA->getFormatIdx(), FA->getFirstArg(), - AttrSpellingListIndex); + NewAttr = S.mergeFormatAttr(D, *FA, FA->getType(), FA->getFormatIdx(), + FA->getFirstArg()); else if (const auto *SA = dyn_cast(Attr)) - NewAttr = S.mergeSectionAttr(D, SA->getRange(), SA->getName(), - AttrSpellingListIndex); + NewAttr = S.mergeSectionAttr(D, *SA, SA->getName()); else if (const auto *CSA = dyn_cast(Attr)) - NewAttr = S.mergeCodeSegAttr(D, CSA->getRange(), CSA->getName(), - AttrSpellingListIndex); + NewAttr = S.mergeCodeSegAttr(D, *CSA, CSA->getName()); else if (const auto *IA = dyn_cast(Attr)) - NewAttr = S.mergeMSInheritanceAttr(D, IA->getRange(), IA->getBestCase(), - AttrSpellingListIndex, + NewAttr = S.mergeMSInheritanceAttr(D, *IA, IA->getBestCase(), IA->getSemanticSpelling()); else if (const auto *AA = dyn_cast(Attr)) - NewAttr = S.mergeAlwaysInlineAttr(D, AA->getRange(), - &S.Context.Idents.get(AA->getSpelling()), - AttrSpellingListIndex); + NewAttr = S.mergeAlwaysInlineAttr(D, *AA, + &S.Context.Idents.get(AA->getSpelling())); else if (S.getLangOpts().CUDA && isa(D) && (isa(Attr) || isa(Attr) || isa(Attr))) { @@ -2518,9 +2508,9 @@ // overloading purposes and must not be merged. return false; } else if (const auto *MA = dyn_cast(Attr)) - NewAttr = S.mergeMinSizeAttr(D, MA->getRange(), AttrSpellingListIndex); + NewAttr = S.mergeMinSizeAttr(D, *MA); else if (const auto *OA = dyn_cast(Attr)) - NewAttr = S.mergeOptimizeNoneAttr(D, OA->getRange(), AttrSpellingListIndex); + NewAttr = S.mergeOptimizeNoneAttr(D, *OA); else if (const auto *InternalLinkageA = dyn_cast(Attr)) NewAttr = S.mergeInternalLinkageAttr(D, *InternalLinkageA); else if (const auto *CommonA = dyn_cast(Attr)) @@ -2534,8 +2524,7 @@ AMK == Sema::AMK_ProtocolImplementation)) NewAttr = nullptr; else if (const auto *UA = dyn_cast(Attr)) - NewAttr = S.mergeUuidAttr(D, UA->getRange(), AttrSpellingListIndex, - UA->getGuid()); + NewAttr = S.mergeUuidAttr(D, *UA, UA->getGuid()); else if (const auto *SLHA = dyn_cast(Attr)) NewAttr = S.mergeSpeculativeLoadHardeningAttr(D, *SLHA); else if (const auto *SLHA = dyn_cast(Attr)) @@ -4612,7 +4601,7 @@ TypeSpecType == DeclSpec::TST_enum) { for (const ParsedAttr &AL : DS.getAttributes()) Diag(AL.getLoc(), diag::warn_declspec_attribute_ignored) - << AL.getName() << GetDiagnosticTypeSpecifierID(TypeSpecType); + << AL << GetDiagnosticTypeSpecifierID(TypeSpecType); } } @@ -6288,9 +6277,8 @@ << NewDecl; S.Diag(OldDecl->getLocation(), diag::note_previous_declaration); NewDecl->dropAttr(); - NewDecl->addAttr(::new (S.Context) DLLExportAttr( - NewImportAttr->getRange(), S.Context, - NewImportAttr->getSpellingListIndex())); + NewDecl->addAttr( + DLLExportAttr::CreateImplicit(S.Context, NewImportAttr->getRange())); } else { S.Diag(NewDecl->getLocation(), diag::warn_redeclaration_without_attribute_prev_attribute_ignored) @@ -6866,9 +6854,9 @@ Diag(D.getDeclSpec().getConstexprSpecLoc(), diag::err_constinit_local_variable); else - NewVD->addAttr(::new (Context) ConstInitAttr( - SourceRange(D.getDeclSpec().getConstexprSpecLoc()), Context, - ConstInitAttr::Keyword_constinit)); + NewVD->addAttr(ConstInitAttr::Create( + Context, D.getDeclSpec().getConstexprSpecLoc(), + AttributeCommonInfo::AS_Keyword, ConstInitAttr::Keyword_constinit)); break; } @@ -6990,8 +6978,8 @@ } } - NewVD->addAttr(::new (Context) AsmLabelAttr(SE->getStrTokenLoc(0), - Context, Label, 0)); + NewVD->addAttr(::new (Context) + AsmLabelAttr(Context, SE->getStrTokenLoc(0), Label)); } else if (!ExtnameUndeclaredIdentifiers.empty()) { llvm::DenseMap::iterator I = ExtnameUndeclaredIdentifiers.find(NewVD->getIdentifier()); @@ -8889,8 +8877,8 @@ if (Expr *E = (Expr*) D.getAsmLabel()) { // The parser guarantees this is a string. StringLiteral *SE = cast(E); - NewFD->addAttr(::new (Context) AsmLabelAttr(SE->getStrTokenLoc(0), Context, - SE->getString(), 0)); + NewFD->addAttr(::new (Context) AsmLabelAttr(Context, SE->getStrTokenLoc(0), + SE->getString())); } else if (!ExtnameUndeclaredIdentifiers.empty()) { llvm::DenseMap::iterator I = ExtnameUndeclaredIdentifiers.find(NewFD->getIdentifier()); @@ -8988,9 +8976,9 @@ NewFD->setParams(Params); if (D.getDeclSpec().isNoreturnSpecified()) - NewFD->addAttr( - ::new(Context) C11NoReturnAttr(D.getDeclSpec().getNoreturnSpecLoc(), - Context, 0)); + NewFD->addAttr(C11NoReturnAttr::Create(Context, + D.getDeclSpec().getNoreturnSpecLoc(), + AttributeCommonInfo::AS_Keyword)); // Functions returning a variably modified type violate C99 6.7.5.2p2 // because all functions have linkage. @@ -9002,19 +8990,18 @@ // Apply an implicit SectionAttr if '#pragma clang section text' is active if (PragmaClangTextSection.Valid && D.isFunctionDefinition() && - !NewFD->hasAttr()) { - NewFD->addAttr(PragmaClangTextSectionAttr::CreateImplicit(Context, - PragmaClangTextSection.SectionName, - PragmaClangTextSection.PragmaLocation)); - } + !NewFD->hasAttr()) + NewFD->addAttr(PragmaClangTextSectionAttr::CreateImplicit( + Context, PragmaClangTextSection.SectionName, + PragmaClangTextSection.PragmaLocation, AttributeCommonInfo::AS_Pragma)); // Apply an implicit SectionAttr if #pragma code_seg is active. if (CodeSegStack.CurrentValue && D.isFunctionDefinition() && !NewFD->hasAttr()) { - NewFD->addAttr( - SectionAttr::CreateImplicit(Context, SectionAttr::Declspec_allocate, - CodeSegStack.CurrentValue->getString(), - CodeSegStack.CurrentPragmaLocation)); + NewFD->addAttr(SectionAttr::CreateImplicit( + Context, CodeSegStack.CurrentValue->getString(), + CodeSegStack.CurrentPragmaLocation, AttributeCommonInfo::AS_Pragma, + SectionAttr::Declspec_allocate)); if (UnifySection(CodeSegStack.CurrentValue->getString(), ASTContext::PSF_Implicit | ASTContext::PSF_Execute | ASTContext::PSF_Read, @@ -9550,12 +9537,11 @@ if (Attr *A = getImplicitCodeSegAttrFromClass(*this, FD)) return A; if (!FD->hasAttr() && IsDefinition && - CodeSegStack.CurrentValue) { - return SectionAttr::CreateImplicit(getASTContext(), - SectionAttr::Declspec_allocate, - CodeSegStack.CurrentValue->getString(), - CodeSegStack.CurrentPragmaLocation); - } + CodeSegStack.CurrentValue) + return SectionAttr::CreateImplicit( + getASTContext(), CodeSegStack.CurrentValue->getString(), + CodeSegStack.CurrentPragmaLocation, AttributeCommonInfo::AS_Pragma, + SectionAttr::Declspec_allocate); return nullptr; } @@ -12401,11 +12387,11 @@ Stack = &DataSegStack; SectionFlags |= ASTContext::PSF_Write; } - if (Stack->CurrentValue && !var->hasAttr()) { + if (Stack->CurrentValue && !var->hasAttr()) var->addAttr(SectionAttr::CreateImplicit( - Context, SectionAttr::Declspec_allocate, - Stack->CurrentValue->getString(), Stack->CurrentPragmaLocation)); - } + Context, Stack->CurrentValue->getString(), + Stack->CurrentPragmaLocation, AttributeCommonInfo::AS_Pragma, + SectionAttr::Declspec_allocate)); if (const SectionAttr *SA = var->getAttr()) if (UnifySection(SA->getName(), SectionFlags, var)) var->dropAttr(); @@ -12415,7 +12401,8 @@ // attribute. if (CurInitSeg && var->getInit()) var->addAttr(InitSegAttr::CreateImplicit(Context, CurInitSeg->getString(), - CurInitSegLoc)); + CurInitSegLoc, + AttributeCommonInfo::AS_Pragma)); } // All the following checks are C++ only. @@ -12548,9 +12535,7 @@ NewAttr->setInherited(true); VD->addAttr(NewAttr); } else if (Attr *A = FD->getAttr()) { - auto *NewAttr = ::new (getASTContext()) DLLExportAttr(A->getRange(), - getASTContext(), - A->getSpellingListIndex()); + auto *NewAttr = DLLExportAttr::CreateImplicit(getASTContext(), *A); NewAttr->setInherited(true); VD->addAttr(NewAttr); @@ -12560,9 +12545,7 @@ FD->addAttr(NewAttr); } else if (Attr *A = FD->getAttr()) { - auto *NewAttr = ::new (getASTContext()) DLLImportAttr(A->getRange(), - getASTContext(), - A->getSpellingListIndex()); + auto *NewAttr = DLLImportAttr::CreateImplicit(getASTContext(), *A); NewAttr->setInherited(true); VD->addAttr(NewAttr); } @@ -12582,17 +12565,20 @@ if (VD->hasGlobalStorage() && VD->isThisDeclarationADefinition() && !inTemplateInstantiation() && !VD->hasAttr()) { if (PragmaClangBSSSection.Valid) - VD->addAttr(PragmaClangBSSSectionAttr::CreateImplicit(Context, - PragmaClangBSSSection.SectionName, - PragmaClangBSSSection.PragmaLocation)); + VD->addAttr(PragmaClangBSSSectionAttr::CreateImplicit( + Context, PragmaClangBSSSection.SectionName, + PragmaClangBSSSection.PragmaLocation, + AttributeCommonInfo::AS_Pragma)); if (PragmaClangDataSection.Valid) - VD->addAttr(PragmaClangDataSectionAttr::CreateImplicit(Context, - PragmaClangDataSection.SectionName, - PragmaClangDataSection.PragmaLocation)); + VD->addAttr(PragmaClangDataSectionAttr::CreateImplicit( + Context, PragmaClangDataSection.SectionName, + PragmaClangDataSection.PragmaLocation, + AttributeCommonInfo::AS_Pragma)); if (PragmaClangRodataSection.Valid) - VD->addAttr(PragmaClangRodataSectionAttr::CreateImplicit(Context, - PragmaClangRodataSection.SectionName, - PragmaClangRodataSection.PragmaLocation)); + VD->addAttr(PragmaClangRodataSectionAttr::CreateImplicit( + Context, PragmaClangRodataSection.SectionName, + PragmaClangRodataSection.PragmaLocation, + AttributeCommonInfo::AS_Pragma)); } if (auto *DD = dyn_cast(ThisDecl)) { @@ -15630,8 +15616,9 @@ return; if (FinalLoc.isValid()) - Record->addAttr(new (Context) - FinalAttr(FinalLoc, Context, IsFinalSpelledSealed)); + Record->addAttr(FinalAttr::Create( + Context, FinalLoc, AttributeCommonInfo::AS_Keyword, + static_cast(IsFinalSpelledSealed))); // C++ [class]p2: // [...] The class-name is also inserted into the scope of the @@ -17551,8 +17538,10 @@ SourceLocation AliasNameLoc) { NamedDecl *PrevDecl = LookupSingleName(TUScope, Name, NameLoc, LookupOrdinaryName); + AttributeCommonInfo Info(AliasName, SourceRange(AliasNameLoc), + AttributeCommonInfo::AS_Pragma); AsmLabelAttr *Attr = - AsmLabelAttr::CreateImplicit(Context, AliasName->getName(), AliasNameLoc); + AsmLabelAttr::CreateImplicit(Context, AliasName->getName(), Info); // If a declaration that: // 1) declares a function or a variable @@ -17575,7 +17564,7 @@ Decl *PrevDecl = LookupSingleName(TUScope, Name, NameLoc, LookupOrdinaryName); if (PrevDecl) { - PrevDecl->addAttr(WeakAttr::CreateImplicit(Context, PragmaLoc)); + PrevDecl->addAttr(WeakAttr::CreateImplicit(Context, PragmaLoc, AttributeCommonInfo::AS_Pragma)); } else { (void)WeakUndeclaredIdentifiers.insert( std::pair Index: cfe/trunk/lib/Sema/SemaDeclAttr.cpp =================================================================== --- cfe/trunk/lib/Sema/SemaDeclAttr.cpp +++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp @@ -398,18 +398,11 @@ /// Applies the given attribute to the Decl without performing any /// additional semantic checking. template -static void handleSimpleAttribute(Sema &S, Decl *D, SourceRange SR, - unsigned SpellingIndex) { - D->addAttr(::new (S.Context) AttrType(SR, S.Context, SpellingIndex)); +static void handleSimpleAttribute(Sema &S, Decl *D, + const AttributeCommonInfo &CI) { + D->addAttr(::new (S.Context) AttrType(S.Context, CI)); } -template -static void handleSimpleAttribute(Sema &S, Decl *D, const ParsedAttr &AL) { - handleSimpleAttribute(S, D, AL.getRange(), - AL.getAttributeSpellingListIndex()); -} - - template static const Sema::SemaDiagnosticBuilder& appendDiagnostics(const Sema::SemaDiagnosticBuilder &Bldr) { @@ -429,28 +422,16 @@ /// Otherwise, emit diagnostic {@code DiagID}, passing in all parameters /// specified in {@code ExtraArgs}. template -static void -handleSimpleAttributeOrDiagnose(Sema &S, Decl *D, SourceRange SR, - unsigned SpellingIndex, - bool PassesCheck, - unsigned DiagID, DiagnosticArgs&&... ExtraArgs) { +static void handleSimpleAttributeOrDiagnose(Sema &S, Decl *D, + const AttributeCommonInfo &CI, + bool PassesCheck, unsigned DiagID, + DiagnosticArgs &&... ExtraArgs) { if (!PassesCheck) { Sema::SemaDiagnosticBuilder DB = S.Diag(D->getBeginLoc(), DiagID); appendDiagnostics(DB, std::forward(ExtraArgs)...); return; } - handleSimpleAttribute(S, D, SR, SpellingIndex); -} - -template -static void -handleSimpleAttributeOrDiagnose(Sema &S, Decl *D, const ParsedAttr &AL, - bool PassesCheck, - unsigned DiagID, - DiagnosticArgs&&... ExtraArgs) { - return handleSimpleAttributeOrDiagnose( - S, D, AL.getRange(), AL.getAttributeSpellingListIndex(), PassesCheck, - DiagID, std::forward(ExtraArgs)...); + handleSimpleAttribute(S, D, CI); } template @@ -745,9 +726,7 @@ if (!threadSafetyCheckIsPointer(S, D, AL)) return; - D->addAttr(::new (S.Context) - PtGuardedVarAttr(AL.getRange(), S.Context, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) PtGuardedVarAttr(S.Context, AL)); } static bool checkGuardedByAttrCommon(Sema &S, Decl *D, const ParsedAttr &AL, @@ -769,8 +748,7 @@ if (!checkGuardedByAttrCommon(S, D, AL, Arg)) return; - D->addAttr(::new (S.Context) GuardedByAttr( - AL.getRange(), S.Context, Arg, AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) GuardedByAttr(S.Context, AL, Arg)); } static void handlePtGuardedByAttr(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -781,8 +759,7 @@ if (!threadSafetyCheckIsPointer(S, D, AL)) return; - D->addAttr(::new (S.Context) PtGuardedByAttr( - AL.getRange(), S.Context, Arg, AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) PtGuardedByAttr(S.Context, AL, Arg)); } static bool checkAcquireOrderAttrCommon(Sema &S, Decl *D, const ParsedAttr &AL, @@ -811,9 +788,8 @@ return; Expr **StartArg = &Args[0]; - D->addAttr(::new (S.Context) AcquiredAfterAttr( - AL.getRange(), S.Context, StartArg, Args.size(), - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) + AcquiredAfterAttr(S.Context, AL, StartArg, Args.size())); } static void handleAcquiredBeforeAttr(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -822,9 +798,8 @@ return; Expr **StartArg = &Args[0]; - D->addAttr(::new (S.Context) AcquiredBeforeAttr( - AL.getRange(), S.Context, StartArg, Args.size(), - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) + AcquiredBeforeAttr(S.Context, AL, StartArg, Args.size())); } static bool checkLockFunAttrCommon(Sema &S, Decl *D, const ParsedAttr &AL, @@ -844,8 +819,7 @@ unsigned Size = Args.size(); Expr **StartArg = Size == 0 ? nullptr : &Args[0]; D->addAttr(::new (S.Context) - AssertSharedLockAttr(AL.getRange(), S.Context, StartArg, Size, - AL.getAttributeSpellingListIndex())); + AssertSharedLockAttr(S.Context, AL, StartArg, Size)); } static void handleAssertExclusiveLockAttr(Sema &S, Decl *D, @@ -856,9 +830,8 @@ unsigned Size = Args.size(); Expr **StartArg = Size == 0 ? nullptr : &Args[0]; - D->addAttr(::new (S.Context) AssertExclusiveLockAttr( - AL.getRange(), S.Context, StartArg, Size, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) + AssertExclusiveLockAttr(S.Context, AL, StartArg, Size)); } /// Checks to be sure that the given parameter number is in bounds, and @@ -919,8 +892,7 @@ } D->addAttr(::new (S.Context) - AllocSizeAttr(AL.getRange(), S.Context, SizeArgNo, NumberArgNo, - AL.getAttributeSpellingListIndex())); + AllocSizeAttr(S.Context, AL, SizeArgNo, NumberArgNo)); } static bool checkTryLockFunAttrCommon(Sema &S, Decl *D, const ParsedAttr &AL, @@ -947,8 +919,7 @@ return; D->addAttr(::new (S.Context) SharedTrylockFunctionAttr( - AL.getRange(), S.Context, AL.getArgAsExpr(0), Args.data(), Args.size(), - AL.getAttributeSpellingListIndex())); + S.Context, AL, AL.getArgAsExpr(0), Args.data(), Args.size())); } static void handleExclusiveTrylockFunctionAttr(Sema &S, Decl *D, @@ -958,8 +929,7 @@ return; D->addAttr(::new (S.Context) ExclusiveTrylockFunctionAttr( - AL.getRange(), S.Context, AL.getArgAsExpr(0), Args.data(), - Args.size(), AL.getAttributeSpellingListIndex())); + S.Context, AL, AL.getArgAsExpr(0), Args.data(), Args.size())); } static void handleLockReturnedAttr(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -970,9 +940,7 @@ if (Size == 0) return; - D->addAttr(::new (S.Context) - LockReturnedAttr(AL.getRange(), S.Context, Args[0], - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) LockReturnedAttr(S.Context, AL, Args[0])); } static void handleLocksExcludedAttr(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -988,8 +956,7 @@ Expr **StartArg = &Args[0]; D->addAttr(::new (S.Context) - LocksExcludedAttr(AL.getRange(), S.Context, StartArg, Size, - AL.getAttributeSpellingListIndex())); + LocksExcludedAttr(S.Context, AL, StartArg, Size)); } static bool checkFunctionConditionAttr(Sema &S, Decl *D, const ParsedAttr &AL, @@ -1026,9 +993,7 @@ Expr *Cond; StringRef Msg; if (checkFunctionConditionAttr(S, D, AL, Cond, Msg)) - D->addAttr(::new (S.Context) - EnableIfAttr(AL.getRange(), S.Context, Cond, Msg, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) EnableIfAttr(S.Context, AL, Cond, Msg)); } namespace { @@ -1100,8 +1065,7 @@ if (const auto *FD = dyn_cast(D)) ArgDependent = ArgumentDependenceChecker(FD).referencesArgs(Cond); D->addAttr(::new (S.Context) DiagnoseIfAttr( - AL.getRange(), S.Context, Cond, Msg, DiagType, ArgDependent, - cast(D), AL.getAttributeSpellingListIndex())); + S.Context, AL, Cond, Msg, DiagType, ArgDependent, cast(D))); } static void handlePassObjectSizeAttr(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -1133,8 +1097,7 @@ return; } - D->addAttr(::new (S.Context) PassObjectSizeAttr( - AL.getRange(), S.Context, (int)Type, AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) PassObjectSizeAttr(S.Context, AL, (int)Type)); } static void handleConsumableAttr(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -1154,9 +1117,7 @@ return; } - D->addAttr(::new (S.Context) - ConsumableAttr(AL.getRange(), S.Context, DefaultState, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) ConsumableAttr(S.Context, AL, DefaultState)); } static bool checkForConsumableClass(Sema &S, const CXXMethodDecl *MD, @@ -1207,8 +1168,7 @@ } D->addAttr(::new (S.Context) - CallableWhenAttr(AL.getRange(), S.Context, States.data(), - States.size(), AL.getAttributeSpellingListIndex())); + CallableWhenAttr(S.Context, AL, States.data(), States.size())); } static void handleParamTypestateAttr(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -1242,9 +1202,7 @@ // return; //} - D->addAttr(::new (S.Context) - ParamTypestateAttr(AL.getRange(), S.Context, ParamState, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) ParamTypestateAttr(S.Context, AL, ParamState)); } static void handleReturnTypestateAttr(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -1289,9 +1247,7 @@ // return; //} - D->addAttr(::new (S.Context) - ReturnTypestateAttr(AL.getRange(), S.Context, ReturnState, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) ReturnTypestateAttr(S.Context, AL, ReturnState)); } static void handleSetTypestateAttr(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -1313,9 +1269,7 @@ return; } - D->addAttr(::new (S.Context) - SetTypestateAttr(AL.getRange(), S.Context, NewState, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) SetTypestateAttr(S.Context, AL, NewState)); } static void handleTestTypestateAttr(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -1337,9 +1291,7 @@ return; } - D->addAttr(::new (S.Context) - TestTypestateAttr(AL.getRange(), S.Context, TestState, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) TestTypestateAttr(S.Context, AL, TestState)); } static void handleExtVectorTypeAttr(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -1349,8 +1301,7 @@ static void handlePackedAttr(Sema &S, Decl *D, const ParsedAttr &AL) { if (auto *TD = dyn_cast(D)) - TD->addAttr(::new (S.Context) PackedAttr(AL.getRange(), S.Context, - AL.getAttributeSpellingListIndex())); + TD->addAttr(::new (S.Context) PackedAttr(S.Context, AL)); else if (auto *FD = dyn_cast(D)) { bool BitfieldByteAligned = (!FD->getType()->isDependentType() && !FD->getType()->isIncompleteType() && @@ -1363,15 +1314,13 @@ S.Diag(AL.getLoc(), diag::warn_attribute_ignored_for_field_of_type) << AL << FD->getType(); else - FD->addAttr(::new (S.Context) PackedAttr( - AL.getRange(), S.Context, AL.getAttributeSpellingListIndex())); + FD->addAttr(::new (S.Context) PackedAttr(S.Context, AL)); } else { // Report warning about changed offset in the newer compiler versions. if (BitfieldByteAligned) S.Diag(AL.getLoc(), diag::warn_attribute_packed_for_bitfield); - FD->addAttr(::new (S.Context) PackedAttr( - AL.getRange(), S.Context, AL.getAttributeSpellingListIndex())); + FD->addAttr(::new (S.Context) PackedAttr(S.Context, AL)); } } else @@ -1408,9 +1357,7 @@ if (!checkIBOutletCommon(S, D, AL)) return; - D->addAttr(::new (S.Context) - IBOutletAttr(AL.getRange(), S.Context, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) IBOutletAttr(S.Context, AL)); } static void handleIBOutletCollection(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -1453,9 +1400,7 @@ return; } - D->addAttr(::new (S.Context) - IBOutletCollectionAttr(AL.getRange(), S.Context, QTLoc, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) IBOutletCollectionAttr(S.Context, AL, QTLoc)); } bool Sema::isValidPointerAttrType(QualType T, bool RefOkay) { @@ -1538,9 +1483,7 @@ ParamIdx *Start = NonNullArgs.data(); unsigned Size = NonNullArgs.size(); llvm::array_pod_sort(Start, Start + Size); - D->addAttr(::new (S.Context) - NonNullAttr(AL.getRange(), S.Context, Start, Size, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) NonNullAttr(S.Context, AL, Start, Size)); } static void handleNonNullAttrParameter(Sema &S, ParmVarDecl *D, @@ -1560,9 +1503,7 @@ D->getSourceRange())) return; - D->addAttr(::new (S.Context) - NonNullAttr(AL.getRange(), S.Context, nullptr, 0, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) NonNullAttr(S.Context, AL, nullptr, 0)); } static void handleReturnsNonNullAttr(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -1572,9 +1513,7 @@ /* isReturnValue */ true)) return; - D->addAttr(::new (S.Context) - ReturnsNonNullAttr(AL.getRange(), S.Context, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) ReturnsNonNullAttr(S.Context, AL)); } static void handleNoEscapeAttr(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -1589,33 +1528,30 @@ return; } - D->addAttr(::new (S.Context) NoEscapeAttr( - AL.getRange(), S.Context, AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) NoEscapeAttr(S.Context, AL)); } static void handleAssumeAlignedAttr(Sema &S, Decl *D, const ParsedAttr &AL) { Expr *E = AL.getArgAsExpr(0), *OE = AL.getNumArgs() > 1 ? AL.getArgAsExpr(1) : nullptr; - S.AddAssumeAlignedAttr(AL.getRange(), D, E, OE, - AL.getAttributeSpellingListIndex()); + S.AddAssumeAlignedAttr(D, AL, E, OE); } static void handleAllocAlignAttr(Sema &S, Decl *D, const ParsedAttr &AL) { - S.AddAllocAlignAttr(AL.getRange(), D, AL.getArgAsExpr(0), - AL.getAttributeSpellingListIndex()); + S.AddAllocAlignAttr(D, AL, AL.getArgAsExpr(0)); } -void Sema::AddAssumeAlignedAttr(SourceRange AttrRange, Decl *D, Expr *E, - Expr *OE, unsigned SpellingListIndex) { +void Sema::AddAssumeAlignedAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E, + Expr *OE) { QualType ResultType = getFunctionOrMethodResultType(D); SourceRange SR = getFunctionOrMethodResultSourceRange(D); - AssumeAlignedAttr TmpAttr(AttrRange, Context, E, OE, SpellingListIndex); - SourceLocation AttrLoc = AttrRange.getBegin(); + AssumeAlignedAttr TmpAttr(Context, CI, E, OE); + SourceLocation AttrLoc = TmpAttr.getLocation(); if (!isValidPointerAttrType(ResultType, /* RefOkay */ true)) { Diag(AttrLoc, diag::warn_attribute_return_pointers_refs_only) - << &TmpAttr << AttrRange << SR; + << &TmpAttr << TmpAttr.getRange() << SR; return; } @@ -1652,21 +1588,20 @@ } } - D->addAttr(::new (Context) - AssumeAlignedAttr(AttrRange, Context, E, OE, SpellingListIndex)); + D->addAttr(::new (Context) AssumeAlignedAttr(Context, CI, E, OE)); } -void Sema::AddAllocAlignAttr(SourceRange AttrRange, Decl *D, Expr *ParamExpr, - unsigned SpellingListIndex) { +void Sema::AddAllocAlignAttr(Decl *D, const AttributeCommonInfo &CI, + Expr *ParamExpr) { QualType ResultType = getFunctionOrMethodResultType(D); - AllocAlignAttr TmpAttr(AttrRange, Context, ParamIdx(), SpellingListIndex); - SourceLocation AttrLoc = AttrRange.getBegin(); + AllocAlignAttr TmpAttr(Context, CI, ParamIdx()); + SourceLocation AttrLoc = CI.getLoc(); if (!ResultType->isDependentType() && !isValidPointerAttrType(ResultType, /* RefOkay */ true)) { Diag(AttrLoc, diag::warn_attribute_return_pointers_refs_only) - << &TmpAttr << AttrRange << getFunctionOrMethodResultSourceRange(D); + << &TmpAttr << CI.getRange() << getFunctionOrMethodResultSourceRange(D); return; } @@ -1684,8 +1619,7 @@ return; } - D->addAttr(::new (Context) - AllocAlignAttr(AttrRange, Context, Idx, SpellingListIndex)); + D->addAttr(::new (Context) AllocAlignAttr(Context, CI, Idx)); } /// Normalize the attribute, __foo__ becomes foo. @@ -1716,8 +1650,7 @@ // Figure out our Kind. OwnershipAttr::OwnershipKind K = - OwnershipAttr(AL.getLoc(), S.Context, nullptr, nullptr, 0, - AL.getAttributeSpellingListIndex()).getOwnKind(); + OwnershipAttr(S.Context, AL, nullptr, nullptr, 0).getOwnKind(); // Check arguments. switch (K) { @@ -1799,8 +1732,7 @@ unsigned Size = OwnershipArgs.size(); llvm::array_pod_sort(Start, Start + Size); D->addAttr(::new (S.Context) - OwnershipAttr(AL.getLoc(), S.Context, Module, Start, Size, - AL.getAttributeSpellingListIndex())); + OwnershipAttr(S.Context, AL, Module, Start, Size)); } static void handleWeakRefAttr(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -1856,12 +1788,9 @@ if (AL.getNumArgs() && S.checkStringLiteralArgumentAttr(AL, 0, Str)) // GCC will accept anything as the argument of weakref. Should we // check for an existing decl? - D->addAttr(::new (S.Context) AliasAttr(AL.getRange(), S.Context, Str, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) AliasAttr(S.Context, AL, Str)); - D->addAttr(::new (S.Context) - WeakRefAttr(AL.getRange(), S.Context, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) WeakRefAttr(S.Context, AL)); } static void handleIFuncAttr(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -1876,8 +1805,7 @@ return; } - D->addAttr(::new (S.Context) IFuncAttr(AL.getRange(), S.Context, Str, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) IFuncAttr(S.Context, AL, Str)); } static void handleAliasAttr(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -1918,8 +1846,7 @@ ND->markUsed(S.Context); } - D->addAttr(::new (S.Context) AliasAttr(AL.getRange(), S.Context, Str, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) AliasAttr(S.Context, AL, Str)); } static void handleTLSModelAttr(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -1936,16 +1863,13 @@ return; } - D->addAttr(::new (S.Context) - TLSModelAttr(AL.getRange(), S.Context, Model, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) TLSModelAttr(S.Context, AL, Model)); } static void handleRestrictAttr(Sema &S, Decl *D, const ParsedAttr &AL) { QualType ResultType = getFunctionOrMethodResultType(D); if (ResultType->isAnyPointerType() || ResultType->isBlockPointerType()) { - D->addAttr(::new (S.Context) RestrictAttr( - AL.getRange(), S.Context, AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) RestrictAttr(S.Context, AL)); return; } @@ -1996,13 +1920,11 @@ FD->setIsMultiVersion(true); if (AL.getKind() == ParsedAttr::AT_CPUSpecific) - D->addAttr(::new (S.Context) CPUSpecificAttr( - AL.getRange(), S.Context, CPUs.data(), CPUs.size(), - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) + CPUSpecificAttr(S.Context, AL, CPUs.data(), CPUs.size())); else - D->addAttr(::new (S.Context) CPUDispatchAttr( - AL.getRange(), S.Context, CPUs.data(), CPUs.size(), - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) + CPUDispatchAttr(S.Context, AL, CPUs.data(), CPUs.size())); } static void handleCommonAttr(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -2031,8 +1953,7 @@ } } - D->addAttr(::new (S.Context) NakedAttr(AL.getRange(), S.Context, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) NakedAttr(S.Context, AL)); } static void handleNoReturnAttr(Sema &S, Decl *D, const ParsedAttr &Attrs) { @@ -2044,8 +1965,7 @@ return; } - D->addAttr(::new (S.Context) NoReturnAttr( - Attrs.getRange(), S.Context, Attrs.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) NoReturnAttr(S.Context, Attrs)); } static void handleNoCfCheckAttr(Sema &S, Decl *D, const ParsedAttr &Attrs) { @@ -2091,9 +2011,7 @@ } } - D->addAttr(::new (S.Context) - AnalyzerNoReturnAttr(AL.getRange(), S.Context, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) AnalyzerNoReturnAttr(S.Context, AL)); } // PS3 PPU-specific. @@ -2148,8 +2066,7 @@ count++; } - D->addAttr(::new (S.Context) VecReturnAttr( - AL.getRange(), S.Context, AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) VecReturnAttr(S.Context, AL)); } static void handleDependencyAttr(Sema &S, Scope *Scope, Decl *D, @@ -2164,9 +2081,7 @@ } } - D->addAttr(::new (S.Context) CarriesDependencyAttr( - AL.getRange(), S.Context, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) CarriesDependencyAttr(S.Context, AL)); } static void handleUnusedAttr(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -2177,8 +2092,7 @@ if (!S.getLangOpts().CPlusPlus17 && IsCXX17Attr) S.Diag(AL.getLoc(), diag::ext_cxx17_attr) << AL; - D->addAttr(::new (S.Context) UnusedAttr( - AL.getRange(), S.Context, AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) UnusedAttr(S.Context, AL)); } static void handleConstructorAttr(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -2187,9 +2101,7 @@ !checkUInt32Argument(S, AL, AL.getArgAsExpr(0), priority)) return; - D->addAttr(::new (S.Context) - ConstructorAttr(AL.getRange(), S.Context, priority, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) ConstructorAttr(S.Context, AL, priority)); } static void handleDestructorAttr(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -2198,9 +2110,7 @@ !checkUInt32Argument(S, AL, AL.getArgAsExpr(0), priority)) return; - D->addAttr(::new (S.Context) - DestructorAttr(AL.getRange(), S.Context, priority, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) DestructorAttr(S.Context, AL, priority)); } template @@ -2210,8 +2120,7 @@ if (AL.getNumArgs() == 1 && !S.checkStringLiteralArgumentAttr(AL, 0, Str)) return; - D->addAttr(::new (S.Context) AttrTy(AL.getRange(), S.Context, Str, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) AttrTy(S.Context, AL, Str)); } static void handleObjCSuppresProtocolAttr(Sema &S, Decl *D, @@ -2222,9 +2131,7 @@ return; } - D->addAttr(::new (S.Context) - ObjCExplicitProtocolImplAttr(AL.getRange(), S.Context, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) ObjCExplicitProtocolImplAttr(S.Context, AL)); } static bool checkAvailabilityAttr(Sema &S, SourceRange Range, @@ -2285,10 +2192,11 @@ } AvailabilityAttr *Sema::mergeAvailabilityAttr( - NamedDecl *D, SourceRange Range, IdentifierInfo *Platform, bool Implicit, - VersionTuple Introduced, VersionTuple Deprecated, VersionTuple Obsoleted, - bool IsUnavailable, StringRef Message, bool IsStrict, StringRef Replacement, - AvailabilityMergeKind AMK, int Priority, unsigned AttrSpellingListIndex) { + NamedDecl *D, const AttributeCommonInfo &CI, IdentifierInfo *Platform, + bool Implicit, VersionTuple Introduced, VersionTuple Deprecated, + VersionTuple Obsoleted, bool IsUnavailable, StringRef Message, + bool IsStrict, StringRef Replacement, AvailabilityMergeKind AMK, + int Priority) { VersionTuple MergedIntroduced = Introduced; VersionTuple MergedDeprecated = Deprecated; VersionTuple MergedObsoleted = Obsoleted; @@ -2379,12 +2287,12 @@ << (AMK == AMK_Override); } if (AMK == AMK_Override) - Diag(Range.getBegin(), diag::note_overridden_method); + Diag(CI.getLoc(), diag::note_overridden_method); else - Diag(Range.getBegin(), diag::note_protocol_method); + Diag(CI.getLoc(), diag::note_protocol_method); } else { Diag(OldAA->getLocation(), diag::warn_mismatched_availability); - Diag(Range.getBegin(), diag::note_previous_attribute); + Diag(CI.getLoc(), diag::note_previous_attribute); } Attrs.erase(Attrs.begin() + i); @@ -2426,13 +2334,12 @@ // Only create a new attribute if !OverrideOrImpl, but we want to do // the checking. - if (!checkAvailabilityAttr(*this, Range, Platform, MergedIntroduced, + if (!checkAvailabilityAttr(*this, CI.getRange(), Platform, MergedIntroduced, MergedDeprecated, MergedObsoleted) && !OverrideOrImpl) { - auto *Avail = ::new (Context) - AvailabilityAttr(Range, Context, Platform, Introduced, Deprecated, - Obsoleted, IsUnavailable, Message, IsStrict, - Replacement, Priority, AttrSpellingListIndex); + auto *Avail = ::new (Context) AvailabilityAttr( + Context, CI, Platform, Introduced, Deprecated, Obsoleted, IsUnavailable, + Message, IsStrict, Replacement, Priority); Avail->setImplicit(Implicit); return Avail; } @@ -2443,7 +2350,6 @@ if (!checkAttributeNumArgs(S, AL, 1)) return; IdentifierLoc *Platform = AL.getArgAsIdent(0); - unsigned Index = AL.getAttributeSpellingListIndex(); IdentifierInfo *II = Platform->Ident; if (AvailabilityAttr::getPrettyPlatformName(II->getName()).empty()) @@ -2479,9 +2385,9 @@ ? Sema::AP_PragmaClangAttribute : Sema::AP_Explicit; AvailabilityAttr *NewAttr = S.mergeAvailabilityAttr( - ND, AL.getRange(), II, false /*Implicit*/, Introduced.Version, - Deprecated.Version, Obsoleted.Version, IsUnavailable, Str, IsStrict, - Replacement, Sema::AMK_None, PriorityModifier, Index); + ND, AL, II, false /*Implicit*/, Introduced.Version, Deprecated.Version, + Obsoleted.Version, IsUnavailable, Str, IsStrict, Replacement, + Sema::AMK_None, PriorityModifier); if (NewAttr) D->addAttr(NewAttr); @@ -2519,10 +2425,10 @@ auto NewObsoleted = adjustWatchOSVersion(Obsoleted.Version); AvailabilityAttr *NewAttr = S.mergeAvailabilityAttr( - ND, AL.getRange(), NewII, true /*Implicit*/, NewIntroduced, - NewDeprecated, NewObsoleted, IsUnavailable, Str, IsStrict, - Replacement, Sema::AMK_None, - PriorityModifier + Sema::AP_InferredFromOtherPlatform, Index); + ND, AL, NewII, true /*Implicit*/, NewIntroduced, NewDeprecated, + NewObsoleted, IsUnavailable, Str, IsStrict, Replacement, + Sema::AMK_None, + PriorityModifier + Sema::AP_InferredFromOtherPlatform); if (NewAttr) D->addAttr(NewAttr); } @@ -2537,10 +2443,10 @@ if (NewII) { AvailabilityAttr *NewAttr = S.mergeAvailabilityAttr( - ND, AL.getRange(), NewII, true /*Implicit*/, Introduced.Version, + ND, AL, NewII, true /*Implicit*/, Introduced.Version, Deprecated.Version, Obsoleted.Version, IsUnavailable, Str, IsStrict, Replacement, Sema::AMK_None, - PriorityModifier + Sema::AP_InferredFromOtherPlatform, Index); + PriorityModifier + Sema::AP_InferredFromOtherPlatform); if (NewAttr) D->addAttr(NewAttr); } @@ -2563,38 +2469,34 @@ bool IsGeneratedDeclaration = AL.getArgAsIdent(2) != nullptr; D->addAttr(::new (S.Context) ExternalSourceSymbolAttr( - AL.getRange(), S.Context, Language, DefinedIn, IsGeneratedDeclaration, - AL.getAttributeSpellingListIndex())); + S.Context, AL, Language, DefinedIn, IsGeneratedDeclaration)); } template -static T *mergeVisibilityAttr(Sema &S, Decl *D, SourceRange range, - typename T::VisibilityType value, - unsigned attrSpellingListIndex) { +static T *mergeVisibilityAttr(Sema &S, Decl *D, const AttributeCommonInfo &CI, + typename T::VisibilityType value) { T *existingAttr = D->getAttr(); if (existingAttr) { typename T::VisibilityType existingValue = existingAttr->getVisibility(); if (existingValue == value) return nullptr; S.Diag(existingAttr->getLocation(), diag::err_mismatched_visibility); - S.Diag(range.getBegin(), diag::note_previous_attribute); + S.Diag(CI.getLoc(), diag::note_previous_attribute); D->dropAttr(); } - return ::new (S.Context) T(range, S.Context, value, attrSpellingListIndex); + return ::new (S.Context) T(S.Context, CI, value); } -VisibilityAttr *Sema::mergeVisibilityAttr(Decl *D, SourceRange Range, - VisibilityAttr::VisibilityType Vis, - unsigned AttrSpellingListIndex) { - return ::mergeVisibilityAttr(*this, D, Range, Vis, - AttrSpellingListIndex); +VisibilityAttr *Sema::mergeVisibilityAttr(Decl *D, + const AttributeCommonInfo &CI, + VisibilityAttr::VisibilityType Vis) { + return ::mergeVisibilityAttr(*this, D, CI, Vis); } -TypeVisibilityAttr *Sema::mergeTypeVisibilityAttr(Decl *D, SourceRange Range, - TypeVisibilityAttr::VisibilityType Vis, - unsigned AttrSpellingListIndex) { - return ::mergeVisibilityAttr(*this, D, Range, Vis, - AttrSpellingListIndex); +TypeVisibilityAttr * +Sema::mergeTypeVisibilityAttr(Decl *D, const AttributeCommonInfo &CI, + TypeVisibilityAttr::VisibilityType Vis) { + return ::mergeVisibilityAttr(*this, D, CI, Vis); } static void handleVisibilityAttr(Sema &S, Decl *D, const ParsedAttr &AL, @@ -2636,14 +2538,12 @@ type = VisibilityAttr::Default; } - unsigned Index = AL.getAttributeSpellingListIndex(); Attr *newAttr; if (isTypeVisibility) { - newAttr = S.mergeTypeVisibilityAttr(D, AL.getRange(), - (TypeVisibilityAttr::VisibilityType) type, - Index); + newAttr = S.mergeTypeVisibilityAttr( + D, AL, (TypeVisibilityAttr::VisibilityType)type); } else { - newAttr = S.mergeVisibilityAttr(D, AL.getRange(), type, Index); + newAttr = S.mergeVisibilityAttr(D, AL, type); } if (newAttr) D->addAttr(newAttr); @@ -2672,8 +2572,7 @@ return; } - D->addAttr(new (S.Context) ObjCMethodFamilyAttr( - AL.getRange(), S.Context, F, AL.getAttributeSpellingListIndex())); + D->addAttr(new (S.Context) ObjCMethodFamilyAttr(S.Context, AL, F)); } static void handleObjCNSObject(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -2700,9 +2599,7 @@ // case. S.Diag(D->getLocation(), diag::warn_nsobject_attribute); } - D->addAttr(::new (S.Context) - ObjCNSObjectAttr(AL.getRange(), S.Context, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) ObjCNSObjectAttr(S.Context, AL)); } static void handleObjCIndependentClass(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -2716,9 +2613,7 @@ S.Diag(D->getLocation(), diag::warn_independentclass_attribute); return; } - D->addAttr(::new (S.Context) - ObjCIndependentClassAttr(AL.getRange(), S.Context, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) ObjCIndependentClassAttr(S.Context, AL)); } static void handleBlocksAttr(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -2735,9 +2630,7 @@ return; } - D->addAttr(::new (S.Context) - BlocksAttr(AL.getRange(), S.Context, type, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) BlocksAttr(S.Context, AL, type)); } static void handleSentinelAttr(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -2824,9 +2717,7 @@ << AL << ExpectedFunctionMethodOrBlock; return; } - D->addAttr(::new (S.Context) - SentinelAttr(AL.getRange(), S.Context, sentinel, nullPos, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) SentinelAttr(S.Context, AL, sentinel, nullPos)); } static void handleWarnUnusedResult(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -2864,9 +2755,7 @@ S.Diag(AL.getLoc(), diag::ext_cxx17_attr) << AL; } - D->addAttr(::new (S.Context) - WarnUnusedResultAttr(AL.getRange(), S.Context, Str, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) WarnUnusedResultAttr(S.Context, AL, Str)); } static void handleWeakImportAttr(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -2887,9 +2776,7 @@ return; } - D->addAttr(::new (S.Context) - WeakImportAttr(AL.getRange(), S.Context, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) WeakImportAttr(S.Context, AL)); } // Handles reqd_work_group_size and work_group_size_hint. @@ -2914,9 +2801,8 @@ Existing->getZDim() == WGSize[2])) S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL; - D->addAttr(::new (S.Context) WorkGroupAttr(AL.getRange(), S.Context, - WGSize[0], WGSize[1], WGSize[2], - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) + WorkGroupAttr(S.Context, AL, WGSize[0], WGSize[1], WGSize[2])); } // Handles intel_reqd_sub_group_size. @@ -2936,9 +2822,8 @@ if (Existing && Existing->getSubGroupSize() != SGSize) S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL; - D->addAttr(::new (S.Context) OpenCLIntelReqdSubGroupSizeAttr( - AL.getRange(), S.Context, SGSize, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) + OpenCLIntelReqdSubGroupSizeAttr(S.Context, AL, SGSize)); } static void handleVecTypeHint(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -2965,18 +2850,15 @@ } } - D->addAttr(::new (S.Context) VecTypeHintAttr(AL.getLoc(), S.Context, - ParmTSI, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) VecTypeHintAttr(S.Context, AL, ParmTSI)); } -SectionAttr *Sema::mergeSectionAttr(Decl *D, SourceRange Range, - StringRef Name, - unsigned AttrSpellingListIndex) { +SectionAttr *Sema::mergeSectionAttr(Decl *D, const AttributeCommonInfo &CI, + StringRef Name) { // Explicit or partial specializations do not inherit // the section attribute from the primary template. if (const auto *FD = dyn_cast(D)) { - if (AttrSpellingListIndex == SectionAttr::Declspec_allocate && + if (CI.getAttributeSpellingListIndex() == SectionAttr::Declspec_allocate && FD->isFunctionTemplateSpecialization()) return nullptr; } @@ -2985,11 +2867,10 @@ return nullptr; Diag(ExistingAttr->getLocation(), diag::warn_mismatched_section) << 1 /*section*/; - Diag(Range.getBegin(), diag::note_previous_attribute); + Diag(CI.getLoc(), diag::note_previous_attribute); return nullptr; } - return ::new (Context) SectionAttr(Range, Context, Name, - AttrSpellingListIndex); + return ::new (Context) SectionAttr(Context, CI, Name); } bool Sema::checkSectionName(SourceLocation LiteralLoc, StringRef SecName) { @@ -3021,8 +2902,7 @@ return; } - unsigned Index = AL.getAttributeSpellingListIndex(); - SectionAttr *NewAttr = S.mergeSectionAttr(D, AL.getRange(), Str, Index); + SectionAttr *NewAttr = S.mergeSectionAttr(D, AL, Str); if (NewAttr) D->addAttr(NewAttr); } @@ -3042,9 +2922,8 @@ return true; } -CodeSegAttr *Sema::mergeCodeSegAttr(Decl *D, SourceRange Range, - StringRef Name, - unsigned AttrSpellingListIndex) { +CodeSegAttr *Sema::mergeCodeSegAttr(Decl *D, const AttributeCommonInfo &CI, + StringRef Name) { // Explicit or partial specializations do not inherit // the code_seg attribute from the primary template. if (const auto *FD = dyn_cast(D)) { @@ -3056,11 +2935,10 @@ return nullptr; Diag(ExistingAttr->getLocation(), diag::warn_mismatched_section) << 0 /*codeseg*/; - Diag(Range.getBegin(), diag::note_previous_attribute); + Diag(CI.getLoc(), diag::note_previous_attribute); return nullptr; } - return ::new (Context) CodeSegAttr(Range, Context, Name, - AttrSpellingListIndex); + return ::new (Context) CodeSegAttr(Context, CI, Name); } static void handleCodeSegAttr(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -3080,8 +2958,7 @@ } D->dropAttr(); } - if (CodeSegAttr *CSA = S.mergeCodeSegAttr(D, AL.getRange(), Str, - AL.getAttributeSpellingListIndex())) + if (CodeSegAttr *CSA = S.mergeCodeSegAttr(D, AL, Str)) D->addAttr(CSA); } @@ -3123,9 +3000,7 @@ S.checkTargetAttr(LiteralLoc, Str)) return; - unsigned Index = AL.getAttributeSpellingListIndex(); - TargetAttr *NewAttr = - ::new (S.Context) TargetAttr(AL.getRange(), S.Context, Str, Index); + TargetAttr *NewAttr = ::new (S.Context) TargetAttr(S.Context, AL, Str); D->addAttr(NewAttr); } @@ -3143,9 +3018,7 @@ return; } - D->addAttr(::new (S.Context) - MinVectorWidthAttr(AL.getRange(), S.Context, VecWidth, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) MinVectorWidthAttr(S.Context, AL, VecWidth)); } static void handleCleanupAttr(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -3200,9 +3073,7 @@ return; } - D->addAttr(::new (S.Context) - CleanupAttr(AL.getRange(), S.Context, FD, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) CleanupAttr(S.Context, AL, FD)); } static void handleEnumExtensibilityAttr(Sema &S, Decl *D, @@ -3221,9 +3092,8 @@ return; } - D->addAttr(::new (S.Context) EnumExtensibilityAttr( - AL.getRange(), S.Context, ExtensibilityKind, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) + EnumExtensibilityAttr(S.Context, AL, ExtensibilityKind)); } /// Handle __attribute__((format_arg((idx)))) attribute based on @@ -3258,8 +3128,7 @@ return; } - D->addAttr(::new (S.Context) FormatArgAttr( - AL.getRange(), S.Context, Idx, AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) FormatArgAttr(S.Context, AL, Idx)); } enum FormatAttrKind { @@ -3327,15 +3196,12 @@ AL.setInvalid(); return; } - D->addAttr(::new (S.Context) - InitPriorityAttr(AL.getRange(), S.Context, prioritynum, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) InitPriorityAttr(S.Context, AL, prioritynum)); } -FormatAttr *Sema::mergeFormatAttr(Decl *D, SourceRange Range, +FormatAttr *Sema::mergeFormatAttr(Decl *D, const AttributeCommonInfo &CI, IdentifierInfo *Format, int FormatIdx, - int FirstArg, - unsigned AttrSpellingListIndex) { + int FirstArg) { // Check whether we already have an equivalent format attribute. for (auto *F : D->specific_attrs()) { if (F->getType() == Format && @@ -3344,13 +3210,12 @@ // If we don't have a valid location for this attribute, adopt the // location. if (F->getLocation().isInvalid()) - F->setRange(Range); + F->setRange(CI.getRange()); return nullptr; } } - return ::new (Context) FormatAttr(Range, Context, Format, FormatIdx, - FirstArg, AttrSpellingListIndex); + return ::new (Context) FormatAttr(Context, CI, Format, FormatIdx, FirstArg); } /// Handle __attribute__((format(type,idx,firstarg))) attributes based on @@ -3470,9 +3335,7 @@ return; } - FormatAttr *NewAttr = S.mergeFormatAttr(D, AL.getRange(), II, - Idx, FirstArg, - AL.getAttributeSpellingListIndex()); + FormatAttr *NewAttr = S.mergeFormatAttr(D, AL, II, Idx, FirstArg); if (NewAttr) D->addAttr(NewAttr); } @@ -3613,8 +3476,7 @@ } D->addAttr(::new (S.Context) CallbackAttr( - AL.getRange(), S.Context, EncodingIndices.data(), EncodingIndices.size(), - AL.getAttributeSpellingListIndex())); + S.Context, AL, EncodingIndices.data(), EncodingIndices.size())); } static void handleTransparentUnionAttr(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -3685,9 +3547,7 @@ } } - RD->addAttr(::new (S.Context) - TransparentUnionAttr(AL.getRange(), S.Context, - AL.getAttributeSpellingListIndex())); + RD->addAttr(::new (S.Context) TransparentUnionAttr(S.Context, AL)); } static void handleAnnotateAttr(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -3703,20 +3563,16 @@ return; } - D->addAttr(::new (S.Context) - AnnotateAttr(AL.getRange(), S.Context, Str, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) AnnotateAttr(S.Context, AL, Str)); } static void handleAlignValueAttr(Sema &S, Decl *D, const ParsedAttr &AL) { - S.AddAlignValueAttr(AL.getRange(), D, AL.getArgAsExpr(0), - AL.getAttributeSpellingListIndex()); + S.AddAlignValueAttr(D, AL, AL.getArgAsExpr(0)); } -void Sema::AddAlignValueAttr(SourceRange AttrRange, Decl *D, Expr *E, - unsigned SpellingListIndex) { - AlignValueAttr TmpAttr(AttrRange, Context, E, SpellingListIndex); - SourceLocation AttrLoc = AttrRange.getBegin(); +void Sema::AddAlignValueAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E) { + AlignValueAttr TmpAttr(Context, CI, E); + SourceLocation AttrLoc = CI.getLoc(); QualType T; if (const auto *TD = dyn_cast(D)) @@ -3748,14 +3604,12 @@ return; } - D->addAttr(::new (Context) - AlignValueAttr(AttrRange, Context, ICE.get(), - SpellingListIndex)); + D->addAttr(::new (Context) AlignValueAttr(Context, CI, ICE.get())); return; } // Save dependent expressions in the AST to be instantiated. - D->addAttr(::new (Context) AlignValueAttr(TmpAttr)); + D->addAttr(::new (Context) AlignValueAttr(Context, CI, E)); } static void handleAlignedAttr(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -3766,8 +3620,7 @@ } if (AL.getNumArgs() == 0) { - D->addAttr(::new (S.Context) AlignedAttr(AL.getRange(), S.Context, - true, nullptr, AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) AlignedAttr(S.Context, AL, true, nullptr)); return; } @@ -3781,14 +3634,13 @@ if (!AL.isPackExpansion() && S.DiagnoseUnexpandedParameterPack(E)) return; - S.AddAlignedAttr(AL.getRange(), D, E, AL.getAttributeSpellingListIndex(), - AL.isPackExpansion()); + S.AddAlignedAttr(D, AL, E, AL.isPackExpansion()); } -void Sema::AddAlignedAttr(SourceRange AttrRange, Decl *D, Expr *E, - unsigned SpellingListIndex, bool IsPackExpansion) { - AlignedAttr TmpAttr(AttrRange, Context, true, E, SpellingListIndex); - SourceLocation AttrLoc = AttrRange.getBegin(); +void Sema::AddAlignedAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E, + bool IsPackExpansion) { + AlignedAttr TmpAttr(Context, CI, true, E); + SourceLocation AttrLoc = CI.getLoc(); // C++11 alignas(...) and C11 _Alignas(...) have additional requirements. if (TmpAttr.isAlignas()) { @@ -3840,7 +3692,7 @@ } // Save dependent expressions in the AST to be instantiated. - AlignedAttr *AA = ::new (Context) AlignedAttr(TmpAttr); + AlignedAttr *AA = ::new (Context) AlignedAttr(Context, CI, true, E); AA->setPackExpansion(IsPackExpansion); D->addAttr(AA); return; @@ -3893,18 +3745,16 @@ } } - AlignedAttr *AA = ::new (Context) AlignedAttr(AttrRange, Context, true, - ICE.get(), SpellingListIndex); + AlignedAttr *AA = ::new (Context) AlignedAttr(Context, CI, true, ICE.get()); AA->setPackExpansion(IsPackExpansion); D->addAttr(AA); } -void Sema::AddAlignedAttr(SourceRange AttrRange, Decl *D, TypeSourceInfo *TS, - unsigned SpellingListIndex, bool IsPackExpansion) { +void Sema::AddAlignedAttr(Decl *D, const AttributeCommonInfo &CI, + TypeSourceInfo *TS, bool IsPackExpansion) { // FIXME: Cache the number on the AL object if non-dependent? // FIXME: Perform checking of type validity - AlignedAttr *AA = ::new (Context) AlignedAttr(AttrRange, Context, false, TS, - SpellingListIndex); + AlignedAttr *AA = ::new (Context) AlignedAttr(Context, CI, false, TS); AA->setPackExpansion(IsPackExpansion); D->addAttr(AA); } @@ -4048,14 +3898,14 @@ IdentifierInfo *Name = AL.getArgAsIdent(0)->Ident; - S.AddModeAttr(AL.getRange(), D, Name, AL.getAttributeSpellingListIndex()); + S.AddModeAttr(D, AL, Name); } -void Sema::AddModeAttr(SourceRange AttrRange, Decl *D, IdentifierInfo *Name, - unsigned SpellingListIndex, bool InInstantiation) { +void Sema::AddModeAttr(Decl *D, const AttributeCommonInfo &CI, + IdentifierInfo *Name, bool InInstantiation) { StringRef Str = Name->getName(); normalizeName(Str); - SourceLocation AttrLoc = AttrRange.getBegin(); + SourceLocation AttrLoc = CI.getLoc(); unsigned DestWidth = 0; bool IntegerMode = true; @@ -4106,8 +3956,7 @@ OldTy = cast(D)->getType(); if (OldTy->isDependentType()) { - D->addAttr(::new (Context) - ModeAttr(AttrRange, Context, Name, SpellingListIndex)); + D->addAttr(::new (Context) ModeAttr(Context, CI, Name)); return; } @@ -4122,7 +3971,7 @@ // type, 'enum { A } __attribute__((mode(V4SI)))' is rejected. if ((isa(D) || OldElemTy->getAs()) && VectorSize.getBoolValue()) { - Diag(AttrLoc, diag::err_enum_mode_vector_type) << Name << AttrRange; + Diag(AttrLoc, diag::err_enum_mode_vector_type) << Name << CI.getRange(); return; } bool IntegralOrAnyEnumType = @@ -4189,21 +4038,18 @@ else cast(D)->setType(NewTy); - D->addAttr(::new (Context) - ModeAttr(AttrRange, Context, Name, SpellingListIndex)); + D->addAttr(::new (Context) ModeAttr(Context, CI, Name)); } static void handleNoDebugAttr(Sema &S, Decl *D, const ParsedAttr &AL) { - D->addAttr(::new (S.Context) - NoDebugAttr(AL.getRange(), S.Context, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) NoDebugAttr(S.Context, AL)); } -AlwaysInlineAttr *Sema::mergeAlwaysInlineAttr(Decl *D, SourceRange Range, - IdentifierInfo *Ident, - unsigned AttrSpellingListIndex) { +AlwaysInlineAttr *Sema::mergeAlwaysInlineAttr(Decl *D, + const AttributeCommonInfo &CI, + const IdentifierInfo *Ident) { if (OptimizeNoneAttr *Optnone = D->getAttr()) { - Diag(Range.getBegin(), diag::warn_attribute_ignored) << Ident; + Diag(CI.getLoc(), diag::warn_attribute_ignored) << Ident; Diag(Optnone->getLocation(), diag::note_conflicting_attribute); return nullptr; } @@ -4211,24 +4057,21 @@ if (D->hasAttr()) return nullptr; - return ::new (Context) AlwaysInlineAttr(Range, Context, - AttrSpellingListIndex); + return ::new (Context) AlwaysInlineAttr(Context, CI); } CommonAttr *Sema::mergeCommonAttr(Decl *D, const ParsedAttr &AL) { if (checkAttrMutualExclusion(*this, D, AL)) return nullptr; - return ::new (Context) - CommonAttr(AL.getRange(), Context, AL.getAttributeSpellingListIndex()); + return ::new (Context) CommonAttr(Context, AL); } CommonAttr *Sema::mergeCommonAttr(Decl *D, const CommonAttr &AL) { if (checkAttrMutualExclusion(*this, D, AL)) return nullptr; - return ::new (Context) - CommonAttr(AL.getRange(), Context, AL.getSpellingListIndex()); + return ::new (Context) CommonAttr(Context, AL); } InternalLinkageAttr *Sema::mergeInternalLinkageAttr(Decl *D, @@ -4252,8 +4095,7 @@ if (checkAttrMutualExclusion(*this, D, AL)) return nullptr; - return ::new (Context) InternalLinkageAttr( - AL.getRange(), Context, AL.getAttributeSpellingListIndex()); + return ::new (Context) InternalLinkageAttr(Context, AL); } InternalLinkageAttr * Sema::mergeInternalLinkageAttr(Decl *D, const InternalLinkageAttr &AL) { @@ -4276,14 +4118,12 @@ if (checkAttrMutualExclusion(*this, D, AL)) return nullptr; - return ::new (Context) - InternalLinkageAttr(AL.getRange(), Context, AL.getSpellingListIndex()); + return ::new (Context) InternalLinkageAttr(Context, AL); } -MinSizeAttr *Sema::mergeMinSizeAttr(Decl *D, SourceRange Range, - unsigned AttrSpellingListIndex) { +MinSizeAttr *Sema::mergeMinSizeAttr(Decl *D, const AttributeCommonInfo &CI) { if (OptimizeNoneAttr *Optnone = D->getAttr()) { - Diag(Range.getBegin(), diag::warn_attribute_ignored) << "'minsize'"; + Diag(CI.getLoc(), diag::warn_attribute_ignored) << "'minsize'"; Diag(Optnone->getLocation(), diag::note_conflicting_attribute); return nullptr; } @@ -4291,7 +4131,7 @@ if (D->hasAttr()) return nullptr; - return ::new (Context) MinSizeAttr(Range, Context, AttrSpellingListIndex); + return ::new (Context) MinSizeAttr(Context, CI); } NoSpeculativeLoadHardeningAttr *Sema::mergeNoSpeculativeLoadHardeningAttr( @@ -4299,28 +4139,26 @@ if (checkAttrMutualExclusion(*this, D, AL)) return nullptr; - return ::new (Context) NoSpeculativeLoadHardeningAttr( - AL.getRange(), Context, AL.getSpellingListIndex()); + return ::new (Context) NoSpeculativeLoadHardeningAttr(Context, AL); } -OptimizeNoneAttr *Sema::mergeOptimizeNoneAttr(Decl *D, SourceRange Range, - unsigned AttrSpellingListIndex) { +OptimizeNoneAttr *Sema::mergeOptimizeNoneAttr(Decl *D, + const AttributeCommonInfo &CI) { if (AlwaysInlineAttr *Inline = D->getAttr()) { Diag(Inline->getLocation(), diag::warn_attribute_ignored) << Inline; - Diag(Range.getBegin(), diag::note_conflicting_attribute); + Diag(CI.getLoc(), diag::note_conflicting_attribute); D->dropAttr(); } if (MinSizeAttr *MinSize = D->getAttr()) { Diag(MinSize->getLocation(), diag::warn_attribute_ignored) << MinSize; - Diag(Range.getBegin(), diag::note_conflicting_attribute); + Diag(CI.getLoc(), diag::note_conflicting_attribute); D->dropAttr(); } if (D->hasAttr()) return nullptr; - return ::new (Context) OptimizeNoneAttr(Range, Context, - AttrSpellingListIndex); + return ::new (Context) OptimizeNoneAttr(Context, CI); } SpeculativeLoadHardeningAttr *Sema::mergeSpeculativeLoadHardeningAttr( @@ -4328,29 +4166,25 @@ if (checkAttrMutualExclusion(*this, D, AL)) return nullptr; - return ::new (Context) SpeculativeLoadHardeningAttr( - AL.getRange(), Context, AL.getSpellingListIndex()); + return ::new (Context) SpeculativeLoadHardeningAttr(Context, AL); } static void handleAlwaysInlineAttr(Sema &S, Decl *D, const ParsedAttr &AL) { if (checkAttrMutualExclusion(S, D, AL)) return; - if (AlwaysInlineAttr *Inline = S.mergeAlwaysInlineAttr( - D, AL.getRange(), AL.getName(), - AL.getAttributeSpellingListIndex())) + if (AlwaysInlineAttr *Inline = + S.mergeAlwaysInlineAttr(D, AL, AL.getAttrName())) D->addAttr(Inline); } static void handleMinSizeAttr(Sema &S, Decl *D, const ParsedAttr &AL) { - if (MinSizeAttr *MinSize = S.mergeMinSizeAttr( - D, AL.getRange(), AL.getAttributeSpellingListIndex())) + if (MinSizeAttr *MinSize = S.mergeMinSizeAttr(D, AL)) D->addAttr(MinSize); } static void handleOptimizeNoneAttr(Sema &S, Decl *D, const ParsedAttr &AL) { - if (OptimizeNoneAttr *Optnone = S.mergeOptimizeNoneAttr( - D, AL.getRange(), AL.getAttributeSpellingListIndex())) + if (OptimizeNoneAttr *Optnone = S.mergeOptimizeNoneAttr(D, AL)) D->addAttr(Optnone); } @@ -4362,8 +4196,7 @@ S.Diag(AL.getLoc(), diag::err_cuda_nonglobal_constant); return; } - D->addAttr(::new (S.Context) CUDAConstantAttr( - AL.getRange(), S.Context, AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) CUDAConstantAttr(S.Context, AL)); } static void handleSharedAttr(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -4381,8 +4214,7 @@ S.CUDADiagIfHostCode(AL.getLoc(), diag::err_cuda_host_shared) << S.CurrentCUDATarget()) return; - D->addAttr(::new (S.Context) CUDASharedAttr( - AL.getRange(), S.Context, AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) CUDASharedAttr(S.Context, AL)); } static void handleGlobalAttr(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -4411,9 +4243,7 @@ if (FD->isInlineSpecified() && !S.getLangOpts().CUDAIsDevice) S.Diag(FD->getBeginLoc(), diag::warn_kern_is_inline) << FD; - D->addAttr(::new (S.Context) - CUDAGlobalAttr(AL.getRange(), S.Context, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) CUDAGlobalAttr(S.Context, AL)); } static void handleGNUInlineAttr(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -4423,9 +4253,7 @@ return; } - D->addAttr(::new (S.Context) - GNUInlineAttr(AL.getRange(), S.Context, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) GNUInlineAttr(S.Context, AL)); } static void handleCallConvAttr(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -4445,53 +4273,34 @@ switch (AL.getKind()) { case ParsedAttr::AT_FastCall: - D->addAttr(::new (S.Context) - FastCallAttr(AL.getRange(), S.Context, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) FastCallAttr(S.Context, AL)); return; case ParsedAttr::AT_StdCall: - D->addAttr(::new (S.Context) - StdCallAttr(AL.getRange(), S.Context, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) StdCallAttr(S.Context, AL)); return; case ParsedAttr::AT_ThisCall: - D->addAttr(::new (S.Context) - ThisCallAttr(AL.getRange(), S.Context, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) ThisCallAttr(S.Context, AL)); return; case ParsedAttr::AT_CDecl: - D->addAttr(::new (S.Context) - CDeclAttr(AL.getRange(), S.Context, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) CDeclAttr(S.Context, AL)); return; case ParsedAttr::AT_Pascal: - D->addAttr(::new (S.Context) - PascalAttr(AL.getRange(), S.Context, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) PascalAttr(S.Context, AL)); return; case ParsedAttr::AT_SwiftCall: - D->addAttr(::new (S.Context) - SwiftCallAttr(AL.getRange(), S.Context, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) SwiftCallAttr(S.Context, AL)); return; case ParsedAttr::AT_VectorCall: - D->addAttr(::new (S.Context) - VectorCallAttr(AL.getRange(), S.Context, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) VectorCallAttr(S.Context, AL)); return; case ParsedAttr::AT_MSABI: - D->addAttr(::new (S.Context) - MSABIAttr(AL.getRange(), S.Context, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) MSABIAttr(S.Context, AL)); return; case ParsedAttr::AT_SysVABI: - D->addAttr(::new (S.Context) - SysVABIAttr(AL.getRange(), S.Context, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) SysVABIAttr(S.Context, AL)); return; case ParsedAttr::AT_RegCall: - D->addAttr(::new (S.Context) RegCallAttr( - AL.getRange(), S.Context, AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) RegCallAttr(S.Context, AL)); return; case ParsedAttr::AT_Pcs: { PcsAttr::PCSType PCS; @@ -4506,28 +4315,20 @@ llvm_unreachable("unexpected calling convention in pcs attribute"); } - D->addAttr(::new (S.Context) - PcsAttr(AL.getRange(), S.Context, PCS, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) PcsAttr(S.Context, AL, PCS)); return; } case ParsedAttr::AT_AArch64VectorPcs: - D->addAttr(::new(S.Context) - AArch64VectorPcsAttr(AL.getRange(), S.Context, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) AArch64VectorPcsAttr(S.Context, AL)); return; case ParsedAttr::AT_IntelOclBicc: - D->addAttr(::new (S.Context) - IntelOclBiccAttr(AL.getRange(), S.Context, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) IntelOclBiccAttr(S.Context, AL)); return; case ParsedAttr::AT_PreserveMost: - D->addAttr(::new (S.Context) PreserveMostAttr( - AL.getRange(), S.Context, AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) PreserveMostAttr(S.Context, AL)); return; case ParsedAttr::AT_PreserveAll: - D->addAttr(::new (S.Context) PreserveAllAttr( - AL.getRange(), S.Context, AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) PreserveAllAttr(S.Context, AL)); return; default: llvm_unreachable("unexpected attribute kind"); @@ -4549,9 +4350,9 @@ // clang-tidy knows about available rules. DiagnosticIdentifiers.push_back(RuleName); } - D->addAttr(::new (S.Context) SuppressAttr( - AL.getRange(), S.Context, DiagnosticIdentifiers.data(), - DiagnosticIdentifiers.size(), AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) + SuppressAttr(S.Context, AL, DiagnosticIdentifiers.data(), + DiagnosticIdentifiers.size())); } static void handleLifetimeCategoryAttr(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -4593,9 +4394,7 @@ return; } for (Decl *Redecl : D->redecls()) { - Redecl->addAttr(::new (S.Context) - OwnerAttr(AL.getRange(), S.Context, DerefTypeLoc, - AL.getAttributeSpellingListIndex())); + Redecl->addAttr(::new (S.Context) OwnerAttr(S.Context, AL, DerefTypeLoc)); } } else { if (checkAttrMutualExclusion(S, D, AL)) @@ -4613,8 +4412,7 @@ } for (Decl *Redecl : D->redecls()) { Redecl->addAttr(::new (S.Context) - PointerAttr(AL.getRange(), S.Context, DerefTypeLoc, - AL.getAttributeSpellingListIndex())); + PointerAttr(S.Context, AL, DerefTypeLoc)); } } } @@ -4807,21 +4605,15 @@ return isValidSwiftContextType(Ty); } -static void handleParameterABIAttr(Sema &S, Decl *D, const ParsedAttr &Attrs, - ParameterABI Abi) { - S.AddParameterABIAttr(Attrs.getRange(), D, Abi, - Attrs.getAttributeSpellingListIndex()); -} - -void Sema::AddParameterABIAttr(SourceRange range, Decl *D, ParameterABI abi, - unsigned spellingIndex) { +void Sema::AddParameterABIAttr(Decl *D, const AttributeCommonInfo &CI, + ParameterABI abi) { QualType type = cast(D)->getType(); if (auto existingAttr = D->getAttr()) { if (existingAttr->getABI() != abi) { - Diag(range.getBegin(), diag::err_attributes_are_not_compatible) - << getParameterABISpelling(abi) << existingAttr; + Diag(CI.getLoc(), diag::err_attributes_are_not_compatible) + << getParameterABISpelling(abi) << existingAttr; Diag(existingAttr->getLocation(), diag::note_conflicting_attribute); return; } @@ -4833,32 +4625,26 @@ case ParameterABI::SwiftContext: if (!isValidSwiftContextType(type)) { - Diag(range.getBegin(), diag::err_swift_abi_parameter_wrong_type) - << getParameterABISpelling(abi) - << /*pointer to pointer */ 0 << type; + Diag(CI.getLoc(), diag::err_swift_abi_parameter_wrong_type) + << getParameterABISpelling(abi) << /*pointer to pointer */ 0 << type; } - D->addAttr(::new (Context) - SwiftContextAttr(range, Context, spellingIndex)); + D->addAttr(::new (Context) SwiftContextAttr(Context, CI)); return; case ParameterABI::SwiftErrorResult: if (!isValidSwiftErrorResultType(type)) { - Diag(range.getBegin(), diag::err_swift_abi_parameter_wrong_type) - << getParameterABISpelling(abi) - << /*pointer to pointer */ 1 << type; + Diag(CI.getLoc(), diag::err_swift_abi_parameter_wrong_type) + << getParameterABISpelling(abi) << /*pointer to pointer */ 1 << type; } - D->addAttr(::new (Context) - SwiftErrorResultAttr(range, Context, spellingIndex)); + D->addAttr(::new (Context) SwiftErrorResultAttr(Context, CI)); return; case ParameterABI::SwiftIndirectResult: if (!isValidSwiftIndirectResultType(type)) { - Diag(range.getBegin(), diag::err_swift_abi_parameter_wrong_type) - << getParameterABISpelling(abi) - << /*pointer*/ 0 << type; + Diag(CI.getLoc(), diag::err_swift_abi_parameter_wrong_type) + << getParameterABISpelling(abi) << /*pointer*/ 0 << type; } - D->addAttr(::new (Context) - SwiftIndirectResultAttr(range, Context, spellingIndex)); + D->addAttr(::new (Context) SwiftIndirectResultAttr(Context, CI)); return; } llvm_unreachable("bad parameter ABI attribute"); @@ -4941,10 +4727,9 @@ return ValArg.getAs(); } -void Sema::AddLaunchBoundsAttr(SourceRange AttrRange, Decl *D, Expr *MaxThreads, - Expr *MinBlocks, unsigned SpellingListIndex) { - CUDALaunchBoundsAttr TmpAttr(AttrRange, Context, MaxThreads, MinBlocks, - SpellingListIndex); +void Sema::AddLaunchBoundsAttr(Decl *D, const AttributeCommonInfo &CI, + Expr *MaxThreads, Expr *MinBlocks) { + CUDALaunchBoundsAttr TmpAttr(Context, CI, MaxThreads, MinBlocks); MaxThreads = makeLaunchBoundsArgExpr(*this, MaxThreads, TmpAttr, 0); if (MaxThreads == nullptr) return; @@ -4955,8 +4740,8 @@ return; } - D->addAttr(::new (Context) CUDALaunchBoundsAttr( - AttrRange, Context, MaxThreads, MinBlocks, SpellingListIndex)); + D->addAttr(::new (Context) + CUDALaunchBoundsAttr(Context, CI, MaxThreads, MinBlocks)); } static void handleLaunchBoundsAttr(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -4964,9 +4749,8 @@ !checkAttributeAtMostNumArgs(S, AL, 2)) return; - S.AddLaunchBoundsAttr(AL.getRange(), D, AL.getArgAsExpr(0), - AL.getNumArgs() > 1 ? AL.getArgAsExpr(1) : nullptr, - AL.getAttributeSpellingListIndex()); + S.AddLaunchBoundsAttr(D, AL, AL.getArgAsExpr(0), + AL.getNumArgs() > 1 ? AL.getArgAsExpr(1) : nullptr); } static void handleArgumentWithTypeTagAttr(Sema &S, Decl *D, @@ -4987,7 +4771,7 @@ TypeTagIdx)) return; - bool IsPointer = AL.getName()->getName() == "pointer_with_type_tag"; + bool IsPointer = AL.getAttrName()->getName() == "pointer_with_type_tag"; if (IsPointer) { // Ensure that buffer has a pointer type. unsigned ArgumentIdxAST = ArgumentIdx.getASTIndex(); @@ -4997,8 +4781,8 @@ } D->addAttr(::new (S.Context) ArgumentWithTypeTagAttr( - AL.getRange(), S.Context, AL.getArgAsIdent(0)->Ident, ArgumentIdx, - TypeTagIdx, IsPointer, AL.getAttributeSpellingListIndex())); + S.Context, AL, AL.getArgAsIdent(0)->Ident, ArgumentIdx, TypeTagIdx, + IsPointer)); } static void handleTypeTagForDatatypeAttr(Sema &S, Decl *D, @@ -5023,12 +4807,9 @@ S.GetTypeFromParser(AL.getMatchingCType(), &MatchingCTypeLoc); assert(MatchingCTypeLoc && "no type source info for attribute argument"); - D->addAttr(::new (S.Context) - TypeTagForDatatypeAttr(AL.getRange(), S.Context, PointerKind, - MatchingCTypeLoc, - AL.getLayoutCompatible(), - AL.getMustBeNull(), - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) TypeTagForDatatypeAttr( + S.Context, AL, PointerKind, MatchingCTypeLoc, AL.getLayoutCompatible(), + AL.getMustBeNull())); } static void handleXRayLogArgsAttr(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -5040,9 +4821,8 @@ return; // ArgCount isn't a parameter index [0;n), it's a count [1;n] - D->addAttr(::new (S.Context) XRayLogArgsAttr( - AL.getRange(), S.Context, ArgCount.getSourceIndex(), - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) + XRayLogArgsAttr(S.Context, AL, ArgCount.getSourceIndex())); } //===----------------------------------------------------------------------===// @@ -5069,20 +4849,20 @@ return !PT.isNull() && PT->getAsCXXRecordDecl() != nullptr; } -void Sema::AddXConsumedAttr(Decl *D, SourceRange SR, unsigned SpellingIndex, +void Sema::AddXConsumedAttr(Decl *D, const AttributeCommonInfo &CI, RetainOwnershipKind K, bool IsTemplateInstantiation) { ValueDecl *VD = cast(D); switch (K) { case RetainOwnershipKind::OS: handleSimpleAttributeOrDiagnose( - *this, VD, SR, SpellingIndex, isValidSubjectOfOSAttribute(VD->getType()), + *this, VD, CI, isValidSubjectOfOSAttribute(VD->getType()), diag::warn_ns_attribute_wrong_parameter_type, - /*ExtraArgs=*/SR, "os_consumed", /*pointers*/ 1); + /*ExtraArgs=*/CI.getRange(), "os_consumed", /*pointers*/ 1); return; case RetainOwnershipKind::NS: handleSimpleAttributeOrDiagnose( - *this, VD, SR, SpellingIndex, isValidSubjectOfNSAttribute(VD->getType()), + *this, VD, CI, isValidSubjectOfNSAttribute(VD->getType()), // These attributes are normally just advisory, but in ARC, ns_consumed // is significant. Allow non-dependent code to contain inappropriate @@ -5091,14 +4871,13 @@ ((IsTemplateInstantiation && getLangOpts().ObjCAutoRefCount) ? diag::err_ns_attribute_wrong_parameter_type : diag::warn_ns_attribute_wrong_parameter_type), - /*ExtraArgs=*/SR, "ns_consumed", /*objc pointers*/ 0); + /*ExtraArgs=*/CI.getRange(), "ns_consumed", /*objc pointers*/ 0); return; case RetainOwnershipKind::CF: handleSimpleAttributeOrDiagnose( - *this, VD, SR, SpellingIndex, - isValidSubjectOfCFAttribute(VD->getType()), + *this, VD, CI, isValidSubjectOfCFAttribute(VD->getType()), diag::warn_ns_attribute_wrong_parameter_type, - /*ExtraArgs=*/SR, "cf_consumed", /*pointers*/1); + /*ExtraArgs=*/CI.getRange(), "cf_consumed", /*pointers*/ 1); return; } } @@ -5301,8 +5080,7 @@ return; } - D->addAttr(::new (S.Context) ObjCReturnsInnerPointerAttr( - Attrs.getRange(), S.Context, Attrs.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) ObjCReturnsInnerPointerAttr(S.Context, Attrs)); } static void handleObjCRequiresSuperAttr(Sema &S, Decl *D, @@ -5322,8 +5100,7 @@ return; } - D->addAttr(::new (S.Context) ObjCRequiresSuperAttr( - Attrs.getRange(), S.Context, Attrs.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) ObjCRequiresSuperAttr(S.Context, Attrs)); } static void handleObjCBridgeAttr(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -5349,9 +5126,7 @@ } } - D->addAttr(::new (S.Context) - ObjCBridgeAttr(AL.getRange(), S.Context, Parm->Ident, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) ObjCBridgeAttr(S.Context, AL, Parm->Ident)); } static void handleObjCBridgeMutableAttr(Sema &S, Decl *D, @@ -5364,8 +5139,7 @@ } D->addAttr(::new (S.Context) - ObjCBridgeMutableAttr(AL.getRange(), S.Context, Parm->Ident, - AL.getAttributeSpellingListIndex())); + ObjCBridgeMutableAttr(S.Context, AL, Parm->Ident)); } static void handleObjCBridgeRelatedAttr(Sema &S, Decl *D, @@ -5380,10 +5154,8 @@ AL.getArgAsIdent(1) ? AL.getArgAsIdent(1)->Ident : nullptr; IdentifierInfo *InstanceMethod = AL.getArgAsIdent(2) ? AL.getArgAsIdent(2)->Ident : nullptr; - D->addAttr(::new (S.Context) - ObjCBridgeRelatedAttr(AL.getRange(), S.Context, RelatedClass, - ClassMethod, InstanceMethod, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) ObjCBridgeRelatedAttr( + S.Context, AL, RelatedClass, ClassMethod, InstanceMethod)); } static void handleObjCDesignatedInitializer(Sema &S, Decl *D, @@ -5409,9 +5181,7 @@ return; IFace->setHasDesignatedInitializers(); - D->addAttr(::new (S.Context) - ObjCDesignatedInitializerAttr(AL.getRange(), S.Context, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) ObjCDesignatedInitializerAttr(S.Context, AL)); } static void handleObjCRuntimeName(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -5419,9 +5189,7 @@ if (!S.checkStringLiteralArgumentAttr(AL, 0, MetaDataName)) return; D->addAttr(::new (S.Context) - ObjCRuntimeNameAttr(AL.getRange(), S.Context, - MetaDataName, - AL.getAttributeSpellingListIndex())); + ObjCRuntimeNameAttr(S.Context, AL, MetaDataName)); } // When a user wants to use objc_boxable with a union or struct @@ -5438,9 +5206,8 @@ } if (RD) { - ObjCBoxableAttr *BoxableAttr = ::new (S.Context) - ObjCBoxableAttr(AL.getRange(), S.Context, - AL.getAttributeSpellingListIndex()); + ObjCBoxableAttr *BoxableAttr = + ::new (S.Context) ObjCBoxableAttr(S.Context, AL); RD->addAttr(BoxableAttr); if (notify) { // we need to notify ASTReader/ASTWriter about @@ -5494,26 +5261,24 @@ break; } - D->addAttr(::new (S.Context) - ObjCPreciseLifetimeAttr(AL.getRange(), S.Context, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) ObjCPreciseLifetimeAttr(S.Context, AL)); } //===----------------------------------------------------------------------===// // Microsoft specific attribute handlers. //===----------------------------------------------------------------------===// -UuidAttr *Sema::mergeUuidAttr(Decl *D, SourceRange Range, - unsigned AttrSpellingListIndex, StringRef Uuid) { +UuidAttr *Sema::mergeUuidAttr(Decl *D, const AttributeCommonInfo &CI, + StringRef Uuid) { if (const auto *UA = D->getAttr()) { if (UA->getGuid().equals_lower(Uuid)) return nullptr; Diag(UA->getLocation(), diag::err_mismatched_uuid); - Diag(Range.getBegin(), diag::note_previous_uuid); + Diag(CI.getLoc(), diag::note_previous_uuid); D->dropAttr(); } - return ::new (Context) UuidAttr(Range, Context, Uuid, AttrSpellingListIndex); + return ::new (Context) UuidAttr(Context, CI, Uuid); } static void handleUuidAttr(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -5560,8 +5325,7 @@ if (AL.isMicrosoftAttribute()) // Check for [uuid(...)] spelling. S.Diag(AL.getLoc(), diag::warn_atl_uuid_deprecated); - UuidAttr *UA = S.mergeUuidAttr(D, AL.getRange(), - AL.getAttributeSpellingListIndex(), StrRef); + UuidAttr *UA = S.mergeUuidAttr(D, AL, StrRef); if (UA) D->addAttr(UA); } @@ -5573,8 +5337,7 @@ return; } MSInheritanceAttr *IA = S.mergeMSInheritanceAttr( - D, AL.getRange(), /*BestCase=*/true, - AL.getAttributeSpellingListIndex(), + D, AL, /*BestCase=*/true, (MSInheritanceAttr::Spelling)AL.getSemanticSpelling()); if (IA) { D->addAttr(IA); @@ -5596,8 +5359,7 @@ S.Diag(AL.getLoc(), diag::err_thread_non_global) << "__declspec(thread)"; return; } - D->addAttr(::new (S.Context) ThreadAttr(AL.getRange(), S.Context, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) ThreadAttr(S.Context, AL)); } static void handleAbiTagAttr(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -5628,8 +5390,7 @@ Tags.erase(std::unique(Tags.begin(), Tags.end()), Tags.end()); D->addAttr(::new (S.Context) - AbiTagAttr(AL.getRange(), S.Context, Tags.data(), Tags.size(), - AL.getAttributeSpellingListIndex())); + AbiTagAttr(S.Context, AL, Tags.data(), Tags.size())); } static void handleARMInterruptAttr(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -5654,9 +5415,7 @@ return; } - unsigned Index = AL.getAttributeSpellingListIndex(); - D->addAttr(::new (S.Context) - ARMInterruptAttr(AL.getLoc(), S.Context, Kind, Index)); + D->addAttr(::new (S.Context) ARMInterruptAttr(S.Context, AL, Kind)); } static void handleMSP430InterruptAttr(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -5707,9 +5466,7 @@ return; } - D->addAttr(::new (S.Context) - MSP430InterruptAttr(AL.getLoc(), S.Context, Num, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) MSP430InterruptAttr(S.Context, AL, Num)); D->addAttr(UsedAttr::CreateImplicit(S.Context)); } @@ -5765,8 +5522,7 @@ return; } - D->addAttr(::new (S.Context) MipsInterruptAttr( - AL.getLoc(), S.Context, Kind, AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) MipsInterruptAttr(S.Context, AL, Kind)); } static void handleAnyX86InterruptAttr(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -5829,8 +5585,7 @@ << 3 << S.Context.getIntTypeForBitwidth(TypeSize, /*Signed=*/false); return; } - D->addAttr(::new (S.Context) AnyX86InterruptAttr( - AL.getLoc(), S.Context, AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) AnyX86InterruptAttr(S.Context, AL)); D->addAttr(UsedAttr::CreateImplicit(S.Context)); } @@ -5878,9 +5633,8 @@ if (!S.checkStringLiteralArgumentAttr(AL, 0, Str, &ArgLoc)) return; - FD->addAttr(::new (S.Context) WebAssemblyImportModuleAttr( - AL.getRange(), S.Context, Str, - AL.getAttributeSpellingListIndex())); + FD->addAttr(::new (S.Context) + WebAssemblyImportModuleAttr(S.Context, AL, Str)); } static void handleWebAssemblyImportNameAttr(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -5901,9 +5655,7 @@ if (!S.checkStringLiteralArgumentAttr(AL, 0, Str, &ArgLoc)) return; - FD->addAttr(::new (S.Context) WebAssemblyImportNameAttr( - AL.getRange(), S.Context, Str, - AL.getAttributeSpellingListIndex())); + FD->addAttr(::new (S.Context) WebAssemblyImportNameAttr(S.Context, AL, Str)); } static void handleRISCVInterruptAttr(Sema &S, Decl *D, @@ -5961,8 +5713,7 @@ return; } - D->addAttr(::new (S.Context) RISCVInterruptAttr( - AL.getLoc(), S.Context, Kind, AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) RISCVInterruptAttr(S.Context, AL, Kind)); } static void handleInterruptAttr(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -6022,17 +5773,16 @@ return false; } -void Sema::addAMDGPUFlatWorkGroupSizeAttr(SourceRange AttrRange, Decl *D, - Expr *MinExpr, Expr *MaxExpr, - unsigned SpellingListIndex) { - AMDGPUFlatWorkGroupSizeAttr TmpAttr(AttrRange, Context, MinExpr, MaxExpr, - SpellingListIndex); +void Sema::addAMDGPUFlatWorkGroupSizeAttr(Decl *D, + const AttributeCommonInfo &CI, + Expr *MinExpr, Expr *MaxExpr) { + AMDGPUFlatWorkGroupSizeAttr TmpAttr(Context, CI, MinExpr, MaxExpr); if (checkAMDGPUFlatWorkGroupSizeArguments(*this, MinExpr, MaxExpr, TmpAttr)) return; - D->addAttr(::new (Context) AMDGPUFlatWorkGroupSizeAttr( - AttrRange, Context, MinExpr, MaxExpr, SpellingListIndex)); + D->addAttr(::new (Context) + AMDGPUFlatWorkGroupSizeAttr(Context, CI, MinExpr, MaxExpr)); } static void handleAMDGPUFlatWorkGroupSizeAttr(Sema &S, Decl *D, @@ -6040,8 +5790,7 @@ Expr *MinExpr = AL.getArgAsExpr(0); Expr *MaxExpr = AL.getArgAsExpr(1); - S.addAMDGPUFlatWorkGroupSizeAttr(AL.getRange(), D, MinExpr, MaxExpr, - AL.getAttributeSpellingListIndex()); + S.addAMDGPUFlatWorkGroupSizeAttr(D, AL, MinExpr, MaxExpr); } static bool checkAMDGPUWavesPerEUArguments(Sema &S, Expr *MinExpr, @@ -6078,17 +5827,15 @@ return false; } -void Sema::addAMDGPUWavesPerEUAttr(SourceRange AttrRange, Decl *D, - Expr *MinExpr, Expr *MaxExpr, - unsigned SpellingListIndex) { - AMDGPUWavesPerEUAttr TmpAttr(AttrRange, Context, MinExpr, MaxExpr, - SpellingListIndex); +void Sema::addAMDGPUWavesPerEUAttr(Decl *D, const AttributeCommonInfo &CI, + Expr *MinExpr, Expr *MaxExpr) { + AMDGPUWavesPerEUAttr TmpAttr(Context, CI, MinExpr, MaxExpr); if (checkAMDGPUWavesPerEUArguments(*this, MinExpr, MaxExpr, TmpAttr)) return; - D->addAttr(::new (Context) AMDGPUWavesPerEUAttr(AttrRange, Context, MinExpr, - MaxExpr, SpellingListIndex)); + D->addAttr(::new (Context) + AMDGPUWavesPerEUAttr(Context, CI, MinExpr, MaxExpr)); } static void handleAMDGPUWavesPerEUAttr(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -6099,8 +5846,7 @@ Expr *MinExpr = AL.getArgAsExpr(0); Expr *MaxExpr = (AL.getNumArgs() > 1) ? AL.getArgAsExpr(1) : nullptr; - S.addAMDGPUWavesPerEUAttr(AL.getRange(), D, MinExpr, MaxExpr, - AL.getAttributeSpellingListIndex()); + S.addAMDGPUWavesPerEUAttr(D, AL, MinExpr, MaxExpr); } static void handleAMDGPUNumSGPRAttr(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -6109,9 +5855,7 @@ if (!checkUInt32Argument(S, AL, NumSGPRExpr, NumSGPR)) return; - D->addAttr(::new (S.Context) - AMDGPUNumSGPRAttr(AL.getLoc(), S.Context, NumSGPR, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) AMDGPUNumSGPRAttr(S.Context, AL, NumSGPR)); } static void handleAMDGPUNumVGPRAttr(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -6120,9 +5864,7 @@ if (!checkUInt32Argument(S, AL, NumVGPRExpr, NumVGPR)) return; - D->addAttr(::new (S.Context) - AMDGPUNumVGPRAttr(AL.getLoc(), S.Context, NumVGPR, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) AMDGPUNumVGPRAttr(S.Context, AL, NumVGPR)); } static void handleX86ForceAlignArgPointerAttr(Sema &S, Decl *D, @@ -6145,9 +5887,7 @@ return; } - D->addAttr(::new (S.Context) - X86ForceAlignArgPointerAttr(AL.getRange(), S.Context, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) X86ForceAlignArgPointerAttr(S.Context, AL)); } static void handleLayoutVersion(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -6168,26 +5908,24 @@ // have to multiply by 100 now. Version *= 100; - D->addAttr(::new (S.Context) - LayoutVersionAttr(AL.getRange(), S.Context, Version, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) LayoutVersionAttr(S.Context, AL, Version)); } -DLLImportAttr *Sema::mergeDLLImportAttr(Decl *D, SourceRange Range, - unsigned AttrSpellingListIndex) { +DLLImportAttr *Sema::mergeDLLImportAttr(Decl *D, + const AttributeCommonInfo &CI) { if (D->hasAttr()) { - Diag(Range.getBegin(), diag::warn_attribute_ignored) << "'dllimport'"; + Diag(CI.getLoc(), diag::warn_attribute_ignored) << "'dllimport'"; return nullptr; } if (D->hasAttr()) return nullptr; - return ::new (Context) DLLImportAttr(Range, Context, AttrSpellingListIndex); + return ::new (Context) DLLImportAttr(Context, CI); } -DLLExportAttr *Sema::mergeDLLExportAttr(Decl *D, SourceRange Range, - unsigned AttrSpellingListIndex) { +DLLExportAttr *Sema::mergeDLLExportAttr(Decl *D, + const AttributeCommonInfo &CI) { if (DLLImportAttr *Import = D->getAttr()) { Diag(Import->getLocation(), diag::warn_attribute_ignored) << Import; D->dropAttr(); @@ -6196,7 +5934,7 @@ if (D->hasAttr()) return nullptr; - return ::new (Context) DLLExportAttr(Range, Context, AttrSpellingListIndex); + return ::new (Context) DLLExportAttr(Context, CI); } static void handleDLLAttr(Sema &S, Decl *D, const ParsedAttr &A) { @@ -6224,48 +5962,46 @@ } } - unsigned Index = A.getAttributeSpellingListIndex(); Attr *NewAttr = A.getKind() == ParsedAttr::AT_DLLExport - ? (Attr *)S.mergeDLLExportAttr(D, A.getRange(), Index) - : (Attr *)S.mergeDLLImportAttr(D, A.getRange(), Index); + ? (Attr *)S.mergeDLLExportAttr(D, A) + : (Attr *)S.mergeDLLImportAttr(D, A); if (NewAttr) D->addAttr(NewAttr); } MSInheritanceAttr * -Sema::mergeMSInheritanceAttr(Decl *D, SourceRange Range, bool BestCase, - unsigned AttrSpellingListIndex, +Sema::mergeMSInheritanceAttr(Decl *D, const AttributeCommonInfo &CI, + bool BestCase, MSInheritanceAttr::Spelling SemanticSpelling) { if (MSInheritanceAttr *IA = D->getAttr()) { if (IA->getSemanticSpelling() == SemanticSpelling) return nullptr; Diag(IA->getLocation(), diag::err_mismatched_ms_inheritance) << 1 /*previous declaration*/; - Diag(Range.getBegin(), diag::note_previous_ms_inheritance); + Diag(CI.getLoc(), diag::note_previous_ms_inheritance); D->dropAttr(); } auto *RD = cast(D); if (RD->hasDefinition()) { - if (checkMSInheritanceAttrOnDefinition(RD, Range, BestCase, + if (checkMSInheritanceAttrOnDefinition(RD, CI.getRange(), BestCase, SemanticSpelling)) { return nullptr; } } else { if (isa(RD)) { - Diag(Range.getBegin(), diag::warn_ignored_ms_inheritance) + Diag(CI.getLoc(), diag::warn_ignored_ms_inheritance) << 1 /*partial specialization*/; return nullptr; } if (RD->getDescribedClassTemplate()) { - Diag(Range.getBegin(), diag::warn_ignored_ms_inheritance) + Diag(CI.getLoc(), diag::warn_ignored_ms_inheritance) << 0 /*primary template*/; return nullptr; } } - return ::new (Context) - MSInheritanceAttr(Range, Context, BestCase, AttrSpellingListIndex); + return ::new (Context) MSInheritanceAttr(Context, CI, BestCase); } static void handleCapabilityAttr(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -6288,8 +6024,7 @@ if (!N.equals_lower("mutex") && !N.equals_lower("role")) S.Diag(LiteralLoc, diag::warn_invalid_capability_name) << N; - D->addAttr(::new (S.Context) CapabilityAttr(AL.getRange(), S.Context, N, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) CapabilityAttr(S.Context, AL, N)); } static void handleAssertCapabilityAttr(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -6297,9 +6032,8 @@ if (!checkLockFunAttrCommon(S, D, AL, Args)) return; - D->addAttr(::new (S.Context) AssertCapabilityAttr(AL.getRange(), S.Context, - Args.data(), Args.size(), - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) + AssertCapabilityAttr(S.Context, AL, Args.data(), Args.size())); } static void handleAcquireCapabilityAttr(Sema &S, Decl *D, @@ -6308,10 +6042,8 @@ if (!checkLockFunAttrCommon(S, D, AL, Args)) return; - D->addAttr(::new (S.Context) AcquireCapabilityAttr(AL.getRange(), - S.Context, - Args.data(), Args.size(), - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) AcquireCapabilityAttr(S.Context, AL, Args.data(), + Args.size())); } static void handleTryAcquireCapabilityAttr(Sema &S, Decl *D, @@ -6320,12 +6052,8 @@ if (!checkTryLockFunAttrCommon(S, D, AL, Args)) return; - D->addAttr(::new (S.Context) TryAcquireCapabilityAttr(AL.getRange(), - S.Context, - AL.getArgAsExpr(0), - Args.data(), - Args.size(), - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) TryAcquireCapabilityAttr( + S.Context, AL, AL.getArgAsExpr(0), Args.data(), Args.size())); } static void handleReleaseCapabilityAttr(Sema &S, Decl *D, @@ -6334,9 +6062,8 @@ SmallVector Args; checkAttrArgsAreCapabilityObjs(S, D, AL, Args, 0, true); - D->addAttr(::new (S.Context) ReleaseCapabilityAttr( - AL.getRange(), S.Context, Args.data(), Args.size(), - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) ReleaseCapabilityAttr(S.Context, AL, Args.data(), + Args.size())); } static void handleRequiresCapabilityAttr(Sema &S, Decl *D, @@ -6351,8 +6078,7 @@ return; RequiresCapabilityAttr *RCA = ::new (S.Context) - RequiresCapabilityAttr(AL.getRange(), S.Context, Args.data(), - Args.size(), AL.getAttributeSpellingListIndex()); + RequiresCapabilityAttr(S.Context, AL, Args.data(), Args.size()); D->addAttr(RCA); } @@ -6384,9 +6110,7 @@ if (!S.getLangOpts().CPlusPlus14 && AL.isCXX11Attribute() && !AL.isGNUScope()) S.Diag(AL.getLoc(), diag::ext_cxx14_attr) << AL; - D->addAttr(::new (S.Context) - DeprecatedAttr(AL.getRange(), S.Context, Str, Replacement, - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) DeprecatedAttr(S.Context, AL, Str, Replacement)); } static bool isGlobalVar(const Decl *D) { @@ -6417,14 +6141,13 @@ Sanitizers.push_back(SanitizerName); } - D->addAttr(::new (S.Context) NoSanitizeAttr( - AL.getRange(), S.Context, Sanitizers.data(), Sanitizers.size(), - AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) NoSanitizeAttr(S.Context, AL, Sanitizers.data(), + Sanitizers.size())); } static void handleNoSanitizeSpecificAttr(Sema &S, Decl *D, const ParsedAttr &AL) { - StringRef AttrName = AL.getName()->getName(); + StringRef AttrName = AL.getAttrName()->getName(); normalizeName(AttrName); StringRef SanitizerName = llvm::StringSwitch(AttrName) .Case("no_address_safety_analysis", "address") @@ -6447,8 +6170,10 @@ if (AL.isC2xAttribute() || AL.isCXX11Attribute()) TranslatedSpellingIndex = 1; - D->addAttr(::new (S.Context) NoSanitizeAttr( - AL.getRange(), S.Context, &SanitizerName, 1, TranslatedSpellingIndex)); + AttributeCommonInfo Info = AL; + Info.setAttributeSpellingListIndex(TranslatedSpellingIndex); + D->addAttr(::new (S.Context) + NoSanitizeAttr(S.Context, Info, &SanitizerName, 1)); } static void handleInternalLinkageAttr(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -6517,7 +6242,7 @@ if (D->getAttr()->getSemanticSpelling() == AL.getSemanticSpelling()) { S.Diag(AL.getLoc(), diag::warn_duplicate_declspec) - << AL.getName()->getName() << AL.getRange(); + << AL.getAttrName()->getName() << AL.getRange(); } else { S.Diag(AL.getLoc(), diag::err_opencl_multiple_access_qualifiers) << D->getSourceRange(); @@ -6533,7 +6258,7 @@ // qualifier is a compilation error. if (const auto *PDecl = dyn_cast(D)) { const Type *DeclTy = PDecl->getType().getCanonicalType().getTypePtr(); - if (AL.getName()->getName().find("read_write") != StringRef::npos) { + if (AL.getAttrName()->getName().find("read_write") != StringRef::npos) { if ((!S.getLangOpts().OpenCLCPlusPlus && S.getLangOpts().OpenCLVersion < 200) || DeclTy->isPipeType()) { @@ -6545,8 +6270,7 @@ } } - D->addAttr(::new (S.Context) OpenCLAccessAttr( - AL.getRange(), S.Context, AL.getAttributeSpellingListIndex())); + D->addAttr(::new (S.Context) OpenCLAccessAttr(S.Context, AL)); } static void handleDestroyAttr(Sema &S, Decl *D, const ParsedAttr &A) { @@ -6565,9 +6289,7 @@ static void handleUninitializedAttr(Sema &S, Decl *D, const ParsedAttr &AL) { assert(cast(D)->getStorageDuration() == SD_Automatic && "uninitialized is only valid on automatic duration variables"); - unsigned Index = AL.getAttributeSpellingListIndex(); - D->addAttr(::new (S.Context) - UninitializedAttr(AL.getLoc(), S.Context, Index)); + D->addAttr(::new (S.Context) UninitializedAttr(S.Context, AL)); } static bool tryMakeVariablePseudoStrong(Sema &S, VarDecl *VD, @@ -7018,9 +6740,8 @@ case ParsedAttr::AT_CFConsumed: case ParsedAttr::AT_NSConsumed: case ParsedAttr::AT_OSConsumed: - S.AddXConsumedAttr(D, AL.getRange(), AL.getAttributeSpellingListIndex(), - parsedAttrToRetainOwnershipKind(AL), - /*IsTemplateInstantiation=*/false); + S.AddXConsumedAttr(D, AL, parsedAttrToRetainOwnershipKind(AL), + /*IsTemplateInstantiation=*/false); break; case ParsedAttr::AT_NSConsumesSelf: handleSimpleAttribute(S, D, AL); @@ -7239,13 +6960,13 @@ handleOpenCLNoSVMAttr(S, D, AL); break; case ParsedAttr::AT_SwiftContext: - handleParameterABIAttr(S, D, AL, ParameterABI::SwiftContext); + S.AddParameterABIAttr(D, AL, ParameterABI::SwiftContext); break; case ParsedAttr::AT_SwiftErrorResult: - handleParameterABIAttr(S, D, AL, ParameterABI::SwiftErrorResult); + S.AddParameterABIAttr(D, AL, ParameterABI::SwiftErrorResult); break; case ParsedAttr::AT_SwiftIndirectResult: - handleParameterABIAttr(S, D, AL, ParameterABI::SwiftIndirectResult); + S.AddParameterABIAttr(D, AL, ParameterABI::SwiftIndirectResult); break; case ParsedAttr::AT_InternalLinkage: handleInternalLinkageAttr(S, D, AL); @@ -7619,9 +7340,10 @@ if (W.getAlias()) { // clone decl, impersonate __attribute(weak,alias(...)) IdentifierInfo *NDId = ND->getIdentifier(); NamedDecl *NewD = DeclClonePragmaWeak(ND, W.getAlias(), W.getLocation()); - NewD->addAttr(AliasAttr::CreateImplicit(Context, NDId->getName(), - W.getLocation())); - NewD->addAttr(WeakAttr::CreateImplicit(Context, W.getLocation())); + NewD->addAttr( + AliasAttr::CreateImplicit(Context, NDId->getName(), W.getLocation())); + NewD->addAttr(WeakAttr::CreateImplicit(Context, W.getLocation(), + AttributeCommonInfo::AS_Pragma)); WeakTopLevelDecl.push_back(NewD); // FIXME: "hideous" code from Sema::LazilyCreateBuiltin // to insert Decl at TU scope, sorry. @@ -7632,7 +7354,8 @@ PushOnScopeChains(NewD, S); CurContext = SavedContext; } else { // just add weak to existing - ND->addAttr(WeakAttr::CreateImplicit(Context, W.getLocation())); + ND->addAttr(WeakAttr::CreateImplicit(Context, W.getLocation(), + AttributeCommonInfo::AS_Pragma)); } } Index: cfe/trunk/lib/Sema/SemaDeclCXX.cpp =================================================================== --- cfe/trunk/lib/Sema/SemaDeclCXX.cpp +++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp @@ -24,6 +24,7 @@ #include "clang/AST/StmtVisitor.h" #include "clang/AST/TypeLoc.h" #include "clang/AST/TypeOrdering.h" +#include "clang/Basic/AttributeCommonInfo.h" #include "clang/Basic/PartialDiagnostic.h" #include "clang/Basic/TargetInfo.h" #include "clang/Lex/LiteralSupport.h" @@ -2500,7 +2501,7 @@ Diag(AL.getLoc(), AL.getKind() == ParsedAttr::UnknownAttribute ? (unsigned)diag::warn_unknown_attribute_ignored : (unsigned)diag::err_base_specifier_attribute) - << AL.getName(); + << AL; } TypeSourceInfo *TInfo = nullptr; @@ -3344,10 +3345,12 @@ } if (VS.isOverrideSpecified()) - Member->addAttr(new (Context) OverrideAttr(VS.getOverrideLoc(), Context, 0)); + Member->addAttr(OverrideAttr::Create(Context, VS.getOverrideLoc(), + AttributeCommonInfo::AS_Keyword)); if (VS.isFinalSpecified()) - Member->addAttr(new (Context) FinalAttr(VS.getFinalLoc(), Context, - VS.isFinalSpelledSealed())); + Member->addAttr(FinalAttr::Create( + Context, VS.getFinalLoc(), AttributeCommonInfo::AS_Keyword, + static_cast(VS.isFinalSpelledSealed()))); if (VS.getLastLocation().isValid()) { // Update the end location of a method that has a virt-specifiers. @@ -5920,14 +5923,10 @@ TSK != TSK_ExplicitInstantiationDefinition) { if (ClassExported) { NewAttr = ::new (getASTContext()) - DLLExportStaticLocalAttr(ClassAttr->getRange(), - getASTContext(), - ClassAttr->getSpellingListIndex()); + DLLExportStaticLocalAttr(getASTContext(), *ClassAttr); } else { NewAttr = ::new (getASTContext()) - DLLImportStaticLocalAttr(ClassAttr->getRange(), - getASTContext(), - ClassAttr->getSpellingListIndex()); + DLLImportStaticLocalAttr(getASTContext(), *ClassAttr); } } else { NewAttr = cast(ClassAttr->clone(getASTContext())); @@ -8101,8 +8100,7 @@ if (AL.getKind() != ParsedAttr::AT_Visibility) continue; AL.setInvalid(); - Diag(AL.getLoc(), diag::warn_attribute_after_definition_ignored) - << AL.getName(); + Diag(AL.getLoc(), diag::warn_attribute_after_definition_ignored) << AL; } ActOnFields(S, RLoc, TagDecl, llvm::makeArrayRef( Index: cfe/trunk/lib/Sema/SemaObjCProperty.cpp =================================================================== --- cfe/trunk/lib/Sema/SemaObjCProperty.cpp +++ cfe/trunk/lib/Sema/SemaObjCProperty.cpp @@ -2419,9 +2419,9 @@ ObjCReturnsInnerPointerAttr::CreateImplicit(Context, Loc)); if (const SectionAttr *SA = property->getAttr()) - GetterMethod->addAttr( - SectionAttr::CreateImplicit(Context, SectionAttr::GNU_section, - SA->getName(), Loc)); + GetterMethod->addAttr(SectionAttr::CreateImplicit( + Context, SA->getName(), Loc, AttributeCommonInfo::AS_GNU, + SectionAttr::GNU_section)); if (getLangOpts().ObjCAutoRefCount) CheckARCMethodDecl(GetterMethod); @@ -2485,9 +2485,9 @@ CD->addDecl(SetterMethod); if (const SectionAttr *SA = property->getAttr()) - SetterMethod->addAttr( - SectionAttr::CreateImplicit(Context, SectionAttr::GNU_section, - SA->getName(), Loc)); + SetterMethod->addAttr(SectionAttr::CreateImplicit( + Context, SA->getName(), Loc, AttributeCommonInfo::AS_GNU, + 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) Index: cfe/trunk/lib/Sema/SemaOpenMP.cpp =================================================================== --- cfe/trunk/lib/Sema/SemaOpenMP.cpp +++ cfe/trunk/lib/Sema/SemaOpenMP.cpp @@ -3154,7 +3154,8 @@ // function directly. getCurCapturedRegion()->TheCapturedDecl->addAttr( AlwaysInlineAttr::CreateImplicit( - Context, AlwaysInlineAttr::Keyword_forceinline)); + Context, {}, AttributeCommonInfo::AS_Keyword, + AlwaysInlineAttr::Keyword_forceinline)); Sema::CapturedParamNameType ParamsTarget[] = { std::make_pair(StringRef(), QualType()) // __context with shared vars }; @@ -3198,7 +3199,8 @@ // function directly. getCurCapturedRegion()->TheCapturedDecl->addAttr( AlwaysInlineAttr::CreateImplicit( - Context, AlwaysInlineAttr::Keyword_forceinline)); + Context, {}, AttributeCommonInfo::AS_Keyword, + AlwaysInlineAttr::Keyword_forceinline)); ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, std::make_pair(StringRef(), QualType()), /*OpenMPCaptureLevel=*/1); @@ -3250,7 +3252,8 @@ // function directly. getCurCapturedRegion()->TheCapturedDecl->addAttr( AlwaysInlineAttr::CreateImplicit( - Context, AlwaysInlineAttr::Keyword_forceinline)); + Context, {}, AttributeCommonInfo::AS_Keyword, + AlwaysInlineAttr::Keyword_forceinline)); break; } case OMPD_taskloop: @@ -3292,7 +3295,8 @@ // function directly. getCurCapturedRegion()->TheCapturedDecl->addAttr( AlwaysInlineAttr::CreateImplicit( - Context, AlwaysInlineAttr::Keyword_forceinline)); + Context, {}, AttributeCommonInfo::AS_Keyword, + AlwaysInlineAttr::Keyword_forceinline)); break; } case OMPD_distribute_parallel_for_simd: @@ -3338,7 +3342,8 @@ // function directly. getCurCapturedRegion()->TheCapturedDecl->addAttr( AlwaysInlineAttr::CreateImplicit( - Context, AlwaysInlineAttr::Keyword_forceinline)); + Context, {}, AttributeCommonInfo::AS_Keyword, + AlwaysInlineAttr::Keyword_forceinline)); Sema::CapturedParamNameType ParamsTarget[] = { std::make_pair(StringRef(), QualType()) // __context with shared vars }; @@ -3424,7 +3429,8 @@ // function directly. getCurCapturedRegion()->TheCapturedDecl->addAttr( AlwaysInlineAttr::CreateImplicit( - Context, AlwaysInlineAttr::Keyword_forceinline)); + Context, {}, AttributeCommonInfo::AS_Keyword, + AlwaysInlineAttr::Keyword_forceinline)); break; } case OMPD_threadprivate: Index: cfe/trunk/lib/Sema/SemaStmtAttr.cpp =================================================================== --- cfe/trunk/lib/Sema/SemaStmtAttr.cpp +++ cfe/trunk/lib/Sema/SemaStmtAttr.cpp @@ -23,8 +23,7 @@ static Attr *handleFallThroughAttr(Sema &S, Stmt *St, const ParsedAttr &A, SourceRange Range) { - FallThroughAttr Attr(A.getRange(), S.Context, - A.getAttributeSpellingListIndex()); + FallThroughAttr Attr(S.Context, A); if (!isa(St)) { S.Diag(A.getRange().getBegin(), diag::err_fallthrough_attr_wrong_target) << Attr.getSpelling() << St->getBeginLoc(); @@ -45,10 +44,10 @@ // about using it as an extension. if (!S.getLangOpts().CPlusPlus17 && A.isCXX11Attribute() && !A.getScopeName()) - S.Diag(A.getLoc(), diag::ext_cxx17_attr) << A.getName(); + S.Diag(A.getLoc(), diag::ext_cxx17_attr) << A; FnScope->setHasFallthroughStmt(); - return ::new (S.Context) auto(Attr); + return ::new (S.Context) FallThroughAttr(S.Context, A); } static Attr *handleSuppressAttr(Sema &S, Stmt *St, const ParsedAttr &A, @@ -71,8 +70,7 @@ } return ::new (S.Context) SuppressAttr( - A.getRange(), S.Context, DiagnosticIdentifiers.data(), - DiagnosticIdentifiers.size(), A.getAttributeSpellingListIndex()); + S.Context, A, DiagnosticIdentifiers.data(), DiagnosticIdentifiers.size()); } static Attr *handleLoopHintAttr(Sema &S, Stmt *St, const ParsedAttr &A, @@ -97,8 +95,6 @@ return nullptr; } - LoopHintAttr::Spelling Spelling = - LoopHintAttr::Spelling(A.getAttributeSpellingListIndex()); LoopHintAttr::OptionType Option; LoopHintAttr::LoopHintState State; @@ -171,8 +167,7 @@ llvm_unreachable("bad loop hint"); } - return LoopHintAttr::CreateImplicit(S.Context, Spelling, Option, State, - ValueExpr, A.getRange()); + return LoopHintAttr::CreateImplicit(S.Context, Option, State, ValueExpr, A); } static void @@ -330,7 +325,7 @@ S.Diag(A.getLoc(), A.isDeclspecAttribute() ? (unsigned)diag::warn_unhandled_ms_attribute_ignored : (unsigned)diag::warn_unknown_attribute_ignored) - << A.getName(); + << A; return nullptr; case ParsedAttr::AT_FallThrough: return handleFallThroughAttr(S, St, A, Range); @@ -344,7 +339,7 @@ // if we're here, then we parsed a known attribute, but didn't recognize // it as a statement attribute => it is declaration attribute S.Diag(A.getRange().getBegin(), diag::err_decl_attribute_invalid_on_stmt) - << A.getName() << St->getBeginLoc(); + << A << St->getBeginLoc(); return nullptr; } } Index: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp =================================================================== --- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp +++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp @@ -1258,9 +1258,8 @@ // Create new LoopHintValueAttr with integral expression in place of the // non-type template parameter. - return LoopHintAttr::CreateImplicit( - getSema().Context, LH->getSemanticSpelling(), LH->getOption(), - LH->getState(), TransformedExpr, LH->getRange()); + return LoopHintAttr::CreateImplicit(getSema().Context, LH->getOption(), + LH->getState(), TransformedExpr, *LH); } ExprResult TemplateInstantiator::transformNonTypeTemplateParmRef( Index: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp =================================================================== --- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -86,15 +86,13 @@ S, Sema::ExpressionEvaluationContext::ConstantEvaluated); ExprResult Result = S.SubstExpr(Aligned->getAlignmentExpr(), TemplateArgs); if (!Result.isInvalid()) - S.AddAlignedAttr(Aligned->getLocation(), New, Result.getAs(), - Aligned->getSpellingListIndex(), IsPackExpansion); + S.AddAlignedAttr(New, *Aligned, Result.getAs(), IsPackExpansion); } else { TypeSourceInfo *Result = S.SubstType(Aligned->getAlignmentType(), TemplateArgs, Aligned->getLocation(), DeclarationName()); if (Result) - S.AddAlignedAttr(Aligned->getLocation(), New, Result, - Aligned->getSpellingListIndex(), IsPackExpansion); + S.AddAlignedAttr(New, *Aligned, Result, IsPackExpansion); } } @@ -156,8 +154,7 @@ OE = Result.getAs(); } - S.AddAssumeAlignedAttr(Aligned->getLocation(), New, E, OE, - Aligned->getSpellingListIndex()); + S.AddAssumeAlignedAttr(New, *Aligned, E, OE); } static void instantiateDependentAlignValueAttr( @@ -168,8 +165,7 @@ S, Sema::ExpressionEvaluationContext::ConstantEvaluated); ExprResult Result = S.SubstExpr(Aligned->getAlignment(), TemplateArgs); if (!Result.isInvalid()) - S.AddAlignValueAttr(Aligned->getLocation(), New, Result.getAs(), - Aligned->getSpellingListIndex()); + S.AddAlignValueAttr(New, *Aligned, Result.getAs()); } static void instantiateDependentAllocAlignAttr( @@ -179,8 +175,7 @@ S.getASTContext(), llvm::APInt(64, Align->getParamIndex().getSourceIndex()), S.getASTContext().UnsignedLongLongTy, Align->getLocation()); - S.AddAllocAlignAttr(Align->getLocation(), New, Param, - Align->getSpellingListIndex()); + S.AddAllocAlignAttr(New, *Align, Param); } static Expr *instantiateDependentFunctionAttrCondition( @@ -221,9 +216,8 @@ S, TemplateArgs, EIA, EIA->getCond(), Tmpl, New); if (Cond) - New->addAttr(new (S.getASTContext()) EnableIfAttr( - EIA->getLocation(), S.getASTContext(), Cond, EIA->getMessage(), - EIA->getSpellingListIndex())); + New->addAttr(new (S.getASTContext()) EnableIfAttr(S.getASTContext(), *EIA, + Cond, EIA->getMessage())); } static void instantiateDependentDiagnoseIfAttr( @@ -234,9 +228,8 @@ if (Cond) New->addAttr(new (S.getASTContext()) DiagnoseIfAttr( - DIA->getLocation(), S.getASTContext(), Cond, DIA->getMessage(), - DIA->getDiagnosticType(), DIA->getArgDependent(), New, - DIA->getSpellingListIndex())); + S.getASTContext(), *DIA, Cond, DIA->getMessage(), + DIA->getDiagnosticType(), DIA->getArgDependent(), New)); } // Constructs and adds to New a new instance of CUDALaunchBoundsAttr using @@ -261,16 +254,15 @@ MinBlocks = Result.getAs(); } - S.AddLaunchBoundsAttr(Attr.getLocation(), New, MaxThreads, MinBlocks, - Attr.getSpellingListIndex()); + S.AddLaunchBoundsAttr(New, Attr, MaxThreads, MinBlocks); } static void instantiateDependentModeAttr(Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs, const ModeAttr &Attr, Decl *New) { - S.AddModeAttr(Attr.getRange(), New, Attr.getMode(), - Attr.getSpellingListIndex(), /*InInstantiation=*/true); + S.AddModeAttr(New, Attr, Attr.getMode(), + /*InInstantiation=*/true); } /// Instantiation of 'declare simd' attribute and its arguments. @@ -373,8 +365,7 @@ return; Expr *MaxExpr = Result.getAs(); - S.addAMDGPUFlatWorkGroupSizeAttr(Attr.getLocation(), New, MinExpr, MaxExpr, - Attr.getSpellingListIndex()); + S.addAMDGPUFlatWorkGroupSizeAttr(New, Attr, MinExpr, MaxExpr); } static ExplicitSpecifier @@ -420,8 +411,7 @@ MaxExpr = Result.getAs(); } - S.addAMDGPUWavesPerEUAttr(Attr.getLocation(), New, MinExpr, MaxExpr, - Attr.getSpellingListIndex()); + S.addAMDGPUWavesPerEUAttr(New, Attr, MinExpr, MaxExpr); } void Sema::InstantiateAttrsForDecl( @@ -536,16 +526,13 @@ } if (const auto *ABIAttr = dyn_cast(TmplAttr)) { - AddParameterABIAttr(ABIAttr->getRange(), New, ABIAttr->getABI(), - ABIAttr->getSpellingListIndex()); + AddParameterABIAttr(New, *ABIAttr, ABIAttr->getABI()); continue; } if (isa(TmplAttr) || isa(TmplAttr) || isa(TmplAttr)) { - AddXConsumedAttr(New, TmplAttr->getRange(), - TmplAttr->getSpellingListIndex(), - attrToRetainOwnershipKind(TmplAttr), + AddXConsumedAttr(New, *TmplAttr, attrToRetainOwnershipKind(TmplAttr), /*template instantiation=*/true); continue; } Index: cfe/trunk/lib/Sema/SemaType.cpp =================================================================== --- cfe/trunk/lib/Sema/SemaType.cpp +++ cfe/trunk/lib/Sema/SemaType.cpp @@ -82,7 +82,7 @@ } SourceLocation loc = attr.getLoc(); - StringRef name = attr.getName()->getName(); + StringRef name = attr.getAttrName()->getName(); // The GC attributes are usually written with macros; special-case them. IdentifierInfo *II = attr.isArgIdent(0) ? attr.getArgAsIdent(0)->Ident @@ -811,7 +811,7 @@ continue; S.Diag(AL.getLoc(), diag::warn_block_literal_attributes_on_omitted_return_type) - << AL.getName(); + << AL; ToBeRemoved.push_back(&AL); } // Remove bad attributes from the list. @@ -3942,10 +3942,9 @@ } template -static AttrT *createSimpleAttr(ASTContext &Ctx, ParsedAttr &Attr) { - Attr.setUsedAsTypeAttr(); - return ::new (Ctx) - AttrT(Attr.getRange(), Ctx, Attr.getAttributeSpellingListIndex()); +static AttrT *createSimpleAttr(ASTContext &Ctx, ParsedAttr &AL) { + AL.setUsedAsTypeAttr(); + return ::new (Ctx) AttrT(Ctx, AL); } static Attr *createNullabilityAttr(ASTContext &Ctx, ParsedAttr &Attr, @@ -5983,9 +5982,8 @@ } ASTContext &Ctx = S.Context; - auto *ASAttr = ::new (Ctx) - AddressSpaceAttr(Attr.getRange(), Ctx, static_cast(ASIdx), - Attr.getAttributeSpellingListIndex()); + auto *ASAttr = + ::new (Ctx) AddressSpaceAttr(Ctx, Attr, static_cast(ASIdx)); // If the expression is not value dependent (not templated), then we can // apply the address space qualifiers just to the equivalent type. @@ -6082,8 +6080,7 @@ else if (II->isStr("autoreleasing")) lifetime = Qualifiers::OCL_Autoreleasing; else { - S.Diag(AttrLoc, diag::warn_attribute_type_not_supported) - << attr.getName() << II; + S.Diag(AttrLoc, diag::warn_attribute_type_not_supported) << attr << II; attr.setInvalid(); return true; } @@ -6125,7 +6122,7 @@ underlyingType.Quals.addObjCLifetime(lifetime); if (NonObjCPointer) { - StringRef name = attr.getName()->getName(); + StringRef name = attr.getAttrName()->getName(); switch (lifetime) { case Qualifiers::OCL_None: case Qualifiers::OCL_ExplicitNone: @@ -6164,9 +6161,8 @@ // If we have a valid source location for the attribute, use an // AttributedType instead. if (AttrLoc.isValid()) { - type = state.getAttributedType(::new (S.Context) ObjCOwnershipAttr( - attr.getRange(), S.Context, II, - attr.getAttributeSpellingListIndex()), + type = state.getAttributedType(::new (S.Context) + ObjCOwnershipAttr(S.Context, attr, II), origType, type); } @@ -6258,7 +6254,7 @@ GCAttr = Qualifiers::Strong; else { S.Diag(attr.getLoc(), diag::warn_attribute_type_not_supported) - << attr.getName() << II; + << attr << II; attr.setInvalid(); return true; } @@ -6269,9 +6265,7 @@ // Make an attributed type to preserve the source information. if (attr.getLoc().isValid()) type = state.getAttributedType( - ::new (S.Context) ObjCGCAttr(attr.getRange(), S.Context, II, - attr.getAttributeSpellingListIndex()), - origType, type); + ::new (S.Context) ObjCGCAttr(S.Context, attr, II), origType, type); return true; } @@ -6443,8 +6437,7 @@ // You cannot specify duplicate type attributes, so if the attribute has // already been applied, flag it. if (NewAttrKind == CurAttrKind) { - S.Diag(PAttr.getLoc(), diag::warn_duplicate_attribute_exact) - << PAttr.getName(); + S.Diag(PAttr.getLoc(), diag::warn_duplicate_attribute_exact) << PAttr; return true; } @@ -6713,9 +6706,9 @@ if (chunk.Kind != DeclaratorChunk::MemberPointer) { diag << FixItHint::CreateRemoval(attr.getLoc()) << FixItHint::CreateInsertion( - state.getSema().getPreprocessor() - .getLocForEndOfToken(chunk.Loc), - " " + attr.getName()->getName().str() + " "); + state.getSema().getPreprocessor().getLocForEndOfToken( + chunk.Loc), + " " + attr.getAttrName()->getName().str() + " "); } moveAttrFromListToList(attr, state.getCurrentAttributes(), @@ -6793,8 +6786,7 @@ PcsAttr::PCSType Type; if (!PcsAttr::ConvertStrToPCSType(Str, Type)) llvm_unreachable("already validated the attribute"); - return ::new (Ctx) PcsAttr(Attr.getRange(), Ctx, Type, - Attr.getAttributeSpellingListIndex()); + return ::new (Ctx) PcsAttr(Ctx, Attr, Type); } case ParsedAttr::AT_IntelOclBicc: return createSimpleAttr(Ctx, Attr); @@ -7313,7 +7305,7 @@ } else { llvm_unreachable("unexpected type"); } - StringRef AttrName = Attr.getName()->getName(); + StringRef AttrName = Attr.getAttrName()->getName(); if (PrevAccessQual == AttrName.ltrim("_")) { // Duplicated qualifiers S.Diag(Attr.getLoc(), diag::warn_duplicate_declspec) @@ -7510,7 +7502,7 @@ IsTypeAttr ? diag::warn_gcc_ignores_type_attr : diag::warn_cxx11_gnu_attribute_on_type) - << attr.getName(); + << attr; if (!IsTypeAttr) continue; } @@ -7539,7 +7531,7 @@ if (attr.isCXX11Attribute() && TAL == TAL_DeclChunk) state.getSema().Diag(attr.getLoc(), diag::warn_unknown_attribute_ignored) - << attr.getName(); + << attr; break; case ParsedAttr::IgnoredAttribute: @@ -7933,14 +7925,16 @@ break; } - RD->addAttr(MSInheritanceAttr::CreateImplicit( - S.getASTContext(), IM, - /*BestCase=*/S.MSPointerToMemberRepresentationMethod == - LangOptions::PPTMK_BestCase, - S.ImplicitMSInheritanceAttrLoc.isValid() - ? S.ImplicitMSInheritanceAttrLoc - : RD->getSourceRange())); - S.Consumer.AssignInheritanceModel(RD); + SourceRange Loc = + S.ImplicitMSInheritanceAttrLoc.isValid() + ? S.ImplicitMSInheritanceAttrLoc + : RD->getSourceRange(); + RD->addAttr(MSInheritanceAttr::CreateImplicit( + S.getASTContext(), + /*BestCase=*/S.MSPointerToMemberRepresentationMethod == + LangOptions::PPTMK_BestCase, + Loc, AttributeCommonInfo::AS_Microsoft, IM)); + S.Consumer.AssignInheritanceModel(RD); } } Index: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp =================================================================== --- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp +++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp @@ -2748,6 +2748,10 @@ return Reader->ReadSourceRange(*F, Record, Idx); } + SourceLocation readSourceLocation() { + return Reader->ReadSourceLocation(*F, Record, Idx); + } + Expr *readExpr() { return Reader->ReadExpr(*F); } std::string readString() { @@ -2783,9 +2787,20 @@ // Kind is stored as a 1-based integer because 0 is used to indicate a null // Attr pointer. auto Kind = static_cast(V - 1); - SourceRange Range = Record.readSourceRange(); ASTContext &Context = getContext(); + IdentifierInfo *AttrName = Record.getIdentifierInfo(); + IdentifierInfo *ScopeName = Record.getIdentifierInfo(); + SourceRange AttrRange = Record.readSourceRange(); + SourceLocation ScopeLoc = Record.readSourceLocation(); + unsigned ParsedKind = Record.readInt(); + unsigned Syntax = Record.readInt(); + unsigned SpellingIndex = Record.readInt(); + + AttributeCommonInfo Info(AttrName, ScopeName, AttrRange, ScopeLoc, + AttributeCommonInfo::Kind(ParsedKind), + AttributeCommonInfo::Syntax(Syntax), SpellingIndex); + #include "clang/Serialization/AttrPCHRead.inc" assert(New && "Unable to decode attribute?"); @@ -4551,8 +4566,9 @@ break; case UPD_DECL_MARKED_OPENMP_THREADPRIVATE: - D->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit(Reader.getContext(), - ReadSourceRange())); + D->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit( + Reader.getContext(), ReadSourceRange(), + AttributeCommonInfo::AS_Pragma)); break; case UPD_DECL_MARKED_OPENMP_ALLOCATE: { @@ -4561,7 +4577,8 @@ Expr *Allocator = Record.readExpr(); SourceRange SR = ReadSourceRange(); D->addAttr(OMPAllocateDeclAttr::CreateImplicit( - Reader.getContext(), AllocatorKind, Allocator, SR)); + Reader.getContext(), AllocatorKind, Allocator, SR, + AttributeCommonInfo::AS_Pragma)); break; } @@ -4580,7 +4597,8 @@ OMPDeclareTargetDeclAttr::DevTypeTy DevType = static_cast(Record.readInt()); D->addAttr(OMPDeclareTargetDeclAttr::CreateImplicit( - Reader.getContext(), MapType, DevType, ReadSourceRange())); + Reader.getContext(), MapType, DevType, ReadSourceRange(), + AttributeCommonInfo::AS_Pragma)); break; } Index: cfe/trunk/lib/Serialization/ASTWriter.cpp =================================================================== --- cfe/trunk/lib/Serialization/ASTWriter.cpp +++ cfe/trunk/lib/Serialization/ASTWriter.cpp @@ -4522,7 +4522,14 @@ if (!A) return Record.push_back(0); Record.push_back(A->getKind() + 1); // FIXME: stable encoding, target attrs + + Record.AddIdentifierRef(A->getAttrName()); + Record.AddIdentifierRef(A->getScopeName()); Record.AddSourceRange(A->getRange()); + Record.AddSourceLocation(A->getScopeLoc()); + Record.push_back(A->getParsedKind()); + Record.push_back(A->getSyntax()); + Record.push_back(A->getAttributeSpellingListIndexRaw()); #include "clang/Serialization/AttrPCHWrite.inc" } Index: cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp =================================================================== --- cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp +++ cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp @@ -1347,7 +1347,7 @@ return; } - OS << " switch (SpellingListIndex) {\n" + OS << " switch (getAttributeSpellingListIndex()) {\n" " default:\n" " llvm_unreachable(\"Unknown attribute spelling!\");\n" " return \"(No spelling)\";\n"; @@ -1375,11 +1375,10 @@ return; } - OS << - " switch (SpellingListIndex) {\n" - " default:\n" - " llvm_unreachable(\"Unknown attribute spelling!\");\n" - " break;\n"; + OS << " switch (getAttributeSpellingListIndex()) {\n" + " default:\n" + " llvm_unreachable(\"Unknown attribute spelling!\");\n" + " break;\n"; for (unsigned I = 0; I < Spellings.size(); ++ I) { llvm::SmallString<16> Prefix; @@ -1560,11 +1559,12 @@ const StringRef Name = Accessor->getValueAsString("Name"); std::vector Spellings = GetFlattenedSpellings(*Accessor); - OS << " bool " << Name << "() const { return SpellingListIndex == "; + OS << " bool " << Name + << "() const { return getAttributeSpellingListIndex() == "; for (unsigned Index = 0; Index < Spellings.size(); ++Index) { OS << getSpellingListIndex(SpellingList, Spellings[Index]); if (Index != Spellings.size() - 1) - OS << " ||\n SpellingListIndex == "; + OS << " ||\n getAttributeSpellingListIndex() == "; else OS << "; }\n"; } @@ -2221,6 +2221,7 @@ OS << "#define LLVM_CLANG_ATTR_CLASSES_INC\n\n"; std::vector Attrs = Records.getAllDerivedDefinitions("Attr"); + ParsedAttrMap AttrMap = getParsedAttrList(Records); for (const auto *Attr : Attrs) { const Record &R = *Attr; @@ -2289,38 +2290,97 @@ if (!ElideSpelling) OS << CreateSemanticSpellings(Spellings, SemanticToSyntacticMap); + const auto &ParsedAttrSpellingItr = llvm::find_if( + AttrMap, [R](const std::pair &P) { + return &R == P.second; + }); + // Emit CreateImplicit factory methods. - auto emitCreateImplicit = [&](bool emitFake) { - OS << " static " << R.getName() << "Attr *CreateImplicit("; + auto emitCreate = [&](bool Implicit, bool emitFake) { + OS << " static " << R.getName() << "Attr *Create"; + if (Implicit) + OS << "Implicit"; + OS << "("; OS << "ASTContext &Ctx"; - if (!ElideSpelling) - OS << ", Spelling S"; for (auto const &ai : Args) { if (ai->isFake() && !emitFake) continue; OS << ", "; ai->writeCtorParameters(OS); } - OS << ", SourceRange Loc = SourceRange()"; - OS << ") {\n"; + OS << ", const AttributeCommonInfo &CommonInfo = {SourceRange{}}) {\n"; OS << " auto *A = new (Ctx) " << R.getName(); - OS << "Attr(Loc, Ctx, "; + OS << "Attr(Ctx, CommonInfo"; for (auto const &ai : Args) { if (ai->isFake() && !emitFake) continue; - ai->writeImplicitCtorArgs(OS); OS << ", "; + ai->writeImplicitCtorArgs(OS); + } + OS << ");\n"; + if (Implicit) { + OS << " A->setImplicit(true);\n"; + } + if (Implicit || ElideSpelling) { + OS << " if (!A->isAttributeSpellingListCalculated() && " + "!A->getAttrName())\n"; + OS << " A->setAttributeSpellingListIndex(0);\n"; } - OS << (ElideSpelling ? "0" : "S") << ");\n"; - OS << " A->setImplicit(true);\n"; OS << " return A;\n }\n\n"; }; + auto emitCreateNoCI = [&](bool Implicit, bool emitFake) { + OS <<" static " << R.getName() << "Attr *Create"; + if (Implicit) + OS << "Implicit"; + OS << "("; + OS << "ASTContext &Ctx"; + for (auto const &ai : Args) { + if (ai->isFake() && !emitFake) continue; + OS << ", "; + ai->writeCtorParameters(OS); + } + OS << ", SourceRange Range, AttributeCommonInfo::Syntax Syntax"; + if (!ElideSpelling) + OS << ", " << R.getName() + << "Attr::Spelling Spelling = " + "static_cast(SpellingNotCalculated)"; + OS << ") {\n"; + OS << " AttributeCommonInfo I(Range, "; + + if (ParsedAttrSpellingItr != std::end(AttrMap)) + OS << "AT_" << ParsedAttrSpellingItr->first; + else + OS << "NoSemaHandlerAttribute"; + + OS << ", Syntax"; + if (!ElideSpelling) + OS << ", Spelling"; + OS << ");\n"; + OS << " return Create"; + if (Implicit) + OS << "Implicit"; + OS << "(Ctx"; + for (auto const &ai : Args) { + if (ai->isFake() && !emitFake) continue; + OS << ", "; + ai->writeImplicitCtorArgs(OS); + } + OS << ", I);\n"; + OS << " }\n"; + }; + + auto emitCreates = [&](bool emitFake) { + emitCreate(true, emitFake); + emitCreate(false, emitFake); + emitCreateNoCI(true, emitFake); + emitCreateNoCI(false, emitFake); + }; + // Emit a CreateImplicit that takes all the arguments. - emitCreateImplicit(true); + emitCreates(true); // Emit a CreateImplicit that takes all the non-fake arguments. - if (HasFakeArg) { - emitCreateImplicit(false); - } + if (HasFakeArg) + emitCreates(false); // Emit constructors. auto emitCtor = [&](bool emitOpt, bool emitFake) { @@ -2329,8 +2389,9 @@ if (arg->isOptional()) return emitOpt; return true; }; - - OS << " " << R.getName() << "Attr(SourceRange R, ASTContext &Ctx\n"; + OS << " " << R.getName() + << "Attr(ASTContext &Ctx, const AttributeCommonInfo &CommonInfo"; + OS << '\n'; for (auto const &ai : Args) { if (!shouldEmitArg(ai)) continue; OS << " , "; @@ -2338,12 +2399,10 @@ OS << "\n"; } - OS << " , "; - OS << "unsigned SI\n"; - OS << " )\n"; - OS << " : " << SuperName << "(attr::" << R.getName() << ", R, SI, " - << ( R.getValueAsBit("LateParsed") ? "true" : "false" ); + OS << " : " << SuperName << "(Ctx, CommonInfo, "; + OS << "attr::" << R.getName() << ", " + << (R.getValueAsBit("LateParsed") ? "true" : "false"); if (Inheritable) { OS << ", " << (R.getValueAsBit("InheritEvenIfAlreadyPresent") ? "true" @@ -2375,14 +2434,12 @@ emitCtor(true, true); // Emit a constructor that takes all the non-fake arguments. - if (HasFakeArg) { + if (HasFakeArg) emitCtor(true, false); - } // Emit a constructor that takes all the non-fake, non-optional arguments. - if (HasOptArg) { + if (HasOptArg) emitCtor(false, false); - } OS << " " << R.getName() << "Attr *clone(ASTContext &C) const;\n"; OS << " void printPretty(raw_ostream &OS,\n" @@ -2392,8 +2449,8 @@ if (!ElideSpelling) { assert(!SemanticToSyntacticMap.empty() && "Empty semantic mapping list"); OS << " Spelling getSemanticSpelling() const {\n"; - WriteSemanticSpellingSwitch("SpellingListIndex", SemanticToSyntacticMap, - OS); + WriteSemanticSpellingSwitch("getAttributeSpellingListIndex()", + SemanticToSyntacticMap, OS); OS << " }\n"; } @@ -2447,15 +2504,15 @@ OS << R.getName() << "Attr *" << R.getName() << "Attr::clone(ASTContext &C) const {\n"; - OS << " auto *A = new (C) " << R.getName() << "Attr(getLocation(), C"; + OS << " auto *A = new (C) " << R.getName() << "Attr(C, *this"; for (auto const &ai : Args) { OS << ", "; ai->writeCloneArgs(OS); } - OS << ", getSpellingListIndex());\n"; + OS << ");\n"; OS << " A->Inherited = Inherited;\n"; OS << " A->IsPackExpansion = IsPackExpansion;\n"; - OS << " A->Implicit = Implicit;\n"; + OS << " A->setImplicit(Implicit);\n"; OS << " return A;\n}\n\n"; writePrettyPrintFunction(R, Args, OS); @@ -2755,24 +2812,23 @@ const Record &R = *Attr; if (!R.getValueAsBit("ASTNode")) continue; - + OS << " case attr::" << R.getName() << ": {\n"; if (R.isSubClassOf(InhClass)) OS << " bool isInherited = Record.readInt();\n"; OS << " bool isImplicit = Record.readInt();\n"; - OS << " unsigned Spelling = Record.readInt();\n"; ArgRecords = R.getValueAsListOfDefs("Args"); Args.clear(); for (const auto *Arg : ArgRecords) { Args.emplace_back(createArgument(*Arg, R.getName())); Args.back()->writePCHReadDecls(OS); } - OS << " New = new (Context) " << R.getName() << "Attr(Range, Context"; + OS << " New = new (Context) " << R.getName() << "Attr(Context, Info"; for (auto const &ri : Args) { OS << ", "; ri->writePCHReadArgs(OS); } - OS << ", Spelling);\n"; + OS << ");\n"; if (R.isSubClassOf(InhClass)) OS << " cast(New)->setInherited(isInherited);\n"; OS << " New->setImplicit(isImplicit);\n"; @@ -2802,7 +2858,6 @@ if (R.isSubClassOf(InhClass)) OS << " Record.push_back(SA->isInherited());\n"; OS << " Record.push_back(A->isImplicit());\n"; - OS << " Record.push_back(A->getSpellingListIndex());\n"; for (const auto *Arg : Args) createArgument(*Arg, R.getName())->writePCHWrite(OS); @@ -3019,7 +3074,11 @@ emitSourceFileHeader("Code to translate different attribute spellings " "into internal identifiers", OS); - OS << " switch (AttrKind) {\n"; + OS << " switch (getParsedKind()) {\n"; + OS << " case IgnoredAttribute:\n"; + OS << " case UnknownAttribute:\n"; + OS << " case NoSemaHandlerAttribute:\n"; + OS << " llvm_unreachable(\"Ignored/unknown shouldn't get here\");\n"; ParsedAttrMap Attrs = getParsedAttrList(Records); for (const auto &I : Attrs) { @@ -3028,16 +3087,7 @@ OS << " case AT_" << I.first << ": {\n"; for (unsigned I = 0; I < Spellings.size(); ++ I) { OS << " if (Name == \"" << Spellings[I].name() << "\" && " - << "SyntaxUsed == " - << StringSwitch(Spellings[I].variety()) - .Case("GNU", 0) - .Case("CXX11", 1) - .Case("C2x", 2) - .Case("Declspec", 3) - .Case("Microsoft", 4) - .Case("Keyword", 5) - .Case("Pragma", 6) - .Default(0) + << "getSyntax() == AttributeCommonInfo::AS_" << Spellings[I].variety() << " && Scope == \"" << Spellings[I].nameSpace() << "\")\n" << " return " << I << ";\n"; } @@ -3158,12 +3208,12 @@ for (auto const &ai : Args) ai->writeTemplateInstantiation(OS); - OS << " return new (C) " << R.getName() << "Attr(A->getLocation(), C"; + OS << " return new (C) " << R.getName() << "Attr(C, *A"; for (auto const &ai : Args) { OS << ", "; ai->writeTemplateInstantiationArgs(OS); } - OS << ", A->getSpellingListIndex());\n }\n"; + OS << ");\n }\n"; } OS << " } // end switch\n" << " llvm_unreachable(\"Unknown attribute!\");\n" @@ -3481,7 +3531,7 @@ OS << " if (" << GenerateTestExpression(LangOpts) << ")\n"; OS << " return true;\n\n"; OS << " S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) "; - OS << "<< Attr.getName();\n"; + OS << "<< Attr;\n"; OS << " return false;\n"; OS << "}\n\n";