r306926 - [ODRHash] Revert r305104 - Skip inline namespaces when hashing.

Richard Trieu via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 30 19:00:05 PDT 2017


Author: rtrieu
Date: Fri Jun 30 19:00:05 2017
New Revision: 306926

URL: http://llvm.org/viewvc/llvm-project?rev=306926&view=rev
Log:
[ODRHash] Revert r305104 - Skip inline namespaces when hashing.

Test inline namespaces and handle them in the ODR hash again.

Modified:
    cfe/trunk/lib/AST/ODRHash.cpp
    cfe/trunk/lib/AST/StmtProfile.cpp
    cfe/trunk/test/Modules/odr_hash.cpp

Modified: cfe/trunk/lib/AST/ODRHash.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ODRHash.cpp?rev=306926&r1=306925&r2=306926&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ODRHash.cpp (original)
+++ cfe/trunk/lib/AST/ODRHash.cpp Fri Jun 30 19:00:05 2017
@@ -82,25 +82,13 @@ void ODRHash::AddDeclarationName(Declara
 }
 
 void ODRHash::AddNestedNameSpecifier(const NestedNameSpecifier *NNS) {
-  // Unlike the other pointer handling functions, allow null pointers here.
-  if (!NNS) {
-    AddBoolean(false);
-    return;
+  assert(NNS && "Expecting non-null pointer.");
+  const auto *Prefix = NNS->getPrefix();
+  AddBoolean(Prefix);
+  if (Prefix) {
+    AddNestedNameSpecifier(Prefix);
   }
-
-  // Skip inlined namespaces.
   auto Kind = NNS->getKind();
-  if (Kind == NestedNameSpecifier::Namespace) {
-    if (NNS->getAsNamespace()->isInline()) {
-      return AddNestedNameSpecifier(NNS->getPrefix());
-    }
-  }
-
-  AddBoolean(true);
-
-  // Process prefix
-  AddNestedNameSpecifier(NNS->getPrefix());
-
   ID.AddInteger(Kind);
   switch (Kind) {
   case NestedNameSpecifier::Identifier:
@@ -441,7 +429,10 @@ public:
   }
 
   void AddNestedNameSpecifier(const NestedNameSpecifier *NNS) {
-    Hash.AddNestedNameSpecifier(NNS);
+    Hash.AddBoolean(NNS);
+    if (NNS) {
+      Hash.AddNestedNameSpecifier(NNS);
+    }
   }
 
   void AddIdentifierInfo(const IdentifierInfo *II) {

Modified: cfe/trunk/lib/AST/StmtProfile.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtProfile.cpp?rev=306926&r1=306925&r2=306926&view=diff
==============================================================================
--- cfe/trunk/lib/AST/StmtProfile.cpp (original)
+++ cfe/trunk/lib/AST/StmtProfile.cpp Fri Jun 30 19:00:05 2017
@@ -186,7 +186,10 @@ namespace {
       Hash.AddTemplateName(Name);
     }
     void VisitNestedNameSpecifier(NestedNameSpecifier *NNS) override {
-      Hash.AddNestedNameSpecifier(NNS);
+      ID.AddBoolean(NNS);
+      if (NNS) {
+        Hash.AddNestedNameSpecifier(NNS);
+      }
     }
   };
 }

Modified: cfe/trunk/test/Modules/odr_hash.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/odr_hash.cpp?rev=306926&r1=306925&r2=306926&view=diff
==============================================================================
--- cfe/trunk/test/Modules/odr_hash.cpp (original)
+++ cfe/trunk/test/Modules/odr_hash.cpp Fri Jun 30 19:00:05 2017
@@ -968,6 +968,24 @@ S9 s9;
 // expected-error at second.h:* {{'NestedNamespaceSpecifier::S9' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type 'P9::I' (aka 'int')}}
 // expected-note at first.h:* {{but in 'FirstModule' found field 'x' with type 'O9::I' (aka 'int')}}
 #endif
+
+namespace N10 {
+#if defined(FIRST)
+inline namespace A { struct X {}; }
+struct S10 {
+  A::X x;
+};
+#elif defined(SECOND)
+inline namespace B { struct X {}; }
+struct S10 {
+  B::X x;
+};
+#else
+S10 s10;
+// expected-error at second.h:* {{'NestedNamespaceSpecifier::N10::S10::x' from module 'SecondModule' is not present in definition of 'NestedNamespaceSpecifier::N10::S10' in module 'FirstModule'}}
+// expected-note at first.h:* {{declaration of 'x' does not match}}
+#endif
+}
 }
 
 namespace TemplateSpecializationType {




More information about the cfe-commits mailing list