Fix bug: instcombine/2003-10-23-InstcombineNullFail.ll

llvm-svn: 9403
This commit is contained in:
Chris Lattner 2003-10-23 05:21:48 +00:00
parent 04f1163148
commit 8a55262c76
1 changed files with 11 additions and 0 deletions

View 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);
}