Hello John, John Criswell <criswell at illinois.edu> writes: [snip]> By the way, it looks like you don't have a build with assertions > enabled. I recommend compiling with > > gmake ENABLE_OPTIMIZED=0 DISABLE_ASSERTIONS=1Shouldn't the above be DISABLE_ASSERTIONS=0 ? (which means DISABLE_ASSERTIONS=No, introducing the dreaded double negation which causes so much confusion on some people.) BTW, Debug+Asserts is the default mode in the configure&make build.
Dear sir or madam, I am a 4-th year student at Yerevan State University, Armenia; and I am studying LLVM in order to write my Bachelor thesis. I am trying to write an llvm pass that just removes all "Add" commands and gives some statstics. Nevertheless, I get this segmentation fault: ................some rows about functions, that are not changed by my pass. The errors occurs after it has modified a "@_Z3addii" function. store i32 %b.0, i32* %4 and the type is ddddbbm 28 %5 = load i32* %a_addr, align 4 and the type is ddddbbm 27 %6 = load i32* %b_addr, align 4 and the type is ddddbbm 27 %7 = add nsw i32 %5, %6 and the type is ddddbbm 8 store i32 %7, i32* %0, align 4 and the type is ddddbbm 28 %7 = add nsw i32 %5, %6 is erased, ba! %7 = load i32* %0, align 4 and the type is ddddbbm 27 store i32 %7, i32* %retval, align 4 and the type is ddddbbm 28 br label %return and the type is ddddbbm 2 ret i32 %retval1 and the type is ddddbbm 1 0 opt 0x00000000008ed93f 1 opt 0x00000000008edcea 2 libpthread.so.0 0x00007f9ba1183c60 3 opt 0x00000000004b3615 llvm::PATypeHolder::get() const + 21 4 opt 0x00000000008a4f11 5 opt 0x00000000008a9404 6 opt 0x0000000000882557 llvm::FPPassManager::runOnFunction(llvm::Function&) + 551 7 opt 0x00000000008825db llvm::FPPassManager::runOnModule(llvm::Module&) + 75 8 opt 0x0000000000882197 llvm::MPPassManager::runOnModule(llvm::Module&) + 503 9 opt 0x0000000000882299 llvm::PassManagerImpl::run(llvm::Module&) + 137 10 opt 0x00000000004ac451 main + 4881 11 libc.so.6 0x00007f9ba0459eff __libc_start_main + 255 12 opt 0x000000000049f5f9 Stack dump: 0. Program arguments: opt hello.bc -load ../llvm/llvm-2.9/plugin/BasicBlockStats.so -basic-block-stats -stats -o newhello.bc 1. Running pass 'Function Pass Manager' on module 'hello.bc'. 2. Running pass 'Module Verifier' on function '@_Z3addii' Segmentation fault Please find the source of my pass attached. Hope to get a reply soon. Regards, Arshak Nazaryan -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20111103/504a02e9/attachment.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: BasicBlockStats.cpp Type: text/x-c++src Size: 1911 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20111103/504a02e9/attachment.cpp>
Hi Arshak, Do you expect us to debug your pass for you? Have you run it in GDB and seen where the segfault occurs? 3 opt 0x00000000004b3615 llvm::PATypeHolder::get() const + 21 Looks like the most likely suspect, run on a bad pointer. But GDB would have told you this. Also, PATypeHolder is deprecated and not available in mainline trunk. Cheers, James From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] On Behalf Of Arshak Nazaryan Sent: 03 November 2011 10:56 To: llvmdev at cs.uiuc.edu Subject: [LLVMdev] LLVM problem, please do not ignore Dear sir or madam, I am a 4-th year student at Yerevan State University, Armenia; and I am studying LLVM in order to write my Bachelor thesis. I am trying to write an llvm pass that just removes all "Add" commands and gives some statstics. Nevertheless, I get this segmentation fault: ................some rows about functions, that are not changed by my pass. The errors occurs after it has modified a "@_Z3addii" function. store i32 %b.0, i32* %4 and the type is ddddbbm 28 %5 = load i32* %a_addr, align 4 and the type is ddddbbm 27 %6 = load i32* %b_addr, align 4 and the type is ddddbbm 27 %7 = add nsw i32 %5, %6 and the type is ddddbbm 8 store i32 %7, i32* %0, align 4 and the type is ddddbbm 28 %7 = add nsw i32 %5, %6 is erased, ba! %7 = load i32* %0, align 4 and the type is ddddbbm 27 store i32 %7, i32* %retval, align 4 and the type is ddddbbm 28 br label %return and the type is ddddbbm 2 ret i32 %retval1 and the type is ddddbbm 1 0 opt 0x00000000008ed93f 1 opt 0x00000000008edcea 2 libpthread.so.0 0x00007f9ba1183c60 3 opt 0x00000000004b3615 llvm::PATypeHolder::get() const + 21 4 opt 0x00000000008a4f11 5 opt 0x00000000008a9404 6 opt 0x0000000000882557 llvm::FPPassManager::runOnFunction(llvm::Function&) + 551 7 opt 0x00000000008825db llvm::FPPassManager::runOnModule(llvm::Module&) + 75 8 opt 0x0000000000882197 llvm::MPPassManager::runOnModule(llvm::Module&) + 503 9 opt 0x0000000000882299 llvm::PassManagerImpl::run(llvm::Module&) + 137 10 opt 0x00000000004ac451 main + 4881 11 libc.so.6 0x00007f9ba0459eff __libc_start_main + 255 12 opt 0x000000000049f5f9 Stack dump: 0. Program arguments: opt hello.bc -load ../llvm/llvm-2.9/plugin/BasicBlockStats.so -basic-block-stats -stats -o newhello.bc 1. Running pass 'Function Pass Manager' on module 'hello.bc'. 2. Running pass 'Module Verifier' on function '@_Z3addii' Segmentation fault Please find the source of my pass attached. Hope to get a reply soon. Regards, Arshak Nazaryan -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20111103/798419fd/attachment.html>
Hi Arshak, build LLVM with assertions on. Then you will get helpful messages like "Destroying a value while uses still around!" and so on. You need to use replaceAllUsesWith to replace all uses of the add with something else (eg an undef value of the same type) before you delete it. Ciao, Duncan. On 11/03/11 11:55, Arshak Nazaryan wrote:> Dear sir or madam, > > I am a 4-th year student at Yerevan State University, Armenia; and I am studying > LLVM in order to write my Bachelor thesis. > I am trying to write an llvm pass that just removes all "Add" commands and gives > some statstics. > Nevertheless, I get this segmentation fault: > > ................some rows about functions, that are not changed by my pass. The > errors occurs after it has modified a "@_Z3addii" function. > store i32 %b.0, i32* %4 and the type is ddddbbm 28 > %5 = load i32* %a_addr, align 4 and the type is ddddbbm 27 > %6 = load i32* %b_addr, align 4 and the type is ddddbbm 27 > %7 = add nsw i32 %5, %6 and the type is ddddbbm 8 > store i32 %7, i32* %0, align 4 and the type is ddddbbm 28 > %7 = add nsw i32 %5, %6 is erased, ba! > %7 = load i32* %0, align 4 and the type is ddddbbm 27 > store i32 %7, i32* %retval, align 4 and the type is ddddbbm 28 > br label %return and the type is ddddbbm 2 > ret i32 %retval1 and the type is ddddbbm 1 > 0 opt 0x00000000008ed93f > 1 opt 0x00000000008edcea > 2 libpthread.so.0 0x00007f9ba1183c60 > 3 opt 0x00000000004b3615 llvm::PATypeHolder::get() const + 21 > 4 opt 0x00000000008a4f11 > 5 opt 0x00000000008a9404 > 6 opt 0x0000000000882557 > llvm::FPPassManager::runOnFunction(llvm::Function&) + 551 > 7 opt 0x00000000008825db > llvm::FPPassManager::runOnModule(llvm::Module&) + 75 > 8 opt 0x0000000000882197 > llvm::MPPassManager::runOnModule(llvm::Module&) + 503 > 9 opt 0x0000000000882299 llvm::PassManagerImpl::run(llvm::Module&) > + 137 > 10 opt 0x00000000004ac451 main + 4881 > 11 libc.so.6 0x00007f9ba0459eff __libc_start_main + 255 > 12 opt 0x000000000049f5f9 > Stack dump: > 0.Program arguments: opt hello.bc -load > ../llvm/llvm-2.9/plugin/BasicBlockStats.so -basic-block-stats -stats -o newhello.bc > 1.Running pass 'Function Pass Manager' on module 'hello.bc'. > 2.Running pass 'Module Verifier' on function '@_Z3addii' > Segmentation fault > > Please find the source of my pass attached. > Hope to get a reply soon. > > Regards, > Arshak Nazaryan > > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
On 11/3/2011 4:55 AM, Arshak Nazaryan wrote:> Dear sir or madam, > > I am a 4-th year student at Yerevan State University, Armenia; and I > am studying LLVM in order to write my Bachelor thesis.Hi Arshak.> I am trying to write an llvm pass that just removes all "Add" commands > and gives some statstics. > Nevertheless, I get this segmentation fault:The problem is most likely that you're not modifying uses of the add instructions. The LLVM IR has explicit def-use chains, so if you want to remove an instruction, you need to modify any other instruction *that uses that instruction* so that it does not use that instruction any more. In this case, an instruction that is using the add instruction will still reference the add instruction even after you've deleted it. The error you're seeing is most likely due to a dangling pointer. To fix it, create a constant integer (ConstantInt object) and use the replaceAllUsesWith() method of the Instruction class to replace uses of the add with the integer. Then you can erase the add from the program. By the way, it looks like you don't have a build with assertions enabled. I recommend compiling with gmake ENABLE_OPTIMIZED=0 DISABLE_ASSERTIONS=1 if you're going to be developing an LLVM pass. -- John T.> > ................some rows about functions, that are not changed by my > pass. The errors occurs after it has modified a "@_Z3addii" function. > store i32 %b.0, i32* %4 and the type is ddddbbm 28 > %5 = load i32* %a_addr, align 4 and the type is ddddbbm 27 > %6 = load i32* %b_addr, align 4 and the type is ddddbbm 27 > %7 = add nsw i32 %5, %6 and the type is ddddbbm 8 > store i32 %7, i32* %0, align 4 and the type is ddddbbm 28 > %7 = add nsw i32 %5, %6 is erased, ba! > %7 = load i32* %0, align 4 and the type is ddddbbm 27 > store i32 %7, i32* %retval, align 4 and the type is ddddbbm 28 > br label %return and the type is ddddbbm 2 > ret i32 %retval1 and the type is ddddbbm 1 > 0 opt 0x00000000008ed93f > 1 opt 0x00000000008edcea > 2 libpthread.so.0 0x00007f9ba1183c60 > 3 opt 0x00000000004b3615 llvm::PATypeHolder::get() const + 21 > 4 opt 0x00000000008a4f11 > 5 opt 0x00000000008a9404 > 6 opt 0x0000000000882557 > llvm::FPPassManager::runOnFunction(llvm::Function&) + 551 > 7 opt 0x00000000008825db > llvm::FPPassManager::runOnModule(llvm::Module&) + 75 > 8 opt 0x0000000000882197 > llvm::MPPassManager::runOnModule(llvm::Module&) + 503 > 9 opt 0x0000000000882299 > llvm::PassManagerImpl::run(llvm::Module&) + 137 > 10 opt 0x00000000004ac451 main + 4881 > 11 libc.so.6 0x00007f9ba0459eff __libc_start_main + 255 > 12 opt 0x000000000049f5f9 > Stack dump: > 0.Program arguments: opt hello.bc -load > ../llvm/llvm-2.9/plugin/BasicBlockStats.so -basic-block-stats -stats > -o newhello.bc > 1.Running pass 'Function Pass Manager' on module 'hello.bc'. > 2.Running pass 'Module Verifier' on function '@_Z3addii' > Segmentation fault > > Please find the source of my pass attached. > Hope to get a reply soon. > > Regards, > Arshak Nazaryan > > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20111103/4cd4f283/attachment.html>
You probably have dangling references to the instructions you removed. Before erasing the instruction, you should call replaceAllUsesWith(Value *v) to remove any references in other instructions. Regards, Michael Smith From: Arshak Nazaryan [mailto:arshak.info at gmail.com] Sent: Thursday, November 03, 2011 3:56 AM To: llvmdev at cs.uiuc.edu Subject: [LLVMdev] LLVM problem, please do not ignore Dear sir or madam, I am a 4-th year student at Yerevan State University, Armenia; and I am studying LLVM in order to write my Bachelor thesis. I am trying to write an llvm pass that just removes all "Add" commands and gives some statstics. Nevertheless, I get this segmentation fault: ................some rows about functions, that are not changed by my pass. The errors occurs after it has modified a "@_Z3addii" function. store i32 %b.0, i32* %4 and the type is ddddbbm 28 %5 = load i32* %a_addr, align 4 and the type is ddddbbm 27 %6 = load i32* %b_addr, align 4 and the type is ddddbbm 27 %7 = add nsw i32 %5, %6 and the type is ddddbbm 8 store i32 %7, i32* %0, align 4 and the type is ddddbbm 28 %7 = add nsw i32 %5, %6 is erased, ba! %7 = load i32* %0, align 4 and the type is ddddbbm 27 store i32 %7, i32* %retval, align 4 and the type is ddddbbm 28 br label %return and the type is ddddbbm 2 ret i32 %retval1 and the type is ddddbbm 1 0 opt 0x00000000008ed93f 1 opt 0x00000000008edcea 2 libpthread.so.0 0x00007f9ba1183c60 3 opt 0x00000000004b3615 llvm::PATypeHolder::get() const + 21 4 opt 0x00000000008a4f11 5 opt 0x00000000008a9404 6 opt 0x0000000000882557 llvm::FPPassManager::runOnFunction(llvm::Function&) + 551 7 opt 0x00000000008825db llvm::FPPassManager::runOnModule(llvm::Module&) + 75 8 opt 0x0000000000882197 llvm::MPPassManager::runOnModule(llvm::Module&) + 503 9 opt 0x0000000000882299 llvm::PassManagerImpl::run(llvm::Module&) + 137 10 opt 0x00000000004ac451 main + 4881 11 libc.so.6 0x00007f9ba0459eff __libc_start_main + 255 12 opt 0x000000000049f5f9 Stack dump: 0. Program arguments: opt hello.bc -load ../llvm/llvm-2.9/plugin/BasicBlockStats.so -basic-block-stats -stats -o newhello.bc 1. Running pass 'Function Pass Manager' on module 'hello.bc'. 2. Running pass 'Module Verifier' on function '@_Z3addii' Segmentation fault Please find the source of my pass attached. Hope to get a reply soon. Regards, Arshak Nazaryan -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20111103/698ff8bd/attachment.html>