How to check if an Instruction is still in a Function

Hi,

Given an instruction ptr instr, and a Function ptr func,
can I simply check if func == instr->get_parent()->get_parent() to see if
this instruction is still in this Function?

We can also look up this instruction in the blocks of this function.
But this may take more time.

Thanks.

Yup!

-bw

Hi,

Given an instruction ptr instr, and a Function ptr func,
can I simply check if func == instr->get_parent()->get_parent() to see if
this instruction is still in this Function?

Yup!

Well. I just found that this is not quite safe sometimes.
After an instruction is removed via 'eraseFromParent',
the instruction will be deleted, and become 'dangling'.
LLVM does not set this removed instruction as NULL.
In this case, instr->get_parent()->get_parent() gives
me 'seq fault'.

Hi Jianzhou,

Well. I just found that this is not quite safe sometimes.
After an instruction is removed via 'eraseFromParent',
the instruction will be deleted, and become 'dangling'.
LLVM does not set this removed instruction as NULL.
In this case, instr->get_parent()->get_parent() gives
me 'seq fault'.

you should not access an instruction after it has been deleted. This is
sometimes quite problematic, so LLVM has a callback infrastructure that
you can use to be informed when your instruction is deleted. Take a look
at llvm/Support/ValueHandle.h

Best wishes,

Duncan.