diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/clang/AST/Attr.h | 151 | ||||
-rw-r--r-- | include/clang/Basic/Attr.td | 4 | ||||
-rw-r--r-- | include/clang/Basic/AttributeCommonInfo.h | 190 | ||||
-rw-r--r-- | include/clang/Lex/Preprocessor.h | 14 | ||||
-rw-r--r-- | include/clang/Sema/ParsedAttr.h | 212 | ||||
-rw-r--r-- | include/clang/Sema/Sema.h | 103 | ||||
-rw-r--r-- | include/clang/Serialization/ASTBitCodes.h | 2 |
7 files changed, 390 insertions, 286 deletions
diff --git a/include/clang/AST/Attr.h b/include/clang/AST/Attr.h index 1fbed7ceeb..d315dde6ed 100644 --- a/include/clang/AST/Attr.h +++ b/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 @@ namespace clang { class TypeSourceInfo; /// Attr - This represents one attribute. -class Attr { -private: - SourceRange Range; - unsigned AttrKind : 16; - -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); - } + 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; + + 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<attr::Kind>(AttrKind); - } + public: + attr::Kind getKind() const { return static_cast<attr::Kind>(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 @@ public: 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 @@ public: 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 @@ public: 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 @@ public: /// 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 { diff --git a/include/clang/Basic/Attr.td b/include/clang/Basic/Attr.td index e31f3cd9b2..4cb1618b25 100644 --- a/include/clang/Basic/Attr.td +++ b/include/clang/Basic/Attr.td @@ -3042,7 +3042,7 @@ def LoopHint : Attr { } 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 @@ def LoopHint : Attr { // 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) diff --git a/include/clang/Basic/AttributeCommonInfo.h b/include/clang/Basic/AttributeCommonInfo.h new file mode 100644 index 0000000000..c8fc0a5a04 --- /dev/null +++ b/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 diff --git a/include/clang/Lex/Preprocessor.h b/include/clang/Lex/Preprocessor.h index 0db365792a..d800ee1289 100644 --- a/include/clang/Lex/Preprocessor.h +++ b/include/clang/Lex/Preprocessor.h @@ -371,9 +371,9 @@ class Preprocessor { /// 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<IdentifierInfo *, SourceLocation> PragmaARCCFCodeAuditedInfo; /// The source location of the currently-active /// \#pragma clang assume_nonnull begin. @@ -1602,14 +1602,16 @@ public: /// arc_cf_code_audited begin. /// /// Returns an invalid location if there is no such pragma active. - SourceLocation getPragmaARCCFCodeAuditedLoc() const { - return PragmaARCCFCodeAuditedLoc; + std::pair<IdentifierInfo *, SourceLocation> + 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 diff --git a/include/clang/Sema/ParsedAttr.h b/include/clang/Sema/ParsedAttr.h index d87d5da04a..d9d8585970 100644 --- a/include/clang/Sema/ParsedAttr.h +++ b/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 @@ using ArgsVector = llvm::SmallVector<ArgsUnion, 12U>; /// 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 @@ class ParsedAttr final 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 @@ private: 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 @@ private: 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 @@ private: 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 @@ private: 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 @@ private: 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 @@ private: 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 @@ public: 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 @@ public: 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 @@ public: 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 @@ public: } 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 @@ public: 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 @@ public: /// 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 @@ public: return LangAS::Default; } } + + AttributeCommonInfo::Kind getKind() const { return getParsedKind(); } }; class AttributePool; @@ -889,8 +806,9 @@ public: } 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 @@ enum AttributeDeclKind { inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, const ParsedAttr &At) { - DB.AddTaggedVal(reinterpret_cast<intptr_t>(At.getName()), + DB.AddTaggedVal(reinterpret_cast<intptr_t>(At.getAttrName()), DiagnosticsEngine::ak_identifierinfo); return DB; } inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD, const ParsedAttr &At) { - PD.AddTaggedVal(reinterpret_cast<intptr_t>(At.getName()), + PD.AddTaggedVal(reinterpret_cast<intptr_t>(At.getAttrName()), DiagnosticsEngine::ak_identifierinfo); return PD; } inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, const ParsedAttr *At) { - DB.AddTaggedVal(reinterpret_cast<intptr_t>(At->getName()), + DB.AddTaggedVal(reinterpret_cast<intptr_t>(At->getAttrName()), DiagnosticsEngine::ak_identifierinfo); return DB; } inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD, const ParsedAttr *At) { - PD.AddTaggedVal(reinterpret_cast<intptr_t>(At->getName()), + PD.AddTaggedVal(reinterpret_cast<intptr_t>(At->getAttrName()), DiagnosticsEngine::ak_identifierinfo); return PD; } diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index 59f16da8f3..59b1d9c3e4 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -2665,48 +2665,44 @@ public: }; /// 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 @@ public: 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); diff --git a/include/clang/Serialization/ASTBitCodes.h b/include/clang/Serialization/ASTBitCodes.h index 7b9ff7e550..be0bbe1a8c 100644 --- a/include/clang/Serialization/ASTBitCodes.h +++ b/include/clang/Serialization/ASTBitCodes.h @@ -41,7 +41,7 @@ namespace serialization { /// 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. |