summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Scalar/SCCP.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Transforms/Scalar/SCCP.cpp')
-rw-r--r--llvm/lib/Transforms/Scalar/SCCP.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/Scalar/SCCP.cpp b/llvm/lib/Transforms/Scalar/SCCP.cpp
index 4e5e5156bb7..8304e2e823b 100644
--- a/llvm/lib/Transforms/Scalar/SCCP.cpp
+++ b/llvm/lib/Transforms/Scalar/SCCP.cpp
@@ -689,14 +689,16 @@ static Constant *GetGEPGlobalInitializer(Constant *C, ConstantExpr *CE) {
// addressing...
for (unsigned i = 2, e = CE->getNumOperands(); i != e; ++i)
if (ConstantUInt *CU = dyn_cast<ConstantUInt>(CE->getOperand(i))) {
- ConstantStruct *CS = cast<ConstantStruct>(C);
+ ConstantStruct *CS = dyn_cast<ConstantStruct>(C);
+ if (CS == 0) return 0;
if (CU->getValue() >= CS->getValues().size()) return 0;
C = cast<Constant>(CS->getValues()[CU->getValue()]);
} else if (ConstantSInt *CS = dyn_cast<ConstantSInt>(CE->getOperand(i))) {
- ConstantArray *CA = cast<ConstantArray>(C);
+ ConstantArray *CA = dyn_cast<ConstantArray>(C);
+ if (CA == 0) return 0;
if ((uint64_t)CS->getValue() >= CA->getValues().size()) return 0;
C = cast<Constant>(CA->getValues()[CS->getValue()]);
- } else
+ } else
return 0;
return C;
}
OpenPOWER on IntegriCloud