summaryrefslogtreecommitdiffstats
path: root/llvm/lib/VMCore/ConstantFold.cpp
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2008-09-03 05:54:33 +0000
committerNick Lewycky <nicholas@mxc.ca>2008-09-03 05:54:33 +0000
commitf023db644492337f13d36cad3cbce12f76d8113f (patch)
treebbf4530f408a97f6ab9f9bf58a4da171cd5185f3 /llvm/lib/VMCore/ConstantFold.cpp
parent1b9e10390bbaa39d852592959dad44e025138a39 (diff)
downloadbcm5719-llvm-f023db644492337f13d36cad3cbce12f76d8113f.tar.gz
bcm5719-llvm-f023db644492337f13d36cad3cbce12f76d8113f.zip
Don't crash when trying to constant fold a vector with some elements that can't
be folded. Instead, fail to fold the entire vector. We could also return a vector with some elements folded and some not. If anyone thinks that's a better approach, please speak up! llvm-svn: 55689
Diffstat (limited to 'llvm/lib/VMCore/ConstantFold.cpp')
-rw-r--r--llvm/lib/VMCore/ConstantFold.cpp18
1 files changed, 12 insertions, 6 deletions
diff --git a/llvm/lib/VMCore/ConstantFold.cpp b/llvm/lib/VMCore/ConstantFold.cpp
index 5167c12d49b..25c756ab6e5 100644
--- a/llvm/lib/VMCore/ConstantFold.cpp
+++ b/llvm/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;
OpenPOWER on IntegriCloud