aboutsummaryrefslogtreecommitdiff
path: root/lib/VMCore/ConstantFold.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/VMCore/ConstantFold.cpp')
-rw-r--r--lib/VMCore/ConstantFold.cpp18
1 files changed, 12 insertions, 6 deletions
diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp
index 5167c12d49..25c756ab6e 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<Constant*> res;
const VectorType *DestVecTy = cast<VectorType>(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<Constant*> res;
const VectorType *DestVecTy = cast<VectorType>(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;