From cfbf9faaa4f1c92a746c8681ecd3bc52ad5313e8 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 17 Oct 2004 21:54:55 +0000 Subject: [PATCH] fold gep undef, ... -> undef This comes up many times in perlbmk and probably others. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@17100 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/VMCore/ConstantFold.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp index b56366ea663..d224afefc5c 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(IdxList[0])->isNullValue())) return const_cast(C); - Constant *Idx0 = cast(IdxList[0]); + if (isa(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(IdxList[0]); if (C->isNullValue()) { bool isNull = true; for (unsigned i = 0, e = IdxList.size(); i != e; ++i)