[cfe-commits] r136693 - in /cfe/trunk: include/clang/Serialization/ASTBitCodes.h include/clang/Serialization/ASTReader.h include/clang/Serialization/ContinuousRangeMap.h lib/Serialization/ASTReader.cpp lib/Serialization/ASTWriter.cpp

Douglas Gregor dgregor at apple.com
Tue Aug 2 11:38:15 PDT 2011


On Aug 2, 2011, at 9:26 AM, Douglas Gregor wrote:

> Author: dgregor
> Date: Tue Aug  2 11:26:37 2011
> New Revision: 136693
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=136693&view=rev
> Log:
> Implement a proper local -> global type ID remapping scheme in the AST
> reader. This scheme permits an AST file to be loaded with its type IDs
> shifted anywhere in the type ID space. 
> 
> At present, the type indices are still allocated in the same boring
> way they always have been, just by adding up the number of types in
> each PCH file within the chain. However, I've done testing with this
> patch by randomly sliding the base indices at load time, to ensure
> that remapping is occurring as expected. I may eventually formalize
> this in some testing flag, but loading multiple (non-chained) AST
> files at once will eventually exercise the same code.

For those following along at home, here's how I tweak the AST reader to perform random sliding of type IDs at load time:

Index: lib/Serialization/ASTReader.cpp
===================================================================
--- lib/Serialization/ASTReader.cpp	(revision 136708)
+++ lib/Serialization/ASTReader.cpp	(working copy)
@@ -2053,7 +2053,8 @@
       F.TypeOffsets = (const uint32_t *)BlobStart;
       F.LocalNumTypes = Record[0];
       unsigned LocalBaseTypeIndex = Record[1];
-      F.BaseTypeIndex = getTotalNumTypes();
+      unsigned FudgeFactor = 17 + rand() % 17;
+      F.BaseTypeIndex = getTotalNumTypes() + FudgeFactor;
         
       if (F.LocalNumTypes > 0) {
         // Introduce the global -> local mapping for types within this module.
@@ -2063,7 +2064,7 @@
         F.TypeRemap.insert(std::make_pair(LocalBaseTypeIndex, 
                              F.BaseTypeIndex - LocalBaseTypeIndex));
         
-        TypesLoaded.resize(TypesLoaded.size() + F.LocalNumTypes);
+        TypesLoaded.resize(TypesLoaded.size() + F.LocalNumTypes + FudgeFactor);
       }
       break;
     }


	- Doug



More information about the cfe-commits mailing list