[LLVMdev] insertions with inst_iterators?

ret val retval386 at gmail.com
Mon Aug 29 16:02:57 PDT 2011


That just gives me

"error: cannot convert ‘llvm::Instruction’ to ‘llvm::Instruction*’ in
initialization"

I'm guessing you ment

Instruction *Inst = &*i++;

Which also leaves me with a infinite loop

Thanks


On Mon, Aug 29, 2011 at 3:52 PM, Bill Wendling <wendling at apple.com> wrote:
>
> On Aug 29, 2011, at 12:38 PM, ret val wrote:
>
>> I am looping through all instructions in a Function and depending on
>> what I found I may or may not insert code. Despite the fact that I'm
>> only actually inserting *before* instruction I have a infinite loop
>> when I do something like below. For awhile it was simple enough to
>> just increment i enough times but now I need something better.
>>
>> for(inst_iterator i = inst_begin(F); i != inst_end(F); ++i) {
>>         ...
>>         // possible insertions of unknown size
>>         ...
>> }
>>
>> I tried storing the storing the initial iterator and reverting back to
>> it(along with storing the next element) and I am still left with a
>> infinite loop. I see some discussion online about weather insertions
>> with iterators in C++ is allowed period, so what is the correct way to
>> do something like this in LLVM? This must be a common problem.
>>
> Have you tried this?
>
> for(inst_iterator i = inst_begin(F); i != inst_end(F); ) {
>        Instruction *Inst = *i++;
>        ...
>        // possible insertions of unknown size
>        ...
> }
>
> ?
>
> -bw
>
>




More information about the llvm-dev mailing list