From: Aaron Ballman Date: Fri, 5 Dec 2014 15:24:55 +0000 (+0000) Subject: Modify __has_attribute so that it only looks for GNU-style attributes. Removes the... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e3446ce886b20b363e093cbd400b6f4337efb6c4;p=clang Modify __has_attribute so that it only looks for GNU-style attributes. Removes the ability to look for generic attributes and keywords via this macro, which has the potential to be a breaking change. However, since there is __has_cpp_attribute and __has_declspec_attribute, and given the limited usefulness of querying a generic attribute name regardless of syntax, this seems like the correct path forward. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@223468 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/docs/ReleaseNotes.rst b/docs/ReleaseNotes.rst index daab804b53..8c47d693ed 100644 --- a/docs/ReleaseNotes.rst +++ b/docs/ReleaseNotes.rst @@ -47,7 +47,11 @@ sections with improvements to Clang's support for those languages. Major New Features ------------------ -- A big one. +- The __has_attribute built-in macro no longer queries for attributes across + multiple attribute syntaxes (GNU, C++11, __declspec, etc). Instead, it only + queries GNU-style attributes. With the addition of __has_cpp_attribute and + __has_declspec_attribute, this allows for more precise coverage of attribute + syntax querying. Improvements to Clang's diagnostics diff --git a/include/clang/Basic/Attributes.h b/include/clang/Basic/Attributes.h index 982e12d9f2..10786006f8 100644 --- a/include/clang/Basic/Attributes.h +++ b/include/clang/Basic/Attributes.h @@ -18,8 +18,6 @@ namespace clang { class IdentifierInfo; enum class AttrSyntax { - /// Is the attribute identifier generally known for any syntax? - Generic, /// Is the identifier known as a GNU-style attribute? GNU, /// Is the identifier known as a __declspec-style attribute? diff --git a/lib/Lex/PPMacroExpansion.cpp b/lib/Lex/PPMacroExpansion.cpp index 26cf5439e7..b402a939c5 100644 --- a/lib/Lex/PPMacroExpansion.cpp +++ b/lib/Lex/PPMacroExpansion.cpp @@ -1425,7 +1425,7 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) { // Check for a builtin is trivial. Value = FeatureII->getBuiltinID() != 0; } else if (II == Ident__has_attribute) - Value = hasAttribute(AttrSyntax::Generic, nullptr, FeatureII, + Value = hasAttribute(AttrSyntax::GNU, nullptr, FeatureII, getTargetInfo().getTriple(), getLangOpts()); else if (II == Ident__has_cpp_attribute) Value = hasAttribute(AttrSyntax::CXX, ScopeII, FeatureII, diff --git a/test/Preprocessor/has_attribute.c b/test/Preprocessor/has_attribute.c index 5fe060e68d..0ef5b4857a 100644 --- a/test/Preprocessor/has_attribute.c +++ b/test/Preprocessor/has_attribute.c @@ -48,3 +48,8 @@ int has_no_volatile_attribute(); #if !__has_attribute(dllexport) int does_not_have_dllexport(); #endif + +// CHECK: does_not_have_uuid +#if !__has_attribute(uuid) + int does_not_have_uuid +#endif diff --git a/utils/TableGen/ClangAttrEmitter.cpp b/utils/TableGen/ClangAttrEmitter.cpp index 7847b4f931..67f9452ba6 100644 --- a/utils/TableGen/ClangAttrEmitter.cpp +++ b/utils/TableGen/ClangAttrEmitter.cpp @@ -1920,9 +1920,6 @@ void EmitClangAttrHasAttrImpl(RecordKeeper &Records, raw_ostream &OS) { } OS << "switch (Syntax) {\n"; - OS << "case AttrSyntax::Generic:\n"; - OS << " return llvm::StringSwitch(Name)\n"; - GenerateHasAttrSpellingStringSwitch(Attrs, OS); OS << "case AttrSyntax::GNU:\n"; OS << " return llvm::StringSwitch(Name)\n"; GenerateHasAttrSpellingStringSwitch(GNU, OS, "GNU");