diff options
author | Owen Anderson <resistor@mac.com> | 2015-03-09 07:13:42 +0000 |
---|---|---|
committer | Owen Anderson <resistor@mac.com> | 2015-03-09 07:13:42 +0000 |
commit | f8f259df48d3af96b06b50b14cc08e7e72b028ce (patch) | |
tree | 3e610fe89b659ce693e095329c3d87f5bfd1d43c | |
parent | 6e084ccda3ac4f4e817036ca2df734f3bc1133f4 (diff) | |
download | bcm5719-llvm-f8f259df48d3af96b06b50b14cc08e7e72b028ce.tar.gz bcm5719-llvm-f8f259df48d3af96b06b50b14cc08e7e72b028ce.zip |
Fix a bug in the LLParser where we failed to diagnose landingpads with 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.
llvm-svn: 231634
-rw-r--r-- | llvm/lib/AsmParser/LLParser.cpp | 13 | ||||
-rw-r--r-- | llvm/test/Assembler/invalid-landingpad.ll | 7 |
2 files changed, 14 insertions, 6 deletions
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp index a07a109cf66..67d74c0c121 100644 --- a/llvm/lib/AsmParser/LLParser.cpp +++ b/llvm/lib/AsmParser/LLParser.cpp @@ -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){ @@ -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. @@ -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; } diff --git a/llvm/test/Assembler/invalid-landingpad.ll b/llvm/test/Assembler/invalid-landingpad.ll new file mode 100644 index 00000000000..c8eab4ac6ae --- /dev/null +++ b/llvm/test/Assembler/invalid-landingpad.ll @@ -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 +} |