[cfe-commits] r147168 - in /cfe/trunk: include/clang/Serialization/ASTReader.h lib/Serialization/ASTReaderDecl.cpp test/Modules/Inputs/module.map test/Modules/Inputs/redecl-merge-bottom.h test/Modules/Inputs/redecl-merge-left-left.h test/Modules/Inputs/redecl-merge-right.h test/Modules/redecl-merge.m

Douglas Gregor dgregor at apple.com
Thu Dec 22 11:45:00 PST 2011


Author: dgregor
Date: Thu Dec 22 13:44:59 2011
New Revision: 147168

URL: http://llvm.org/viewvc/llvm-project?rev=147168&view=rev
Log:
If we end up merging an Objective-C class with an existing Objective-C
class that comes from a different module file, make sure that we load
all of the pending declarations for the original declaration.

Added:
    cfe/trunk/test/Modules/Inputs/redecl-merge-left-left.h
Modified:
    cfe/trunk/include/clang/Serialization/ASTReader.h
    cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
    cfe/trunk/test/Modules/Inputs/module.map
    cfe/trunk/test/Modules/Inputs/redecl-merge-bottom.h
    cfe/trunk/test/Modules/Inputs/redecl-merge-right.h
    cfe/trunk/test/Modules/redecl-merge.m

Modified: cfe/trunk/include/clang/Serialization/ASTReader.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTReader.h?rev=147168&r1=147167&r2=147168&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ASTReader.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTReader.h Thu Dec 22 13:44:59 2011
@@ -675,6 +675,13 @@
   /// \brief Keeps track of the elements added to PendingDeclChains.
   llvm::SmallSet<serialization::DeclID, 16> PendingDeclChainsKnown;
 
+  /// \brief Reverse mapping from declarations to their global declaration IDs.
+  /// 
+  /// FIXME: This data structure is currently only used for ObjCInterfaceDecls, 
+  /// support declaration merging. If we must have this for other declarations,
+  /// allocate it along with the Decl itself.
+  llvm::DenseMap<Decl *, serialization::GlobalDeclID> DeclToID;
+  
   typedef llvm::DenseMap<Decl *, llvm::SmallVector<serialization::DeclID, 2> >
     MergedDeclsMap;
     

Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=147168&r1=147167&r2=147168&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Thu Dec 22 13:44:59 2011
@@ -643,10 +643,13 @@
 }
 
 void ASTDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
+  // Record the declaration -> global ID mapping.
+  Reader.DeclToID[ID] = ThisDeclID;
+  
   RedeclarableResult Redecl = VisitRedeclarable(ID);
   VisitObjCContainerDecl(ID);
   TypeIDForTypeDecl = Reader.getGlobalTypeID(F, Record[Idx++]);
-  
+                  
   // Determine whether we need to merge this declaration with another @interface
   // with the same name.
   // FIXME: Not needed unless the module file graph is a DAG.
@@ -660,6 +663,18 @@
         // appropriate canonical declaration.
         ID->RedeclLink = ObjCInterfaceDecl::PreviousDeclLink(ExistingCanon);
         
+        // Don't introduce IDCanon into the set of pending declaration chains.
+        Redecl.suppress();
+        
+        // Introduce ExistingCanon into the set of pending declaration chains,
+        // if in fact it came from a module file.
+        if (ExistingCanon->isFromASTFile()) {
+          GlobalDeclID ExistingCanonID = Reader.DeclToID[ExistingCanon];
+          assert(ExistingCanonID && "Unrecorded canonical declaration ID?");
+          if (Reader.PendingDeclChainsKnown.insert(ExistingCanonID))
+            Reader.PendingDeclChains.push_back(ExistingCanonID);
+        }
+        
         // If this declaration was the canonical declaration, make a note of 
         // that.
         if (IDCanon == ID)
@@ -2192,7 +2207,6 @@
   if (Chains.empty())
     return;
     
-    
   // Capture all of the parsed declarations and put them at the end.
   Decl *MostRecent = getMostRecentDecl(CanonDecl);
   Decl *FirstParsed = MostRecent;

Modified: cfe/trunk/test/Modules/Inputs/module.map
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/module.map?rev=147168&r1=147167&r2=147168&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/module.map (original)
+++ cfe/trunk/test/Modules/Inputs/module.map Thu Dec 22 13:44:59 2011
@@ -51,6 +51,10 @@
   header "redecl-merge-left.h" 
   export *
 }
+module redecl_merge_left_left { 
+  header "redecl-merge-left-left.h" 
+  export *
+}
 module redecl_merge_right { 
   header "redecl-merge-right.h" 
   export *

Modified: cfe/trunk/test/Modules/Inputs/redecl-merge-bottom.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/redecl-merge-bottom.h?rev=147168&r1=147167&r2=147168&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/redecl-merge-bottom.h (original)
+++ cfe/trunk/test/Modules/Inputs/redecl-merge-bottom.h Thu Dec 22 13:44:59 2011
@@ -1,4 +1,7 @@
 __import_module__ redecl_merge_left;
+
+ at class C4;
+ at class C4;
 __import_module__ redecl_merge_right;
 
 @class B;

Added: cfe/trunk/test/Modules/Inputs/redecl-merge-left-left.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/redecl-merge-left-left.h?rev=147168&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/redecl-merge-left-left.h (added)
+++ cfe/trunk/test/Modules/Inputs/redecl-merge-left-left.h Thu Dec 22 13:44:59 2011
@@ -0,0 +1,5 @@
+__import_module__ redecl_merge_left;
+
+ at class C4;
+void accept_a_C4(C4*);
+

Modified: cfe/trunk/test/Modules/Inputs/redecl-merge-right.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/redecl-merge-right.h?rev=147168&r1=147167&r2=147168&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/redecl-merge-right.h (original)
+++ cfe/trunk/test/Modules/Inputs/redecl-merge-right.h Thu Dec 22 13:44:59 2011
@@ -18,6 +18,12 @@
 @class C3;
 C3 *get_a_C3(void);
 
+ at class C4;
+ at class C4;
+ at class C4;
+ at class C4;
+C4 *get_a_C4(void);
+
 @class Explicit;
 
 int *explicit_func(void);

Modified: cfe/trunk/test/Modules/redecl-merge.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/redecl-merge.m?rev=147168&r1=147167&r2=147168&view=diff
==============================================================================
--- cfe/trunk/test/Modules/redecl-merge.m (original)
+++ cfe/trunk/test/Modules/redecl-merge.m Thu Dec 22 13:44:59 2011
@@ -55,6 +55,14 @@
   accept_a_C3(c3);
 }
 
+C4 *global_C4;
+__import_module__ redecl_merge_left_left;
+
+void test_C4(C4 *c4) {
+  global_C4 = c4 = get_a_C4();
+  accept_a_C4(c4);
+}
+
 __import_module__ redecl_merge_bottom;
 
 @implementation B





More information about the cfe-commits mailing list