]> granicus.if.org Git - clang/commitdiff
Only those InterestingDecls that got added to the AST should be passed to the ASTCons...
authorAxel Naumann <Axel.Naumann@cern.ch>
Tue, 2 Oct 2012 12:18:46 +0000 (12:18 +0000)
committerAxel Naumann <Axel.Naumann@cern.ch>
Tue, 2 Oct 2012 12:18:46 +0000 (12:18 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@165001 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Serialization/ASTReader.h
lib/Serialization/ASTReader.cpp
lib/Serialization/ASTReaderDecl.cpp
test/Modules/Inputs/templates-left.h
test/Modules/Inputs/templates-right.h
test/Modules/templates.mm

index e87c93fbecefbeb1a9013db3bc538030db72e8b8..a3abce11684e257bf57124b256bce8ac3024abec 100644 (file)
@@ -687,6 +687,12 @@ private:
   /// Objective-C protocols.
   std::deque<Decl *> InterestingDecls;
 
+  /// \brief Redecls that have been added to the AST
+  ///
+  /// Redecls that are deserialized but not in RedeclsAddedToAST must
+  /// not be passed to the ASTConsumers, even if they are InterestignDecls.
+  llvm::SmallPtrSet<Decl *, 16> RedeclsAddedToAST;
+
   /// \brief The set of redeclarable declarations that have been deserialized
   /// since the last time the declaration chains were linked.
   llvm::SmallPtrSet<Decl *, 16> RedeclsDeserialized;
index a897d868e45045bf8316f935adb2885cd83220a2..c5153b567291476b95316ae1bb1abb8d8c3183b3 100644 (file)
@@ -6509,4 +6509,5 @@ ASTReader::~ASTReader() {
          J != F; ++J)
       delete J->first;
   }
+  assert(RedeclsAddedToAST.empty() && "RedeclsAddedToAST not empty!");
 }
index 85740de15b564dc898e4b9c50d776c9e1e865415..e770c0651990e02da781c7b7b315985505dd5f00 100644 (file)
@@ -1777,9 +1777,11 @@ ASTDeclReader::FindExistingResult::~FindExistingResult() {
   
   DeclContext *DC = New->getDeclContext()->getRedeclContext();
   if (DC->isTranslationUnit() && Reader.SemaObj) {
-    Reader.SemaObj->IdResolver.tryAddTopLevelDecl(New, New->getDeclName());
+    if (Reader.SemaObj->IdResolver.tryAddTopLevelDecl(New, New->getDeclName()))
+      Reader.RedeclsAddedToAST.insert(New);
   } else if (DC->isNamespace()) {
     DC->addDecl(New);
+    Reader.RedeclsAddedToAST.insert(New);
   }
 }
 
@@ -2154,7 +2156,13 @@ Decl *ASTReader::ReadDeclRecord(DeclID ID) {
   // AST consumer might need to know about, queue it.
   // We don't pass it to the consumer immediately because we may be in recursive
   // loading, and some declarations may still be initializing.
-  if (isConsumerInterestedIn(D))
+  if (getContext().getLangOpts().Modules) {
+    if (RedeclsAddedToAST.count(D)) {
+      RedeclsAddedToAST.erase(D);
+      if (isConsumerInterestedIn(D))
+        InterestingDecls.push_back(D);
+    }
+  } else if (isConsumerInterestedIn(D))
     InterestingDecls.push_back(D);
 
   return D;
index 7f50cd4c4f9351e7167584640033c2c4bf79819c..57a8c85bf602ba1251ffc04c03be0eec9828cb01 100644 (file)
@@ -20,8 +20,10 @@ namespace N {
 }
 
 template <typename T>
-void pendingInstantiation(T) {}
+void pendingInstantiationEmit(T) {}
 void triggerPendingInstantiation() {
-  pendingInstantiation(12);
-  pendingInstantiation(42.);
+  pendingInstantiationEmit(12);
+  pendingInstantiationEmit(42.);
 }
+
+void redeclDefinitionEmit(){}
index f5487fb0e127edbaa8d4e32be1338959d2d24bc5..4ef4a32e8e276584539c34a1720fe9fff91d3489 100644 (file)
@@ -19,7 +19,9 @@ namespace N {
 }
 
 template <typename T>
-void pendingInstantiation(T) {}
+void pendingInstantiationEmit(T) {}
 void triggerPendingInstantiationToo() {
-  pendingInstantiation(12);
+  pendingInstantiationEmit(12);
 }
+
+void redeclDefinitionEmit(){}
index a9b45913c7550b11d3cd43bf026e7e5750919fa5..e2d762c11e53cfc7cb12e9e5bebd8751c6868c09 100644 (file)
@@ -1,6 +1,6 @@
 // RUN: rm -rf %t
 // RUN: %clang_cc1 -x objective-c++ -fmodules -fmodule-cache-path %t -I %S/Inputs -verify %s -Wno-objc-root-class
-// RUN: %clang_cc1 -x objective-c++ -fmodules -fmodule-cache-path %t -I %S/Inputs -emit-llvm %s -o - -Wno-objc-root-class | grep pendingInstantiation | FileCheck %s
+// RUN: %clang_cc1 -x objective-c++ -fmodules -fmodule-cache-path %t -I %S/Inputs -emit-llvm %s -o - -Wno-objc-root-class | grep Emit | FileCheck %s
 
 @__experimental_modules_import templates_left;
 @__experimental_modules_import templates_right;
@@ -18,11 +18,18 @@ void testTemplateClasses() {
 }
 
 void testPendingInstantiations() {
-  // CHECK: call
-  // CHECK: call
-  // CHECK: {{define .*pendingInstantiation.*[(]i}}
-  // CHECK: {{define .*pendingInstantiation.*[(]double}}
-  // CHECK: call
+  // CHECK: call {{.*pendingInstantiationEmit}}
+  // CHECK: call {{.*pendingInstantiationEmit}}
+  // CHECK: define {{.*pendingInstantiationEmit.*[(]i}}
+  // CHECK: define {{.*pendingInstantiationEmit.*[(]double}}
   triggerPendingInstantiation();
   triggerPendingInstantiationToo();
 }
+
+void testRedeclDefinition() {
+  // CHECK: define {{.*redeclDefinitionEmit}}
+  redeclDefinitionEmit();
+}
+
+// CHECK: call {{.*pendingInstantiation}}
+// CHECK: call {{.*redeclDefinitionEmit}}