diff options
author | Aaron Ballman <aaron@aaronballman.com> | 2018-11-09 17:19:45 +0000 |
---|---|---|
committer | Aaron Ballman <aaron@aaronballman.com> | 2018-11-09 17:19:45 +0000 |
commit | 71ae196c71f83c6d209e3e27dadd0d6cf56a1992 (patch) | |
tree | 4394a8ae79163e0f20095307f8132420c629592a /lib/Parse/ParseDeclCXX.cpp | |
parent | e4084593e04ade7abbca3ab568f9f1c54b17d431 (diff) | |
download | clang-71ae196c71f83c6d209e3e27dadd0d6cf56a1992.tar.gz |
Introduce the _Clang scoped attribute token.
Currently, we only accept clang as the scoped attribute identifier for double square bracket attributes provided by Clang, but this has the potential to conflict with user-defined macros. To help alleviate these concerns, this introduces the _Clang scoped attribute identifier as an alias for clang. It also introduces a warning with a fixit on the off chance someone attempts to use __clang__ as the scoped attribute (which is a predefined compiler identification macro).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@346521 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Parse/ParseDeclCXX.cpp')
-rw-r--r-- | lib/Parse/ParseDeclCXX.cpp | 44 |
1 files changed, 32 insertions, 12 deletions
diff --git a/lib/Parse/ParseDeclCXX.cpp b/lib/Parse/ParseDeclCXX.cpp index 9369f0f56c..c814775c77 100644 --- a/lib/Parse/ParseDeclCXX.cpp +++ b/lib/Parse/ParseDeclCXX.cpp @@ -3790,6 +3790,28 @@ IdentifierInfo *Parser::TryParseCXX11AttributeIdentifier(SourceLocation &Loc) { } return nullptr; + case tok::numeric_constant: { + // If we got a numeric constant, check to see if it comes from a macro that + // corresponds to the predefined __clang__ macro. If it does, warn the user + // and recover by pretending they said _Clang instead. + if (Tok.getLocation().isMacroID()) { + SmallString<8> ExpansionBuf; + SourceLocation ExpansionLoc = + PP.getSourceManager().getExpansionLoc(Tok.getLocation()); + StringRef Spelling = PP.getSpelling(ExpansionLoc, ExpansionBuf); + if (Spelling == "__clang__") { + SourceRange TokRange( + ExpansionLoc, + PP.getSourceManager().getExpansionLoc(Tok.getEndLoc())); + Diag(Tok, diag::warn_wrong_clang_attr_namespace) + << FixItHint::CreateReplacement(TokRange, "_Clang"); + Loc = ConsumeToken(); + return &PP.getIdentifierTable().get("_Clang"); + } + } + return nullptr; + } + case tok::ampamp: // 'and' case tok::pipe: // 'bitor' case tok::pipepipe: // 'or' @@ -3865,24 +3887,22 @@ bool Parser::ParseCXX11AttributeArgs(IdentifierInfo *AttrName, // Eat the left paren, then skip to the ending right paren. ConsumeParen(); SkipUntil(tok::r_paren); - return false;
- }
-
- if (ScopeName &&
- (ScopeName->getName() == "gnu" || ScopeName->getName() == "__gnu__")) {
- // GNU-scoped attributes have some special cases to handle GNU-specific
- // behaviors.
- ParseGNUAttributeArgs(AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
+ return false; + } + + if (ScopeName && (ScopeName->isStr("gnu") || ScopeName->isStr("__gnu__"))) { + // GNU-scoped attributes have some special cases to handle GNU-specific + // behaviors. + ParseGNUAttributeArgs(AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName, ScopeLoc, Syntax, nullptr); return true; } unsigned NumArgs; // Some Clang-scoped attributes have some special parsing behavior. - if (ScopeName && ScopeName->getName() == "clang") - NumArgs = - ParseClangAttributeArgs(AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName, - ScopeLoc, Syntax); + if (ScopeName && (ScopeName->isStr("clang") || ScopeName->isStr("_Clang"))) + NumArgs = ParseClangAttributeArgs(AttrName, AttrNameLoc, Attrs, EndLoc, + ScopeName, ScopeLoc, Syntax); else NumArgs = ParseAttributeArgsCommon(AttrName, AttrNameLoc, Attrs, EndLoc, |