Fix bug: instcombine/2003-10-23-InstcombineNullFail.ll
authorChris Lattner <sabre@nondot.org>
Thu, 23 Oct 2003 05:21:48 +0000 (05:21 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 23 Oct 2003 05:21:48 +0000 (05:21 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@9403 91177308-0d34-0410-b5e6-96231b3b80d8

lib/VMCore/Constants.cpp

index b755c6f913a9699dc4203349823e12f81233b716..bc1e9d2c1c80ad4d5a3ea320c73bec9de34f2213 100644 (file)
@@ -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);
 }