Skip to content

Commit

Permalink
Fix a bug in the LLParser where we failed to diagnose landingpads wit…
Browse files Browse the repository at this point in the history
…h non-constant clause operands.

Fixing this also exposed a related issue where the landingpad under construction was not
cleaned up when an error was raised, which would cause bad reference errors before the
error could actually be printed.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@231634 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
resistor committed Mar 9, 2015
1 parent 40e6627 commit 8e120d8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/AsmParser/LLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5041,7 +5041,7 @@ bool LLParser::ParseLandingPad(Instruction *&Inst, PerFunctionState &PFS) {
ParseTypeAndValue(PersFn, PersFnLoc, PFS))
return true;

LandingPadInst *LP = LandingPadInst::Create(Ty, PersFn, 0);
std::unique_ptr<LandingPadInst> LP(LandingPadInst::Create(Ty, PersFn, 0));
LP->setCleanup(EatIfPresent(lltok::kw_cleanup));

while (Lex.getKind() == lltok::kw_catch || Lex.getKind() == lltok::kw_filter){
Expand All @@ -5055,10 +5055,8 @@ bool LLParser::ParseLandingPad(Instruction *&Inst, PerFunctionState &PFS) {

Value *V;
LocTy VLoc;
if (ParseTypeAndValue(V, VLoc, PFS)) {
delete LP;
if (ParseTypeAndValue(V, VLoc, PFS))
return true;
}

// A 'catch' type expects a non-array constant. A filter clause expects an
// array constant.
Expand All @@ -5070,10 +5068,13 @@ bool LLParser::ParseLandingPad(Instruction *&Inst, PerFunctionState &PFS) {
Error(VLoc, "'filter' clause has an invalid type");
}

LP->addClause(cast<Constant>(V));
Constant *CV = dyn_cast<Constant>(V);
if (!CV)
return Error(VLoc, "clause argument must be a constant");
LP->addClause(CV);
}

Inst = LP;
Inst = LP.release();
return false;
}

Expand Down
7 changes: 7 additions & 0 deletions test/Assembler/invalid-landingpad.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
; RUN: not llvm-as < %s 2>&1 | FileCheck %s

; CHECK: clause argument must be a constant

define void @test(i32 %in) {
landingpad {} personality void()* null filter i32 %in
}

0 comments on commit 8e120d8

Please sign in to comment.