diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index 21e25b444a1..beab3d5a847 100644 --- a/lib/Linker/LinkModules.cpp +++ b/lib/Linker/LinkModules.cpp @@ -118,7 +118,16 @@ static Value *RemapOperand(const Value *In, map &LocalMap, Value *V = RemapOperand(CPR->getValue(), LocalMap, GlobalMap); Result = ConstantPointerRef::get(cast(V)); } else if (const ConstantExpr *CE = dyn_cast(CPV)) { - if (CE->getNumOperands() == 1) { + if (CE->getOpcode() == Instruction::GetElementPtr) { + Value *Ptr = RemapOperand(CE->getOperand(0), LocalMap, GlobalMap); + std::vector Indices; + Indices.reserve(CE->getNumOperands()-1); + for (unsigned i = 1, e = CE->getNumOperands(); i != e; ++i) + Indices.push_back(cast(RemapOperand(CE->getOperand(i), + LocalMap, GlobalMap))); + + Result = ConstantExpr::getGetElementPtr(cast(Ptr), Indices); + } else if (CE->getNumOperands() == 1) { // Cast instruction assert(CE->getOpcode() == Instruction::Cast); Value *V = RemapOperand(CE->getOperand(0), LocalMap, GlobalMap); @@ -131,16 +140,7 @@ static Value *RemapOperand(const Value *In, map &LocalMap, Result = ConstantExpr::get(CE->getOpcode(), cast(V1), cast(V2)); } else { - // GetElementPtr Expression - assert(CE->getOpcode() == Instruction::GetElementPtr); - Value *Ptr = RemapOperand(CE->getOperand(0), LocalMap, GlobalMap); - std::vector Indices; - Indices.reserve(CE->getNumOperands()-1); - for (unsigned i = 1, e = CE->getNumOperands(); i != e; ++i) - Indices.push_back(cast(RemapOperand(CE->getOperand(i), - LocalMap, GlobalMap))); - - Result = ConstantExpr::getGetElementPtr(cast(Ptr), Indices); + assert(0 && "Unknown constant expr type!"); } } else { diff --git a/lib/Transforms/Utils/Linker.cpp b/lib/Transforms/Utils/Linker.cpp index 21e25b444a1..beab3d5a847 100644 --- a/lib/Transforms/Utils/Linker.cpp +++ b/lib/Transforms/Utils/Linker.cpp @@ -118,7 +118,16 @@ static Value *RemapOperand(const Value *In, map &LocalMap, Value *V = RemapOperand(CPR->getValue(), LocalMap, GlobalMap); Result = ConstantPointerRef::get(cast(V)); } else if (const ConstantExpr *CE = dyn_cast(CPV)) { - if (CE->getNumOperands() == 1) { + if (CE->getOpcode() == Instruction::GetElementPtr) { + Value *Ptr = RemapOperand(CE->getOperand(0), LocalMap, GlobalMap); + std::vector Indices; + Indices.reserve(CE->getNumOperands()-1); + for (unsigned i = 1, e = CE->getNumOperands(); i != e; ++i) + Indices.push_back(cast(RemapOperand(CE->getOperand(i), + LocalMap, GlobalMap))); + + Result = ConstantExpr::getGetElementPtr(cast(Ptr), Indices); + } else if (CE->getNumOperands() == 1) { // Cast instruction assert(CE->getOpcode() == Instruction::Cast); Value *V = RemapOperand(CE->getOperand(0), LocalMap, GlobalMap); @@ -131,16 +140,7 @@ static Value *RemapOperand(const Value *In, map &LocalMap, Result = ConstantExpr::get(CE->getOpcode(), cast(V1), cast(V2)); } else { - // GetElementPtr Expression - assert(CE->getOpcode() == Instruction::GetElementPtr); - Value *Ptr = RemapOperand(CE->getOperand(0), LocalMap, GlobalMap); - std::vector Indices; - Indices.reserve(CE->getNumOperands()-1); - for (unsigned i = 1, e = CE->getNumOperands(); i != e; ++i) - Indices.push_back(cast(RemapOperand(CE->getOperand(i), - LocalMap, GlobalMap))); - - Result = ConstantExpr::getGetElementPtr(cast(Ptr), Indices); + assert(0 && "Unknown constant expr type!"); } } else { diff --git a/lib/VMCore/Linker.cpp b/lib/VMCore/Linker.cpp index 21e25b444a1..beab3d5a847 100644 --- a/lib/VMCore/Linker.cpp +++ b/lib/VMCore/Linker.cpp @@ -118,7 +118,16 @@ static Value *RemapOperand(const Value *In, map &LocalMap, Value *V = RemapOperand(CPR->getValue(), LocalMap, GlobalMap); Result = ConstantPointerRef::get(cast(V)); } else if (const ConstantExpr *CE = dyn_cast(CPV)) { - if (CE->getNumOperands() == 1) { + if (CE->getOpcode() == Instruction::GetElementPtr) { + Value *Ptr = RemapOperand(CE->getOperand(0), LocalMap, GlobalMap); + std::vector Indices; + Indices.reserve(CE->getNumOperands()-1); + for (unsigned i = 1, e = CE->getNumOperands(); i != e; ++i) + Indices.push_back(cast(RemapOperand(CE->getOperand(i), + LocalMap, GlobalMap))); + + Result = ConstantExpr::getGetElementPtr(cast(Ptr), Indices); + } else if (CE->getNumOperands() == 1) { // Cast instruction assert(CE->getOpcode() == Instruction::Cast); Value *V = RemapOperand(CE->getOperand(0), LocalMap, GlobalMap); @@ -131,16 +140,7 @@ static Value *RemapOperand(const Value *In, map &LocalMap, Result = ConstantExpr::get(CE->getOpcode(), cast(V1), cast(V2)); } else { - // GetElementPtr Expression - assert(CE->getOpcode() == Instruction::GetElementPtr); - Value *Ptr = RemapOperand(CE->getOperand(0), LocalMap, GlobalMap); - std::vector Indices; - Indices.reserve(CE->getNumOperands()-1); - for (unsigned i = 1, e = CE->getNumOperands(); i != e; ++i) - Indices.push_back(cast(RemapOperand(CE->getOperand(i), - LocalMap, GlobalMap))); - - Result = ConstantExpr::getGetElementPtr(cast(Ptr), Indices); + assert(0 && "Unknown constant expr type!"); } } else {