diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-02-25 10:41:10 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-02-25 10:41:10 +0000 |
commit | 2cca7b5ca98ae5e273d365b62b9d82ad58a4bada (patch) | |
tree | 53432ef82a0573d694c3564bb7dfaa1d55652865 /clang/lib/Lex | |
parent | 2a986117e9ba4324fb041ba629b2a5fa85ff750e (diff) | |
download | bcm5719-llvm-2cca7b5ca98ae5e273d365b62b9d82ad58a4bada.tar.gz bcm5719-llvm-2cca7b5ca98ae5e273d365b62b9d82ad58a4bada.zip |
Accept __has_feature(__feature__) as a synonym for __has_feature(feature) (and
likewise for __has_extension). Patch by Jonathan Sauer!
llvm-svn: 151445
Diffstat (limited to 'clang/lib/Lex')
-rw-r--r-- | clang/lib/Lex/PPMacroExpansion.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/clang/lib/Lex/PPMacroExpansion.cpp b/clang/lib/Lex/PPMacroExpansion.cpp index bc346927027..c7c8e00f409 100644 --- a/clang/lib/Lex/PPMacroExpansion.cpp +++ b/clang/lib/Lex/PPMacroExpansion.cpp @@ -589,8 +589,13 @@ static void ComputeDATE_TIME(SourceLocation &DATELoc, SourceLocation &TIMELoc, /// specified by the identifier as a standard language feature. static bool HasFeature(const Preprocessor &PP, const IdentifierInfo *II) { const LangOptions &LangOpts = PP.getLangOptions(); + StringRef Feature = II->getName(); - return llvm::StringSwitch<bool>(II->getName()) + // Normalize the feature name, __foo__ becomes foo. + if (Feature.startswith("__") && Feature.endswith("__") && Feature.size() >= 4) + Feature = Feature.substr(2, Feature.size() - 4); + + return llvm::StringSwitch<bool>(Feature) .Case("address_sanitizer", LangOpts.AddressSanitizer) .Case("attribute_analyzer_noreturn", true) .Case("attribute_availability", true) @@ -724,10 +729,16 @@ static bool HasExtension(const Preprocessor &PP, const IdentifierInfo *II) { return false; const LangOptions &LangOpts = PP.getLangOptions(); + StringRef Extension = II->getName(); + + // Normalize the extension name, __foo__ becomes foo. + if (Extension.startswith("__") && Extension.endswith("__") && + Extension.size() >= 4) + Extension = Extension.substr(2, Extension.size() - 4); // Because we inherit the feature list from HasFeature, this string switch // must be less restrictive than HasFeature's. - return llvm::StringSwitch<bool>(II->getName()) + return llvm::StringSwitch<bool>(Extension) // C11 features supported by other languages as extensions. .Case("c_alignas", true) .Case("c_atomic", true) |