Author: Timm Bäder Date: 2021-01-12T13:20:08-05:00 New Revision: ef3800e82169c674219501d9ac09ef12b28e6359
URL: https://github.com/llvm/llvm-project/commit/ef3800e82169c674219501d9ac09ef12b28e6359 DIFF: https://github.com/llvm/llvm-project/commit/ef3800e82169c674219501d9ac09ef12b28e6359.diff LOG: Return false from __has_declspec_attribute() if not explicitly enabled Currently, projects can check for __has_declspec_attribute() and use it accordingly, but the check for __has_declspec_attribute will return true even if declspec attributes are not enabled for the target. This changes Clang to instead return false when declspec attributes are not supported for the target. Added: Modified: clang/lib/Lex/PPMacroExpansion.cpp Removed: ################################################################################ diff --git a/clang/lib/Lex/PPMacroExpansion.cpp b/clang/lib/Lex/PPMacroExpansion.cpp index 3969630f2002..43d31d6c5732 100644 --- a/clang/lib/Lex/PPMacroExpansion.cpp +++ b/clang/lib/Lex/PPMacroExpansion.cpp @@ -1693,8 +1693,14 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) { [this](Token &Tok, bool &HasLexedNextToken) -> int { IdentifierInfo *II = ExpectFeatureIdentifierInfo(Tok, *this, diag::err_feature_check_malformed); - return II ? hasAttribute(AttrSyntax::Declspec, nullptr, II, - getTargetInfo(), getLangOpts()) : 0; + if (II) { + const LangOptions &LangOpts = getLangOpts(); + return LangOpts.DeclSpecKeyword && + hasAttribute(AttrSyntax::Declspec, nullptr, II, + getTargetInfo(), LangOpts); + } + + return false; }); } else if (II == Ident__has_cpp_attribute || II == Ident__has_c_attribute) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits