[cfe-commits] r130102 - in /cfe/trunk: lib/Serialization/ASTReaderDecl.cpp test/PCH/chain-empty-initial-namespace.cpp

Sebastian Redl sebastian.redl at getdesigned.at
Sun Apr 24 09:27:54 PDT 2011


Author: cornedbee
Date: Sun Apr 24 11:27:54 2011
New Revision: 130102

URL: http://llvm.org/viewvc/llvm-project?rev=130102&view=rev
Log:
On reading DeclContexts from PCH, check for visible updates even if the context was empty in the original version. Also, if there are any, tell the context that it has external visible decls. This fixes the problem that a namespace that was empty in the initial PCH (could also happen if the initial PCH didn't include any std header but caused implicit creation of namespace std, e.g. due to implicit declaration of a virtual destructor) never found any declaration declared in *any* chained PCH. Very ugly when the chained PCH includes all that std stuff, as the errors were effectively the same as not including std headers.

Added:
    cfe/trunk/test/PCH/chain-empty-initial-namespace.cpp
Modified:
    cfe/trunk/lib/Serialization/ASTReaderDecl.cpp

Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=130102&r1=130101&r2=130102&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Sun Apr 24 11:27:54 2011
@@ -1661,22 +1661,26 @@
       // so we need to make sure we insert in front. For all other contexts,
       // the vector is empty here anyway, so there's no loss in efficiency.
       Infos.insert(Infos.begin(), Info);
+    }
 
-      // Now add the pending visible updates for this decl context, if it has
-      // any.
-      DeclContextVisibleUpdatesPending::iterator I =
-          PendingVisibleUpdates.find(ID);
-      if (I != PendingVisibleUpdates.end()) {
-        DeclContextVisibleUpdates &U = I->second;
-        Info.LexicalDecls = 0;
-        Info.NumLexicalDecls = 0;
-        for (DeclContextVisibleUpdates::iterator UI = U.begin(), UE = U.end();
-             UI != UE; ++UI) {
-          Info.NameLookupTableData = *UI;
-          Infos.push_back(Info);
-        }
-        PendingVisibleUpdates.erase(I);
+    // Now add the pending visible updates for this decl context, if it has any.
+    DeclContextVisibleUpdatesPending::iterator I =
+        PendingVisibleUpdates.find(ID);
+    if (I != PendingVisibleUpdates.end()) {
+      // There are updates. This means the context has external visible
+      // storage, even if the original stored version didn't.
+      DC->setHasExternalVisibleStorage(true);
+      DeclContextVisibleUpdates &U = I->second;
+      DeclContextInfos &Infos = DeclContextOffsets[DC];
+      DeclContextInfo Info;
+      Info.LexicalDecls = 0;
+      Info.NumLexicalDecls = 0;
+      for (DeclContextVisibleUpdates::iterator UI = U.begin(), UE = U.end();
+           UI != UE; ++UI) {
+        Info.NameLookupTableData = *UI;
+        Infos.push_back(Info);
       }
+      PendingVisibleUpdates.erase(I);
     }
   }
   assert(Idx == Record.size());

Added: cfe/trunk/test/PCH/chain-empty-initial-namespace.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/chain-empty-initial-namespace.cpp?rev=130102&view=auto
==============================================================================
--- cfe/trunk/test/PCH/chain-empty-initial-namespace.cpp (added)
+++ cfe/trunk/test/PCH/chain-empty-initial-namespace.cpp Sun Apr 24 11:27:54 2011
@@ -0,0 +1,24 @@
+// no PCH
+// RUN: %clang_cc1 -include %s -include %s -fsyntax-only %s
+// full PCH
+// RUN: %clang_cc1 -chain-include %s -chain-include %s -fsyntax-only %s
+#if !defined(PASS1)
+#define PASS1
+
+namespace foo {} // no external storage
+
+#elif !defined(PASS2)
+#define PASS2
+
+namespace foo {
+  void bar();
+}
+
+#else
+// PASS3
+
+void test() {
+  foo::bar(); // no-error
+}
+
+#endif





More information about the cfe-commits mailing list