From c44c174246280dc7614b6591f48010858f482eb9 Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Fri, 9 Nov 2018 17:19:45 +0000 Subject: 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). llvm-svn: 346521 --- clang/lib/Basic/Attributes.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'clang/lib/Basic/Attributes.cpp') diff --git a/clang/lib/Basic/Attributes.cpp b/clang/lib/Basic/Attributes.cpp index 1c84d0779e1..9a8eb3d932c 100644 --- a/clang/lib/Basic/Attributes.cpp +++ b/clang/lib/Basic/Attributes.cpp @@ -9,16 +9,18 @@ int clang::hasAttribute(AttrSyntax Syntax, const IdentifierInfo *Scope, const LangOptions &LangOpts) { StringRef Name = Attr->getName(); // Normalize the attribute name, __foo__ becomes foo. - if (Name.size() >= 4 && Name.startswith("__") && Name.endswith("__")) - Name = Name.substr(2, Name.size() - 4); - - // Normalize the scope name, but only for gnu attributes. - StringRef ScopeName = Scope ? Scope->getName() : ""; - if (ScopeName == "__gnu__") - ScopeName = ScopeName.slice(2, ScopeName.size() - 2); - -#include "clang/Basic/AttrHasAttributeImpl.inc" - + if (Name.size() >= 4 && Name.startswith("__") && Name.endswith("__")) + Name = Name.substr(2, Name.size() - 4); + + // Normalize the scope name, but only for gnu and clang attributes. + StringRef ScopeName = Scope ? Scope->getName() : ""; + if (ScopeName == "__gnu__") + ScopeName = "gnu"; + else if (ScopeName == "_Clang") + ScopeName = "clang"; + +#include "clang/Basic/AttrHasAttributeImpl.inc" + return 0; } -- cgit v1.2.3