From dcac1523c0db69547fe0f929690875ef23299a9a Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Wed, 4 Jun 2014 18:51:31 +0000 Subject: [PATCH] Clauses in a landingpad are always Constant. Use a stricter type. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210203 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/IR/Instructions.h | 12 +++++++----- lib/AsmParser/LLParser.cpp | 5 +++-- lib/Bitcode/Reader/BitcodeReader.cpp | 2 +- lib/IR/Instructions.cpp | 2 +- lib/IR/Verifier.cpp | 3 +-- lib/Transforms/InstCombine/InstructionCombining.cpp | 8 ++++---- 6 files changed, 17 insertions(+), 15 deletions(-) diff --git a/include/llvm/IR/Instructions.h b/include/llvm/IR/Instructions.h index 7d338a68f54..c6709f44592 100644 --- a/include/llvm/IR/Instructions.h +++ b/include/llvm/IR/Instructions.h @@ -2311,12 +2311,14 @@ public: (V ? 1 : 0)); } - /// addClause - Add a catch or filter clause to the landing pad. - void addClause(Value *ClauseVal); + /// Add a catch or filter clause to the landing pad. + void addClause(Constant *ClauseVal); - /// getClause - Get the value of the clause at index Idx. Use isCatch/isFilter - /// to determine what type of clause this is. - Value *getClause(unsigned Idx) const { return OperandList[Idx + 1]; } + /// Get the value of the clause at index Idx. Use isCatch/isFilter to + /// determine what type of clause this is. + Constant *getClause(unsigned Idx) const { + return cast(OperandList[Idx + 1]); + } /// isCatch - Return 'true' if the clause and index Idx is a catch clause. bool isCatch(unsigned Idx) const { diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp index ef9b34ca47a..cbb72ef0125 100644 --- a/lib/AsmParser/LLParser.cpp +++ b/lib/AsmParser/LLParser.cpp @@ -3991,7 +3991,8 @@ bool LLParser::ParseLandingPad(Instruction *&Inst, PerFunctionState &PFS) { else return TokError("expected 'catch' or 'filter' clause type"); - Value *V; LocTy VLoc; + Value *V; + LocTy VLoc; if (ParseTypeAndValue(V, VLoc, PFS)) { delete LP; return true; @@ -4007,7 +4008,7 @@ bool LLParser::ParseLandingPad(Instruction *&Inst, PerFunctionState &PFS) { Error(VLoc, "'filter' clause has an invalid type"); } - LP->addClause(V); + LP->addClause(cast(V)); } Inst = LP; diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index 322879b5666..7b018a6b655 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/lib/Bitcode/Reader/BitcodeReader.cpp @@ -2826,7 +2826,7 @@ error_code BitcodeReader::ParseFunctionBody(Function *F) { assert((CT != LandingPadInst::Filter || isa(Val->getType())) && "Filter clause has invalid type!"); - LP->addClause(Val); + LP->addClause(cast(Val)); } I = LP; diff --git a/lib/IR/Instructions.cpp b/lib/IR/Instructions.cpp index 13c51b817c0..592cdd85e87 100644 --- a/lib/IR/Instructions.cpp +++ b/lib/IR/Instructions.cpp @@ -248,7 +248,7 @@ void LandingPadInst::growOperands(unsigned Size) { Use::zap(OldOps, OldOps + e, true); } -void LandingPadInst::addClause(Value *Val) { +void LandingPadInst::addClause(Constant *Val) { unsigned OpNo = getNumOperands(); growOperands(1); assert(OpNo < ReservedSpace && "Growing didn't work!"); diff --git a/lib/IR/Verifier.cpp b/lib/IR/Verifier.cpp index 1719cb27590..6da8014a22d 100644 --- a/lib/IR/Verifier.cpp +++ b/lib/IR/Verifier.cpp @@ -2077,8 +2077,7 @@ void Verifier::visitLandingPadInst(LandingPadInst &LPI) { Assert1(isa(PersonalityFn), "Personality function is not constant!", &LPI); for (unsigned i = 0, e = LPI.getNumClauses(); i < e; ++i) { - Value *Clause = LPI.getClause(i); - Assert1(isa(Clause), "Clause is not constant!", &LPI); + Constant *Clause = LPI.getClause(i); if (LPI.isCatch(i)) { Assert1(isa(Clause->getType()), "Catch operand does not have pointer type!", &LPI); diff --git a/lib/Transforms/InstCombine/InstructionCombining.cpp b/lib/Transforms/InstCombine/InstructionCombining.cpp index 9b8fdb27002..0fffc5a1548 100644 --- a/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -2099,7 +2099,7 @@ Instruction *InstCombiner::visitLandingPadInst(LandingPadInst &LI) { // Simplify the list of clauses, eg by removing repeated catch clauses // (these are often created by inlining). bool MakeNewInstruction = false; // If true, recreate using the following: - SmallVector NewClauses; // - Clauses for the new instruction; + SmallVector NewClauses; // - Clauses for the new instruction; bool CleanupFlag = LI.isCleanup(); // - The new instruction is a cleanup. SmallPtrSet AlreadyCaught; // Typeinfos known caught already. @@ -2107,7 +2107,7 @@ Instruction *InstCombiner::visitLandingPadInst(LandingPadInst &LI) { bool isLastClause = i + 1 == e; if (LI.isCatch(i)) { // A catch clause. - Value *CatchClause = LI.getClause(i); + Constant *CatchClause = LI.getClause(i); Constant *TypeInfo = cast(CatchClause->stripPointerCasts()); // If we already saw this clause, there is no point in having a second @@ -2137,7 +2137,7 @@ Instruction *InstCombiner::visitLandingPadInst(LandingPadInst &LI) { // equal (for example if one represents a C++ class, and the other some // class derived from it). assert(LI.isFilter(i) && "Unsupported landingpad clause!"); - Value *FilterClause = LI.getClause(i); + Constant *FilterClause = LI.getClause(i); ArrayType *FilterType = cast(FilterClause->getType()); unsigned NumTypeInfos = FilterType->getNumElements(); @@ -2287,7 +2287,7 @@ Instruction *InstCombiner::visitLandingPadInst(LandingPadInst &LI) { continue; // If Filter is a subset of LFilter, i.e. every element of Filter is also // an element of LFilter, then discard LFilter. - SmallVectorImpl::iterator J = NewClauses.begin() + j; + SmallVectorImpl::iterator J = NewClauses.begin() + j; // If Filter is empty then it is a subset of LFilter. if (!FElts) { // Discard LFilter. -- 2.34.1