[LLVMdev] insert ICmpInst/BranchIns in Pass?

Eli Friedman eli.friedman at gmail.com
Tue Oct 11 19:36:51 PDT 2011

On Tue, Oct 11, 2011 at 7:22 PM, ret val <retval386 at gmail.com> wrote:
> In a pass I would like to insert a ICmpInst/BranchInst pair to check
> if 2 GlobalVariables are equal or not. If they are not I would like to
> call a function. I've tried splitting the current block and then
> inserting before the existing instructions, but for some reason this
> seems to ruin the iterator(i). What is the correct way todo something
> like this?
> void checkShadowPtr(Module &M, Function &F, inst_iterator i,
> GlobalVariable *shadow, Value *val) {

inst_iterator is hiding iterators which aren't going to stay
consistent across this kind of change.  I'd suggest explicitly using
Function::iterator and BasicBlock::iterator to keep track of where you
are in the function; that should make it obvious what is going wrong.


More information about the llvm-dev mailing list