[cfe-commits] r146870 - in /cfe/trunk: include/clang/Serialization/ContinuousRangeMap.h lib/Serialization/ASTReader.cpp test/Modules/Inputs/redecl-merge-left.h test/Modules/redecl-merge.m

Douglas Gregor dgregor at apple.com
Mon Dec 19 08:14:14 PST 2011


Author: dgregor
Date: Mon Dec 19 10:14:14 2011
New Revision: 146870

URL: http://llvm.org/viewvc/llvm-project?rev=146870&view=rev
Log:
The submodule offset map can introduce "empty" remapping entries for
imported modules that don't introduce any new entities of a particular
kind. Allow these entries to be replaced with entries for another
loaded module.

In the included test case, selectors exhibit this behavior.


Modified:
    cfe/trunk/include/clang/Serialization/ContinuousRangeMap.h
    cfe/trunk/lib/Serialization/ASTReader.cpp
    cfe/trunk/test/Modules/Inputs/redecl-merge-left.h
    cfe/trunk/test/Modules/redecl-merge.m

Modified: cfe/trunk/include/clang/Serialization/ContinuousRangeMap.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ContinuousRangeMap.h?rev=146870&r1=146869&r2=146870&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ContinuousRangeMap.h (original)
+++ cfe/trunk/include/clang/Serialization/ContinuousRangeMap.h Mon Dec 19 10:14:14 2011
@@ -68,6 +68,16 @@
            "Must insert keys in order.");
     Rep.push_back(Val);
   }
+  
+  void insertOrReplace(const value_type &Val) {
+    iterator I = std::lower_bound(Rep.begin(), Rep.end(), Val, Compare());
+    if (I != Rep.end() && I->first == Val.first) {
+      I->second = Val.second;
+      return;
+    }
+    
+    Rep.insert(I, Val);
+  }
 
   typedef typename Representation::iterator iterator;
   typedef typename Representation::const_iterator const_iterator;

Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=146870&r1=146869&r2=146870&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Mon Dec 19 10:14:14 2011
@@ -1817,8 +1817,9 @@
         GlobalTypeMap.insert(std::make_pair(getTotalNumTypes(), &F));
         
         // Introduce the local -> global mapping for types within this module.
-        F.TypeRemap.insert(std::make_pair(LocalBaseTypeIndex, 
-                             F.BaseTypeIndex - LocalBaseTypeIndex));
+        F.TypeRemap.insertOrReplace(
+          std::make_pair(LocalBaseTypeIndex, 
+                         F.BaseTypeIndex - LocalBaseTypeIndex));
         
         TypesLoaded.resize(TypesLoaded.size() + F.LocalNumTypes);
       }
@@ -1843,8 +1844,8 @@
         
         // Introduce the local -> global mapping for declarations within this
         // module.
-        F.DeclRemap.insert(std::make_pair(LocalBaseDeclID, 
-                                          F.BaseDeclID - LocalBaseDeclID));
+        F.DeclRemap.insertOrReplace(
+          std::make_pair(LocalBaseDeclID, F.BaseDeclID - LocalBaseDeclID));
         
         // Introduce the global -> local mapping for declarations within this
         // module.
@@ -1927,9 +1928,9 @@
         
         // Introduce the local -> global mapping for identifiers within this
         // module.
-        F.IdentifierRemap.insert(
-                            std::make_pair(LocalBaseIdentifierID,
-                              F.BaseIdentifierID - LocalBaseIdentifierID));
+        F.IdentifierRemap.insertOrReplace(
+          std::make_pair(LocalBaseIdentifierID,
+                         F.BaseIdentifierID - LocalBaseIdentifierID));
         
         IdentifiersLoaded.resize(IdentifiersLoaded.size() 
                                  + F.LocalNumIdentifiers);
@@ -2004,8 +2005,9 @@
         
         // Introduce the local -> global mapping for selectors within this 
         // module.
-        F.SelectorRemap.insert(std::make_pair(LocalBaseSelectorID,
-                                 F.BaseSelectorID - LocalBaseSelectorID));
+        F.SelectorRemap.insertOrReplace(
+          std::make_pair(LocalBaseSelectorID,
+                         F.BaseSelectorID - LocalBaseSelectorID));
 
         SelectorsLoaded.resize(SelectorsLoaded.size() + F.LocalNumSelectors);        
       }
@@ -2275,7 +2277,7 @@
        
         // Introduce the local -> global mapping for preprocessed entities in
         // this module.
-        F.PreprocessedEntityRemap.insert(
+        F.PreprocessedEntityRemap.insertOrReplace(
           std::make_pair(LocalBasePreprocessedEntityID,
             F.BasePreprocessedEntityID - LocalBasePreprocessedEntityID));
       }
@@ -3184,7 +3186,7 @@
         
         // Introduce the local -> global mapping for submodules within this 
         // module.
-        F.SubmoduleRemap.insert(
+        F.SubmoduleRemap.insertOrReplace(
           std::make_pair(LocalBaseSubmoduleID,
                          F.BaseSubmoduleID - LocalBaseSubmoduleID));
         

Modified: cfe/trunk/test/Modules/Inputs/redecl-merge-left.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/redecl-merge-left.h?rev=146870&r1=146869&r2=146870&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/redecl-merge-left.h (original)
+++ cfe/trunk/test/Modules/Inputs/redecl-merge-left.h Mon Dec 19 10:14:14 2011
@@ -5,6 +5,7 @@
 @class A;
 
 @interface B
++ (B*) create_a_B;
 @end
 
 @class A;

Modified: cfe/trunk/test/Modules/redecl-merge.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/redecl-merge.m?rev=146870&r1=146869&r2=146870&view=diff
==============================================================================
--- cfe/trunk/test/Modules/redecl-merge.m (original)
+++ cfe/trunk/test/Modules/redecl-merge.m Mon Dec 19 10:14:14 2011
@@ -14,11 +14,16 @@
 
 @class A;
 
+B *f1() {
+  return [B create_a_B];
+}
+
 @class B;
 
 __import_module__ redecl_merge_bottom;
 
 @implementation B
++ (B*)create_a_B { return 0; }
 @end
 
 void g(A *a) {





More information about the cfe-commits mailing list