diff options
-rw-r--r-- | lib/VMCore/Constants.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index b755c6f913..bc1e9d2c1c 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); } |