[llvm-dev] InstList insert depreciated?

Jonathan Roelofs via llvm-dev llvm-dev at lists.llvm.org
Thu Aug 25 10:24:08 PDT 2016



On 8/25/16 11:17 AM, Shehbaz Jaffer wrote:
> More specifically,
>
> -     FirstI->insertAfter(TaintVar);
> +      auto t = dyn_cast<Instruction>(TaintVar);
> +       t->insertBefore(&FirstI);
>
> worked for me.
>
> since TaintVar is of type AllocaInst, it does not have an insertAfter
> insertBefore defined, so I had to dynamically cast it to Instruction.

Instruction is AllocaInst's public base class... you shouldn't need to 
dyn_cast<> here.

Also, dyn_cast<> followed by dereferencing its result without checking 
for null is an anti-pattern. You should either use cast<>, or add a 
check for it.

>
> Also, making t->insertAfter(&FirstI) causes some errors of type
> "llvm-instruction-does-not-dominate-all-uses", since I want alloca to
> appear before FirstI, I had to make insertAfter => insertBefore.

Yeah, sticking alloca's at the top of the block is a good idea. Even 
better if it's the entry block.


Jon

>
> On Thu, Aug 25, 2016 at 10:12 AM, Shehbaz Jaffer
> <shehbazjaffer007 at gmail.com> wrote:
>> Jon,
>>
>>> You want:
>>>    TaintVar->insertAfter(FirstI);
>>
>> This worked! Thank you.
>>
>> On Thu, Aug 25, 2016 at 9:38 AM, Jonathan Roelofs
>> <jonathan at codesourcery.com> wrote:
>>>
>>>
>>> On 8/25/16 7:01 AM, Shehbaz Jaffer via llvm-dev wrote:
>>>>
>>>> I tried an alternative way of adding instruction by first getting the
>>>> first instruction of the basic block, and then calling insertAfter()
>>>> on it as follows:
>>>>
>>>>   auto &B = F->getEntryBlock();
>>>>   auto &IList = B.getInstList();
>>>>   auto &FirstI = *IList.begin();
>>>>     auto TaintVar = new AllocaInst(IntPtrTy);
>>>>     // IList.insert(FirstI, TaintVar);  // OLD
>>>>      FirstI.insertAfter(TaintVar); // NEW
>>>
>>>
>>> You want:
>>>
>>>    TaintVar->insertAfter(FirstI);
>>>
>>>
>>> Jon
>>>
>>> --
>>> Jon Roelofs
>>> jonathan at codesourcery.com
>>> CodeSourcery / Mentor Embedded
>>
>>
>>
>> --
>> Shehbaz Jaffer
>> First Year Graduate Student
>> Sir Edward S Rogers Sr Department of Electrical and Computer Engineering
>> University of Toronto
>
>
>

-- 
Jon Roelofs
jonathan at codesourcery.com
CodeSourcery / Mentor Embedded


More information about the llvm-dev mailing list