Fix a nasty problem where we would miss enumeration of some types. This fixes
authorChris Lattner <sabre@nondot.org>
Sun, 6 May 2007 08:35:19 +0000 (08:35 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 6 May 2007 08:35:19 +0000 (08:35 +0000)
issues with CE_CAST etc.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36864 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Bitcode/Writer/ValueEnumerator.cpp
lib/Bitcode/Writer/ValueEnumerator.h

index f5224d2a7cab8e352e52e7fb0e4237f34d558248..6b3885ed1c7fbb4e82f7ee78f5b2fe58f232a658 100644 (file)
@@ -84,7 +84,7 @@ ValueEnumerator::ValueEnumerator(const Module *M) {
       for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I!=E;++I){
         for (User::const_op_iterator OI = I->op_begin(), E = I->op_end(); 
              OI != E; ++OI)
-          EnumerateType((*OI)->getType());
+          EnumerateOperandType(*OI);
         EnumerateType(I->getType());
       }
   }
@@ -226,6 +226,22 @@ void ValueEnumerator::EnumerateType(const Type *Ty) {
     EnumerateParamAttrs(FTy->getParamAttrs());
 }
 
+// Enumerate the types for the specified value.  If the value is a constant,
+// walk through it, enumerating the types of the constant.
+void ValueEnumerator::EnumerateOperandType(const Value *V) {
+  EnumerateType(V->getType());
+  if (const Constant *C = dyn_cast<Constant>(V)) {
+    // If this constant is already enumerated, ignore it, we know its type must
+    // be enumerated.
+    if (ValueMap.count(V)) return;
+
+    // This constant may have operands, make sure to enumerate the types in
+    // them.
+    for (unsigned i = 0, e = C->getNumOperands(); i != e; ++i)
+      EnumerateOperandType(C->getOperand(i));
+  }
+}
+
 void ValueEnumerator::EnumerateParamAttrs(const ParamAttrsList *PAL) {
   if (PAL == 0) return;  // null is always 0.
   // Do a lookup.
index 1e8e8e81e1e7f332e52a253a527547e8b5a168f8..e2554115ee4ae88ca3101728514ad60f11330174 100644 (file)
@@ -114,6 +114,7 @@ private:
     
   void EnumerateValue(const Value *V);
   void EnumerateType(const Type *T);
+  void EnumerateOperandType(const Value *V);
   void EnumerateParamAttrs(const ParamAttrsList *PAL);
   
   void EnumerateTypeSymbolTable(const TypeSymbolTable &ST);