Skip to content

Commit

Permalink
Fix for PR 14965: Better error message for GEP with partially defined…
Browse files Browse the repository at this point in the history
… contents

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@180030 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
eliben committed Apr 22, 2013
1 parent 4402151 commit 59eb5ee
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/AsmParser/LLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4263,7 +4263,9 @@ int LLParser::ParseGetElementPtr(Instruction *&Inst, PerFunctionState &PFS) {

if (ParseTypeAndValue(Ptr, Loc, PFS)) return true;

if (!Ptr->getType()->getScalarType()->isPointerTy())
Type *BaseType = Ptr->getType();
PointerType *BasePointerType = dyn_cast<PointerType>(BaseType->getScalarType());
if (!BasePointerType)
return Error(Loc, "base of getelementptr must be a pointer");

SmallVector<Value*, 16> Indices;
Expand All @@ -4288,7 +4290,10 @@ int LLParser::ParseGetElementPtr(Instruction *&Inst, PerFunctionState &PFS) {
Indices.push_back(Val);
}

if (!GetElementPtrInst::getIndexedType(Ptr->getType(), Indices))
if (!Indices.empty() && !BasePointerType->getElementType()->isSized())
return Error(Loc, "base element of getelementptr must be sized");

if (!GetElementPtrInst::getIndexedType(BaseType, Indices))
return Error(Loc, "invalid getelementptr indices");
Inst = GetElementPtrInst::Create(Ptr, Indices);
if (InBounds)
Expand Down

0 comments on commit 59eb5ee

Please sign in to comment.