From a6f759e423940dd5357772372524daf469c40ff1 Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Fri, 5 Dec 2014 15:24:55 +0000 Subject: [PATCH] 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. llvm-svn: 223468 --- clang/docs/ReleaseNotes.rst | 6 +++++- clang/include/clang/Basic/Attributes.h | 2 -- clang/lib/Lex/PPMacroExpansion.cpp | 2 +- clang/test/Preprocessor/has_attribute.c | 5 +++++ clang/utils/TableGen/ClangAttrEmitter.cpp | 3 --- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index daab804..8c47d69 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/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/clang/include/clang/Basic/Attributes.h b/clang/include/clang/Basic/Attributes.h index 982e12d..1078600 100644 --- a/clang/include/clang/Basic/Attributes.h +++ b/clang/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/clang/lib/Lex/PPMacroExpansion.cpp b/clang/lib/Lex/PPMacroExpansion.cpp index 26cf543..b402a93 100644 --- a/clang/lib/Lex/PPMacroExpansion.cpp +++ b/clang/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/clang/test/Preprocessor/has_attribute.c b/clang/test/Preprocessor/has_attribute.c index 5fe060e..0ef5b48 100644 --- a/clang/test/Preprocessor/has_attribute.c +++ b/clang/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/clang/utils/TableGen/ClangAttrEmitter.cpp b/clang/utils/TableGen/ClangAttrEmitter.cpp index 7847b4f..67f9452 100644 --- a/clang/utils/TableGen/ClangAttrEmitter.cpp +++ b/clang/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"); -- 2.7.4