diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index 26f56a7ec1d..9054cd71428 100644 --- a/lib/Linker/LinkModules.cpp +++ b/lib/Linker/LinkModules.cpp @@ -262,20 +262,19 @@ static void PrintMap(const std::map &M) { // RemapOperand - Use ValueMap to convert references from one module to another. // This is somewhat sophisticated in that it can automatically handle constant -// references correctly as well... +// references correctly as well. static Value *RemapOperand(const Value *In, std::map &ValueMap) { std::map::const_iterator I = ValueMap.find(In); if (I != ValueMap.end()) return I->second; // Check to see if it's a constant that we are interesting in transforming. + Value *Result = 0; if (const Constant *CPV = dyn_cast(In)) { if ((!isa(CPV->getType()) && !isa(CPV)) || isa(CPV)) return const_cast(CPV); // Simple constants stay identical. - Constant *Result = 0; - if (const ConstantArray *CPA = dyn_cast(CPV)) { std::vector Operands(CPA->getNumOperands()); for (unsigned i = 0, e = CPA->getNumOperands(); i != e; ++i) @@ -350,11 +349,16 @@ static Value *RemapOperand(const Value *In, } else { assert(0 && "Unknown type of derived type constant value!"); } - - // Cache the mapping in our local map structure... + } else if (isa(In)) { + Result = const_cast(In); + } + + // Cache the mapping in our local map structure... + if (Result) { ValueMap.insert(std::make_pair(In, Result)); return Result; } + std::cerr << "LinkModules ValueMap: \n"; PrintMap(ValueMap);