summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/ParsedAttr.cpp
diff options
context:
space:
mode:
authorAaron Ballman <aaron@aaronballman.com>2018-10-24 12:26:23 +0000
committerAaron Ballman <aaron@aaronballman.com>2018-10-24 12:26:23 +0000
commitad672ffb643c646ca7680c765342bd58252ecdbe (patch)
tree983949541e2d1345350ca5f6f01833b6db7a09da /clang/lib/Sema/ParsedAttr.cpp
parentc4a995c8e05bd63932677ee30e4f4cfd6623eaff (diff)
downloadbcm5719-llvm-ad672ffb643c646ca7680c765342bd58252ecdbe.tar.gz
bcm5719-llvm-ad672ffb643c646ca7680c765342bd58252ecdbe.zip
Support accepting __gnu__ as a scoped attribute namespace that aliases to gnu.
This is useful in libstdc++ to avoid clashes with identifiers in the user's namespace. llvm-svn: 345132
Diffstat (limited to 'clang/lib/Sema/ParsedAttr.cpp')
-rw-r--r--clang/lib/Sema/ParsedAttr.cpp26
1 files changed, 19 insertions, 7 deletions
diff --git a/clang/lib/Sema/ParsedAttr.cpp b/clang/lib/Sema/ParsedAttr.cpp
index 3dff0ad63e2..ccfbe66db97 100644
--- a/clang/lib/Sema/ParsedAttr.cpp
+++ b/clang/lib/Sema/ParsedAttr.cpp
@@ -103,14 +103,25 @@ void AttributePool::takePool(AttributePool &pool) {
#include "clang/Sema/AttrParsedAttrKinds.inc"
-static StringRef normalizeAttrName(StringRef AttrName, StringRef ScopeName,
+static StringRef normalizeAttrScopeName(StringRef ScopeName,
+ ParsedAttr::Syntax SyntaxUsed) {
+ // We currently only normalize the "__gnu__" scope name to be "gnu".
+ if ((SyntaxUsed == ParsedAttr::AS_CXX11 ||
+ SyntaxUsed == ParsedAttr::AS_C2x) &&
+ ScopeName == "__gnu__")
+ ScopeName = ScopeName.slice(2, ScopeName.size() - 2);
+ return ScopeName;
+}
+
+static StringRef normalizeAttrName(StringRef AttrName,
+ StringRef NormalizedScopeName,
ParsedAttr::Syntax SyntaxUsed) {
// Normalize the attribute name, __foo__ becomes foo. This is only allowable
- // for GNU attributes.
+ // for GNU attributes, and attributes using the double square bracket syntax.
bool IsGNU = SyntaxUsed == ParsedAttr::AS_GNU ||
((SyntaxUsed == ParsedAttr::AS_CXX11 ||
SyntaxUsed == ParsedAttr::AS_C2x) &&
- ScopeName == "gnu");
+ NormalizedScopeName == "gnu");
if (IsGNU && AttrName.size() >= 4 && AttrName.startswith("__") &&
AttrName.endswith("__"))
AttrName = AttrName.slice(2, AttrName.size() - 2);
@@ -125,7 +136,7 @@ ParsedAttr::Kind ParsedAttr::getKind(const IdentifierInfo *Name,
SmallString<64> FullName;
if (ScopeName)
- FullName += ScopeName->getName();
+ FullName += normalizeAttrScopeName(ScopeName->getName(), SyntaxUsed);
AttrName = normalizeAttrName(AttrName, FullName, SyntaxUsed);
@@ -141,9 +152,10 @@ ParsedAttr::Kind ParsedAttr::getKind(const IdentifierInfo *Name,
unsigned ParsedAttr::getAttributeSpellingListIndex() const {
// Both variables will be used in tablegen generated
// attribute spell list index matching code.
- StringRef Scope = ScopeName ? ScopeName->getName() : "";
- StringRef Name = normalizeAttrName(AttrName->getName(), Scope,
- (ParsedAttr::Syntax)SyntaxUsed);
+ auto Syntax = static_cast<ParsedAttr::Syntax>(SyntaxUsed);
+ StringRef Scope =
+ ScopeName ? normalizeAttrScopeName(ScopeName->getName(), Syntax) : "";
+ StringRef Name = normalizeAttrName(AttrName->getName(), Scope, Syntax);
#include "clang/Sema/AttrSpellingListIndex.inc"
OpenPOWER on IntegriCloud