diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp index 5167c12d49b..25c756ab6e5 100644 --- a/lib/VMCore/ConstantFold.cpp +++ b/lib/VMCore/ConstantFold.cpp @@ -238,9 +238,12 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V, std::vector res; const VectorType *DestVecTy = cast(DestTy); const Type *DstEltTy = DestVecTy->getElementType(); - for (unsigned i = 0, e = CV->getType()->getNumElements(); i != e; ++i) - res.push_back(ConstantFoldCastInstruction(opc, V->getOperand(i), - DstEltTy)); + for (unsigned i = 0, e = CV->getType()->getNumElements(); i != e; ++i) { + Constant *C = ConstantFoldCastInstruction(opc, CV->getOperand(i), + DstEltTy); + if (!C) return 0; // Can't fold operand. + res.push_back(C); + } return ConstantVector::get(DestVecTy, res); } return 0; // Can't fold. @@ -268,9 +271,12 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V, std::vector res; const VectorType *DestVecTy = cast(DestTy); const Type *DstEltTy = DestVecTy->getElementType(); - for (unsigned i = 0, e = CV->getType()->getNumElements(); i != e; ++i) - res.push_back(ConstantFoldCastInstruction(opc, V->getOperand(i), - DstEltTy)); + for (unsigned i = 0, e = CV->getType()->getNumElements(); i != e; ++i) { + Constant *C = ConstantFoldCastInstruction(opc, CV->getOperand(i), + DstEltTy); + if (!C) return 0; // Can't fold operand. + res.push_back(C); + } return ConstantVector::get(DestVecTy, res); } return 0; diff --git a/test/Transforms/InstCombine/2008-09-02-VectorCrash.ll b/test/Transforms/InstCombine/2008-09-02-VectorCrash.ll new file mode 100644 index 00000000000..4b5dc6a5dfc --- /dev/null +++ b/test/Transforms/InstCombine/2008-09-02-VectorCrash.ll @@ -0,0 +1,27 @@ +; RUN: llvm-as < %s | opt -instcombine + +define void @entry(i32 %m_task_id, i32 %start_x, i32 %end_x, i32 %start_y, i32 %end_y) { + br label %1 + +;