From: Chris Lattner Date: Thu, 23 Oct 2003 05:21:48 +0000 (+0000) Subject: Fix bug: instcombine/2003-10-23-InstcombineNullFail.ll X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=653de272c21eb532294a3a3c6a39ebfd15165ee5;p=oota-llvm.git Fix bug: instcombine/2003-10-23-InstcombineNullFail.ll git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@9403 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index b755c6f913a..bc1e9d2c1c8 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -975,6 +975,17 @@ Constant *ConstantExpr::getGetElementPtr(Constant *C, const Type *Ty = GetElementPtrInst::getIndexedType(C->getType(), VIdxList, true); assert(Ty && "GEP indices invalid!"); + + if (C->isNullValue()) { + bool isNull = true; + for (unsigned i = 0, e = IdxList.size(); i != e; ++i) + if (!IdxList[i]->isNullValue()) { + isNull = false; + break; + } + if (isNull) return ConstantPointerNull::get(PointerType::get(Ty)); + } + return getGetElementPtrTy(PointerType::get(Ty), C, IdxList); }