[cfe-commits] r111882 - in /cfe/trunk: lib/Serialization/ASTReader.cpp lib/Serialization/ASTWriter.cpp test/PCH/Inputs/chain-cxx1.h test/PCH/Inputs/chain-cxx2.h test/PCH/chain-cxx.cpp

Sebastian Redl sebastian.redl at getdesigned.at
Mon Aug 23 17:50:16 PDT 2010


Author: cornedbee
Date: Mon Aug 23 19:50:16 2010
New Revision: 111882

URL: http://llvm.org/viewvc/llvm-project?rev=111882&view=rev
Log:
Add testcase for C++ chained PCH and fix the bugs it uncovered in name lookup.

Added:
    cfe/trunk/test/PCH/Inputs/chain-cxx1.h
    cfe/trunk/test/PCH/Inputs/chain-cxx2.h
    cfe/trunk/test/PCH/chain-cxx.cpp
Modified:
    cfe/trunk/lib/Serialization/ASTReader.cpp
    cfe/trunk/lib/Serialization/ASTWriter.cpp

Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=111882&r1=111881&r2=111882&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Mon Aug 23 19:50:16 2010
@@ -3192,9 +3192,10 @@
 
   llvm::SmallVector<NamedDecl *, 64> Decls;
   // There might be visible decls in multiple parts of the chain, for the TU
-  // and namespaces.
+  // and namespaces. For any given name, the last available results replace
+  // all earlier ones. For this reason, we walk in reverse.
   DeclContextInfos &Infos = DeclContextOffsets[DC];
-  for (DeclContextInfos::iterator I = Infos.begin(), E = Infos.end();
+  for (DeclContextInfos::reverse_iterator I = Infos.rbegin(), E = Infos.rend();
        I != E; ++I) {
     if (!I->NameLookupTableData)
       continue;
@@ -3208,6 +3209,7 @@
     ASTDeclContextNameLookupTrait::data_type Data = *Pos;
     for (; Data.first != Data.second; ++Data.first)
       Decls.push_back(cast<NamedDecl>(GetDecl(*Data.first)));
+    break;
   }
 
   ++NumVisibleDeclContextsRead;

Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=111882&r1=111881&r2=111882&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Mon Aug 23 19:50:16 2010
@@ -2101,23 +2101,13 @@
   ASTDeclContextNameLookupTrait Trait(*this);
 
   // Create the hash table.
-  llvm::SmallVector<NamedDecl *, 16> Decls;
   for (StoredDeclsMap::iterator D = Map->begin(), DEnd = Map->end();
        D != DEnd; ++D) {
     DeclarationName Name = D->first;
     DeclContext::lookup_result Result = D->second.getLookupResult();
-    // Need to filter these results to only include decls that are not from
-    // an existing PCH.
-    Decls.clear();
-    for (; Result.first != Result.second; ++Result.first) {
-      if ((*Result.first)->getPCHLevel() == 0)
-        Decls.push_back(*Result.first);
-    }
-    if (!Decls.empty()) {
-      Result.first = Decls.data();
-      Result.second = Result.first + Decls.size();
-      Generator.insert(Name, Result, Trait);
-    }
+    // For any name that appears in this table, the results are complete, i.e.
+    // they overwrite results from previous PCHs. Merging is always a mess.
+    Generator.insert(Name, Result, Trait);
   }
 
   // Create the on-disk hash table in a buffer.

Added: cfe/trunk/test/PCH/Inputs/chain-cxx1.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/Inputs/chain-cxx1.h?rev=111882&view=auto
==============================================================================
--- cfe/trunk/test/PCH/Inputs/chain-cxx1.h (added)
+++ cfe/trunk/test/PCH/Inputs/chain-cxx1.h Mon Aug 23 19:50:16 2010
@@ -0,0 +1,15 @@
+// Primary header for C++ chained PCH test
+
+void f();
+
+// Name not appearing in dependent
+void pf();
+
+namespace ns {
+  void g();
+
+  void pg();
+}
+
+template <typename T>
+struct S {};

Added: cfe/trunk/test/PCH/Inputs/chain-cxx2.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/Inputs/chain-cxx2.h?rev=111882&view=auto
==============================================================================
--- cfe/trunk/test/PCH/Inputs/chain-cxx2.h (added)
+++ cfe/trunk/test/PCH/Inputs/chain-cxx2.h Mon Aug 23 19:50:16 2010
@@ -0,0 +1,20 @@
+// Dependent header for C++ chained PCH test
+
+// Overload function from primary
+void f(int);
+
+// Add function with different name
+void f2();
+
+// Reopen namespace
+namespace ns {
+  // Overload function from primary
+  void g(int);
+
+  // Add different name
+  void g2();
+}
+
+// Specialize template from primary
+template <>
+struct S<int> { typedef int I; };

Added: cfe/trunk/test/PCH/chain-cxx.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/chain-cxx.cpp?rev=111882&view=auto
==============================================================================
--- cfe/trunk/test/PCH/chain-cxx.cpp (added)
+++ cfe/trunk/test/PCH/chain-cxx.cpp Mon Aug 23 19:50:16 2010
@@ -0,0 +1,23 @@
+// Test C++ chained PCH functionality
+
+// Without PCH
+// RUN: %clang_cc1 -fsyntax-only -verify -include %S/Inputs/chain-cxx1.h -include %S/Inputs/chain-cxx2.h %s
+
+// With PCH
+// RUN: %clang_cc1 -x c++ -emit-pch -o %t1 %S/Inputs/chain-cxx1.h
+// RUN: %clang_cc1 -x c++ -emit-pch -o %t2 %S/Inputs/chain-cxx2.h -include-pch %t1 -chained-pch
+// RUN: %clang_cc1 -fsyntax-only -verify -include-pch %t2 %s
+
+void test() {
+  f();
+  f(1);
+  pf();
+  f2();
+
+  ns::g();
+  ns::g(1);
+  ns::pg();
+  ns::g2();
+
+  //typedef S<int>::I J;
+}





More information about the cfe-commits mailing list