[modules] If we find more formerly-canonical declarations of an entity while
authorRichard Smith <richard-llvm@metafoo.co.uk>
Mon, 16 Mar 2015 20:54:07 +0000 (20:54 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Mon, 16 Mar 2015 20:54:07 +0000 (20:54 +0000)
building its redecl chains, make sure we pull in the redeclarations of those
canonical declarations.

It's pretty difficult to reach a situation where we can find more canonical
declarations of an entity while building its redecl chains; I think the
provided testcase (4 modules and 7 declarations) cannot be reduced further.

llvm-svn: 232411

clang/lib/Serialization/ASTReader.cpp
clang/test/Modules/Inputs/redecl-found-building-chains/a.h [new file with mode: 0644]
clang/test/Modules/Inputs/redecl-found-building-chains/b.h [new file with mode: 0644]
clang/test/Modules/Inputs/redecl-found-building-chains/c.h [new file with mode: 0644]
clang/test/Modules/Inputs/redecl-found-building-chains/d.h [new file with mode: 0644]
clang/test/Modules/Inputs/redecl-found-building-chains/module.modulemap [new file with mode: 0644]
clang/test/Modules/redecl-found-building-chains.cpp [new file with mode: 0644]

index 68d5756..ec14eec 100644 (file)
@@ -8304,8 +8304,8 @@ void ASTReader::finishPendingActions() {
 
     // Load pending declaration chains.
     for (unsigned I = 0; I != PendingDeclChains.size(); ++I) {
-      loadPendingDeclChain(PendingDeclChains[I]);
       PendingDeclChainsKnown.erase(PendingDeclChains[I]);
+      loadPendingDeclChain(PendingDeclChains[I]);
     }
     assert(PendingDeclChainsKnown.empty());
     PendingDeclChains.clear();
diff --git a/clang/test/Modules/Inputs/redecl-found-building-chains/a.h b/clang/test/Modules/Inputs/redecl-found-building-chains/a.h
new file mode 100644 (file)
index 0000000..27f503c
--- /dev/null
@@ -0,0 +1 @@
+struct A;
diff --git a/clang/test/Modules/Inputs/redecl-found-building-chains/b.h b/clang/test/Modules/Inputs/redecl-found-building-chains/b.h
new file mode 100644 (file)
index 0000000..f69dccb
--- /dev/null
@@ -0,0 +1,2 @@
+struct A; // ensure that loading b's canonical decl doesn't load the definition
+struct A {};
diff --git a/clang/test/Modules/Inputs/redecl-found-building-chains/c.h b/clang/test/Modules/Inputs/redecl-found-building-chains/c.h
new file mode 100644 (file)
index 0000000..27f503c
--- /dev/null
@@ -0,0 +1 @@
+struct A;
diff --git a/clang/test/Modules/Inputs/redecl-found-building-chains/d.h b/clang/test/Modules/Inputs/redecl-found-building-chains/d.h
new file mode 100644 (file)
index 0000000..0beef5a
--- /dev/null
@@ -0,0 +1,6 @@
+#include "a.h" // ensure that our canonical decl is not from b
+struct A;
+#include "b.h"
+struct A;
+#include "c.h" // ensure that our type for A doesn't reference the definition in b
+struct A;
diff --git a/clang/test/Modules/Inputs/redecl-found-building-chains/module.modulemap b/clang/test/Modules/Inputs/redecl-found-building-chains/module.modulemap
new file mode 100644 (file)
index 0000000..73a7c41
--- /dev/null
@@ -0,0 +1,4 @@
+module a { header "a.h" export * }
+module b { header "b.h" export * }
+module c { header "c.h" export * }
+module d { header "d.h" export * }
diff --git a/clang/test/Modules/redecl-found-building-chains.cpp b/clang/test/Modules/redecl-found-building-chains.cpp
new file mode 100644 (file)
index 0000000..1173863
--- /dev/null
@@ -0,0 +1,6 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I%S/Inputs/redecl-found-building-chains -verify %s
+// expected-no-diagnostics
+int n, m;
+#include "d.h"
+A a;