I'm trying to come up with a simple example of using ICmpInst in a Pass. On each of the branches(true, false) I'd like to call a separate function and then resume(to the code that was already there). In this example i is a inst_iterator to Instruction the Pass is currently on. Now it segfaults opt before I can even get a dump() on it. Does anyone see what I am doing wrong? BasicBlock *bb = i->getParent(); Instruction *j = bb->end(); BasicBlock *bb_after = i->getParent()->splitBasicBlock(&*i); bb->getTerminator()->eraseFromParent(); ICmpInst *test = new ICmpInst(j, CmpInst::ICMP_EQ, shadow, val, "Shadow check"); BasicBlock *trueBlock = BasicBlock::Create(M.getContext(), "Shadow Check Block: TRUE", &F); CallInst::Create(qv_true, "", trueBlock); BranchInst::Create(bb_after, trueBlock); BasicBlock *falseBlock = BasicBlock::Create(M.getContext(), "Shadow Check Block: FALSE", &F); CallInst::Create(qv_false, "", falseBlock); BranchInst::Create(bb_after, falseBlock); BranchInst::Create(trueBlock, falseBlock, test, j);
On Tue, Sep 27, 2011 at 7:28 PM, ret val <retval386 at gmail.com> wrote:> I'm trying to come up with a simple example of using ICmpInst in a > Pass. On each of the branches(true, false) I'd like to call a separate > function and then resume(to the code that was already there). > > In this example i is a inst_iterator to Instruction the Pass is > currently on. Now it segfaults opt before I can even get a dump() on > it. Does anyone see what I am doing wrong? > > BasicBlock *bb = i->getParent(); > Instruction *j = bb->end();Your initialization of "j" isn't valid: bb->end() doesn't point at an Instruction. -Eli
On 9/27/11 10:00 PM, Eli Friedman wrote:> On Tue, Sep 27, 2011 at 7:28 PM, ret val<retval386 at gmail.com> wrote: >> I'm trying to come up with a simple example of using ICmpInst in a >> Pass. On each of the branches(true, false) I'd like to call a separate >> function and then resume(to the code that was already there). >> >> In this example i is a inst_iterator to Instruction the Pass is >> currently on. Now it segfaults opt before I can even get a dump() on >> it. Does anyone see what I am doing wrong? >> >> BasicBlock *bb = i->getParent(); >> Instruction *j = bb->end(); > Your initialization of "j" isn't valid: bb->end() doesn't point at an > Instruction.To add to this, if you want to get the last instruction in a basic block, just use BasicBlock::getTerminator(). All basic blocks must have a terminator instruction as the last instruction. -- John T.> > -Eli > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Perhaps try j->back(); Joe Sent from my iPad On Sep 27, 2011, at 11:00 PM, Eli Friedman <eli.friedman at gmail.com> wrote:> On Tue, Sep 27, 2011 at 7:28 PM, ret val <retval386 at gmail.com> wrote: >> I'm trying to come up with a simple example of using ICmpInst in a >> Pass. On each of the branches(true, false) I'd like to call a separate >> function and then resume(to the code that was already there). >> >> In this example i is a inst_iterator to Instruction the Pass is >> currently on. Now it segfaults opt before I can even get a dump() on >> it. Does anyone see what I am doing wrong? >> >> BasicBlock *bb = i->getParent(); >> Instruction *j = bb->end(); > > Your initialization of "j" isn't valid: bb->end() doesn't point at an > Instruction. > > -Eli > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev