Author: John Brawn
Date: 2020-03-25T14:33:44Z
New Revision: bc3f171090f6d9f84a5d7b333bc70a1e14afffd4

URL: 
https://github.com/llvm/llvm-project/commit/bc3f171090f6d9f84a5d7b333bc70a1e14afffd4
DIFF: 
https://github.com/llvm/llvm-project/commit/bc3f171090f6d9f84a5d7b333bc70a1e14afffd4.diff

LOG: Don't normalise CXX11/C2X attribute names to start with ::

Currently square-bracket-style (CXX11/C2X) attribute names are normalised to
start with :: if they don't have a namespace. This is a bit odd, as such
names are rejected when parsing, so don't do this.

Differential Revision: https://reviews.llvm.org/D76704

Added: 
    

Modified: 
    clang/lib/Basic/Attributes.cpp
    clang/utils/TableGen/ClangAttrEmitter.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Basic/Attributes.cpp b/clang/lib/Basic/Attributes.cpp
index a860c9dba2ef..d479b39e149e 100644
--- a/clang/lib/Basic/Attributes.cpp
+++ b/clang/lib/Basic/Attributes.cpp
@@ -85,12 +85,12 @@ static SmallString<64> normalizeName(const IdentifierInfo 
*Name,
   StringRef ScopeName = normalizeAttrScopeName(Scope, SyntaxUsed);
   StringRef AttrName = normalizeAttrName(Name, ScopeName, SyntaxUsed);
 
-  // Ensure that in the case of C++11 attributes, we look for '::foo' if it is
-  // unscoped.
   SmallString<64> FullName = ScopeName;
-  if (Scope || SyntaxUsed == AttributeCommonInfo::AS_CXX11 ||
-      SyntaxUsed == AttributeCommonInfo::AS_C2x)
+  if (!ScopeName.empty()) {
+    assert(SyntaxUsed == AttributeCommonInfo::AS_CXX11 ||
+           SyntaxUsed == AttributeCommonInfo::AS_C2X);
     FullName += "::";
+  }
   FullName += AttrName;
 
   return FullName;

diff  --git a/clang/utils/TableGen/ClangAttrEmitter.cpp 
b/clang/utils/TableGen/ClangAttrEmitter.cpp
index dcb2f323122c..32744f7579fb 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -3739,10 +3739,8 @@ void EmitClangAttrParsedAttrImpl(RecordKeeper &Records, 
raw_ostream &OS) {
     for (const auto &S : GetFlattenedSpellings(Attr)) {
       const std::string &RawSpelling = S.name();
       std::string Spelling;
-      if (S.variety() == "CXX11" || S.variety() == "C2x") {
-        Spelling += S.nameSpace();
-        Spelling += "::";
-      }
+      if (!S.nameSpace().empty())
+        Spelling += S.nameSpace() + "::";
       if (S.variety() == "GNU")
         Spelling += NormalizeGNUAttrSpelling(RawSpelling);
       else
@@ -3815,12 +3813,12 @@ void EmitClangAttrParsedAttrKinds(RecordKeeper 
&Records, raw_ostream &OS) {
         const std::string &Variety = S.variety();
         if (Variety == "CXX11") {
           Matches = &CXX11;
-          Spelling += S.nameSpace();
-          Spelling += "::";
+          if (!S.nameSpace().empty())
+            Spelling += S.nameSpace() + "::";
         } else if (Variety == "C2x") {
           Matches = &C2x;
-          Spelling += S.nameSpace();
-          Spelling += "::";
+          if (!S.nameSpace().empty())
+            Spelling += S.nameSpace() + "::";
         } else if (Variety == "GNU")
           Matches = &GNU;
         else if (Variety == "Declspec")


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to