From ccd27fb84b0ac13ad1d30b17cbeb87a0ea934154 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Mon, 9 Feb 2009 15:45:06 +0000 Subject: [PATCH] make sure that BranchInst::getSuccessor() does not assert in cast<> even if the underlying operand is NULL. This may happen in debugging context within opt with partial loop unrolling (see test/Transforms/LoopUnroll/partial.ll). After this fix I can resubmit the (backed out) r63459: * lib/VMCore/AsmWriter.cpp: use precise accessors. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@64142 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Instructions.h | 4 +++- lib/VMCore/AsmWriter.cpp | 9 +++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/include/llvm/Instructions.h b/include/llvm/Instructions.h index fbf376afd5d..d8ce835d790 100644 --- a/include/llvm/Instructions.h +++ b/include/llvm/Instructions.h @@ -2186,7 +2186,9 @@ public: BasicBlock *getSuccessor(unsigned i) const { assert(i < getNumSuccessors() && "Successor # out of range for Branch!"); - return cast(getOperand(i)); + if (Value *V = getOperand(i)) + return cast(V); + return 0; } void setSuccessor(unsigned idx, BasicBlock *NewSucc) { diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp index 6a17516be26..0322d669d32 100644 --- a/lib/VMCore/AsmWriter.cpp +++ b/lib/VMCore/AsmWriter.cpp @@ -1505,13 +1505,14 @@ void AssemblyWriter::printInstruction(const Instruction &I) { const Value *Operand = I.getNumOperands() ? I.getOperand(0) : 0; // Special case conditional branches to swizzle the condition out to the front - if (isa(I) && I.getNumOperands() > 1) { + if (isa(I) && cast(I).isConditional()) { + BranchInst &BI(cast(I)); Out << ' '; - writeOperand(I.getOperand(2), true); + writeOperand(BI.getCondition(), true); Out << ", "; - writeOperand(Operand, true); + writeOperand(BI.getSuccessor(0), true); Out << ", "; - writeOperand(I.getOperand(1), true); + writeOperand(BI.getSuccessor(1), true); } else if (isa(I)) { // Special case switch statement to get formatting nice and correct... -- 2.34.1