Skip to content

Commit

Permalink
Fix a stack overflow in the assembler when checking that GEPs must be…
Browse files Browse the repository at this point in the history
… over sized types.

We failed to use a marking set to properly handle recursive types, which caused use
to recurse infinitely and eventually overflow the stack.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@231760 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
resistor committed Mar 10, 2015
1 parent 4935faa commit bb6a88c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/AsmParser/LLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2810,7 +2810,9 @@ bool LLParser::ParseValID(ValID &ID, PerFunctionState *PFS) {
}
}

if (!Indices.empty() && !BasePointerType->getElementType()->isSized())
SmallPtrSet<const Type*, 4> Visited;
if (!Indices.empty() &&
!BasePointerType->getElementType()->isSized(&Visited))
return Error(ID.Loc, "base element of getelementptr must be sized");

if (!GetElementPtrInst::getIndexedType(Elts[0]->getType(), Indices))
Expand Down Expand Up @@ -5496,7 +5498,9 @@ int LLParser::ParseGetElementPtr(Instruction *&Inst, PerFunctionState &PFS) {
Indices.push_back(Val);
}

if (!Indices.empty() && !BasePointerType->getElementType()->isSized())
SmallPtrSet<const Type*, 4> Visited;
if (!Indices.empty() &&
!BasePointerType->getElementType()->isSized(&Visited))
return Error(Loc, "base element of getelementptr must be sized");

if (!GetElementPtrInst::getIndexedType(BaseType, Indices))
Expand Down
9 changes: 9 additions & 0 deletions test/Assembler/unsized-recursive-type.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
; RUN: not llvm-as < %s 2>&1 | FileCheck %s

; CHECK: base element of getelementptr must be sized

%myTy = type { %myTy }
define void @foo(%myTy* %p){
%0 = getelementptr %myTy, %myTy* %p, i32 0
ret void
}

0 comments on commit bb6a88c

Please sign in to comment.