[LLVMdev] How to check if an Instruction is still in a Function

Jianzhou Zhao jianzhou at seas.upenn.edu
Mon Mar 1 16:55:21 PST 2010


On Mon, Mar 1, 2010 at 7:29 PM, Bill Wendling <wendling at apple.com> wrote:
> On Feb 28, 2010, at 11:11 AM, Jianzhou Zhao wrote:
>
>> 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'.

>
> -bw
>
>



-- 
Jianzhou



More information about the llvm-dev mailing list