Hi llvm-devel, I have migrated my codebase from llvm-3.6 to llvm 3.8.1-stable. Although I was able to resolve most of the problems, I am facing issues resolving the following: To insert an instruction immediately after the first instruction within a basic block, I first get all instructions in my basic block in an instruction container list. Once that is done, I insert my new instruction in the instruction container list using InstList.insert(). // code void FSliceModulePass::allocaVSetArray(void) { auto &B = F->getEntryBlock(); auto &IList = B.getInstList(); auto &FirstI = *IList.begin(); auto TaintVar = new AllocaInst(IntPtrTy, FirstI); IList.insert(FirstI, TaintVar); // ERROR After migrating to 3.8.1, It gives me the following error: ERROR: /home/shehbaz/project/plugin/FSlice.cpp: In member function ‘void FSliceModulePass::allocaVSetArray()’: /home/shehbaz/project/plugin/FSlice.cpp:284:34: error: no matching function for call to ‘llvm::SymbolTableList<llvm::Instruction>::insert(llvm::I nstruction&, llvm::AllocaInst*&)’ IList.insert(FirstI, TaintVar); ^ In file included from /home/shehbaz/project/llvm/include/llvm/IR/BasicBlock.h:18:0, from /home/shehbaz/project/llvm/include/llvm/IR/Function.h:25, from /home/shehbaz/project/plugin/FSlice.cpp:7: /home/shehbaz/project/llvm/include/llvm/ADT/ilist.h:461:12: note: candidate: llvm::iplist<NodeTy, Traits>::iterator llvm::iplist<NodeTy, Traits>: :insert(llvm::iplist<NodeTy, Traits>::iterator, NodeTy*) [with NodeTy = llvm::Instruction; Traits llvm::SymbolTableListTraits<llvm::Instruction>; llvm::iplist<NodeTy, Traits>::iterator = llvm::ilist_iterator<llvm::Instruction>]iterator insert(iterator where, NodeTy *New) { ^ /home/shehbaz/project/llvm/include/llvm/ADT/ilist.h:461:12: note: no known conversion for argument 1 from ‘llvm::Instruction’ to ‘llvm::iplist< llvm::Instruction, llvm::SymbolTableListTraits<llvm::Instruction>>::iterator {aka llvm::ilist_iterator<llvm::Instruction>}’/home/shehbaz/project/llvm/include/llvm/ADT/ilist.h:620:29: note: candidate: template<class InIt> void llvm::iplist<NodeTy, Traits>::insert(llvm: :iplist<NodeTy, Traits>::iterator, InIt, InIt) [with InIt = InIt; NodeTy = llvm::Instruction; Traits llvm::SymbolTableListTraits<llvm::Instruct ion>] template<class InIt> void insert(iterator where, InIt first, InIt last) { ^ /home/shehbaz/project/llvm/include/llvm/ADT/ilist.h:620:29: note: template argument deduction/substitution failed: /home/shehbaz/project/plugin/FSlice.cpp:284:34: note: candidate expects 3 arguments, 2 provided IList.insert(FirstI, TaintVar); 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 This compiles, however, while running the code, I get the following Stack Dump: #0 0x0000000001466cb8 llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/home/shehbaz/project/llvm/build/bin/opt+0x1466cb8) #1 0x0000000001467337 SignalHandler(int) (/home/shehbaz/project/llvm/build/bin/opt+0x1467337) #2 0x00007f8e846fa3d0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x113d0) #3 0x0000000001107c2b llvm::Instruction::insertAfter(llvm::Instruction*) (/home/shehbaz/project/llvm/build/bin/opt+0x1107c2b) #4 0x00007f8e83642f20 FSliceModulePass::allocaVSetArray() /home/shehbaz/project/plugin/FSlice.cpp:287:0 #5 0x00007f8e83642666 FSliceModulePass::runOnFunction(char const*) /home/shehbaz/project/plugin/FSlice.cpp:172:0 #6 0x00007f8e836425dd FSliceModulePass::runOnModule(llvm::Module&) /home/shehbaz/project/plugin/FSlice.cpp:139:0 #7 0x000000000112852c llvm::legacy::PassManagerImpl::run(llvm::Module&) (/home/shehbaz/project/llvm/build/bin/opt+0x112852c) #8 0x000000000064cf88 main (/home/shehbaz/project/llvm/build/bin/opt+0x64cf88) #9 0x00007f8e83885830 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x20830) #10 0x0000000000641809 _start (/home/shehbaz/project/llvm/build/bin/opt+0x641809) Any suggestions or pointers to how I can go about debugging this issue will be of great help. Thanks in Advance, -- Shehbaz Jaffer First Year Graduate Student Sir Edward S Rogers Sr Department of Electrical and Computer Engineering University of Toronto
Jonathan Roelofs via llvm-dev
2016-Aug-25 13:38 UTC
[llvm-dev] InstList insert depreciated?
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); // NEWYou want: TaintVar->insertAfter(FirstI); Jon -- Jon Roelofs jonathan at codesourcery.com CodeSourcery / Mentor Embedded
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