From 33f1d5b328813c986b8d083006a024e1a0c7d982 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 6 May 2007 08:35:19 +0000 Subject: [PATCH] Fix a nasty problem where we would miss enumeration of some types. This fixes 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 | 18 +++++++++++++++++- lib/Bitcode/Writer/ValueEnumerator.h | 1 + 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/Bitcode/Writer/ValueEnumerator.cpp b/lib/Bitcode/Writer/ValueEnumerator.cpp index f5224d2a7ca..6b3885ed1c7 100644 --- a/lib/Bitcode/Writer/ValueEnumerator.cpp +++ b/lib/Bitcode/Writer/ValueEnumerator.cpp @@ -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(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. diff --git a/lib/Bitcode/Writer/ValueEnumerator.h b/lib/Bitcode/Writer/ValueEnumerator.h index 1e8e8e81e1e..e2554115ee4 100644 --- a/lib/Bitcode/Writer/ValueEnumerator.h +++ b/lib/Bitcode/Writer/ValueEnumerator.h @@ -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); -- 2.34.1