[clang] ef3800e - Return false from __has_declspec_attribute() if not explicitly enabled
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 12 10:20:21 PST 2021
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) {
More information about the cfe-commits
mailing list