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.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp
index b56366ea66..d224afefc5 100644
--- a/lib/VMCore/ConstantFold.cpp
+++ b/lib/VMCore/ConstantFold.cpp
@@ -1011,8 +1011,15 @@ Constant *llvm::ConstantFoldGetElementPtr(const Constant *C,
if (IdxList.size() == 0 ||
(IdxList.size() == 1 && cast<Constant>(IdxList[0])->isNullValue()))
return const_cast<Constant*>(C);
- Constant *Idx0 = cast<Constant>(IdxList[0]);
+ if (isa<UndefValue>(C)) {
+ const Type *Ty = GetElementPtrInst::getIndexedType(C->getType(), IdxList,
+ true);
+ assert(Ty != 0 && "Invalid indices for GEP!");
+ return UndefValue::get(PointerType::get(Ty));
+ }
+
+ Constant *Idx0 = cast<Constant>(IdxList[0]);
if (C->isNullValue()) {
bool isNull = true;
for (unsigned i = 0, e = IdxList.size(); i != e; ++i)