张雨姗(ZHANG Yushan)-11310380 via llvm-dev
2018-Oct-02 03:24 UTC
[llvm-dev] How to properly initialize a callgraph pointer?
Hi all, I want to initialize a callgraph pointer on demand, so I do something like the following: class CallSite { CallSite(llvm::Module &M) { llvmCG = new llvm::CallGraph(*m); // this line causes core dump this->m = &M; } ~CallSite() { ... } public: .... private: llvm::CallGraph *llvmCG; ... } I use out of source to build the code, and it could compile without errors. But when throws "core dump" when running with 'opt -load callsite/libLLVMPassCS.so -callsite < hello.bc > /dev/null'. Command Line output: opt -load callsite/libLLVMPassCS.so -callsite < hello.bc > /dev/null #0 0x208425e llvm::sys::PrintStackTrace(_IO_FILE*) /home/zhangysh1995/packages/llvm36/lib/Support/Unix/Signals.inc:422:15 #1 0x2084feb PrintStackTraceSignalHandler(void*) /home/zhangysh1995/packages/llvm36/lib/Support/Unix/Signals.inc:481:1 #2 0x20852d9 SignalHandler(int) /home/zhangysh1995/packages/llvm36/lib/Support/Unix/Signals.inc:198:60 #3 0x7f7488070390 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x11390) #4 0x78da73 llvm::iplist<llvm::Function, llvm::ilist_traits<llvm::Function> >::CreateLazySentinel() const /home/zhangysh1995/packages/llvm36/include/llvm/ADT/ilist.h:327:22 #5 0x78da39 llvm::iplist<llvm::Function, llvm::ilist_traits<llvm::Function> >::begin() /home/zhangysh1995/packages/llvm36/include/llvm/ADT/ilist.h:360:5 #6 0x78d539 llvm::Module::begin() /home/zhangysh1995/packages/llvm36/include/llvm/IR/Module.h:571:50 #7 0x1b649d9 llvm::CallGraph::CallGraph(llvm::Module&) /home/zhangysh1995/packages/llvm36/lib/Analysis/IPA/CallGraph.cpp:27:29 // this is the constructor #8 0x7f7486dc40b2 CallSite::CallSite(llvm::Module&) (callsite/libLLVMPassCS.so+0x30b2) #9 0x7f7486dc45d3 (anonymous namespace)::test::runOnModule(llvm::Module&) (callsite/libLLVMPassCS.so+0x35d3) #10 0x1fd5df5 (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) /home/zhangysh1995/packages/llvm36/lib/IR/LegacyPassManager.cpp:1616:23 #11 0x1fd5a09 llvm::legacy::PassManagerImpl::run(llvm::Module&) /home/zhangysh1995/packages/llvm36/lib/IR/LegacyPassManager.cpp:1723:16 #12 0x1fd6371 llvm::legacy::PassManager::run(llvm::Module&) /home/zhangysh1995/packages/llvm36/lib/IR/LegacyPassManager.cpp:1756:3 #13 0x7cde9c main /home/zhangysh1995/packages/llvm36/tools/opt/opt.cpp:582:3 #14 0x7f7486fe7830 __libc_start_main /build/glibc-Cl5G7W/glibc-2.23/csu/../csu/libc-start.c:325:0 #15 0x78cb99 _start (/usr/local/bin/opt+0x78cb99) Stack dump: 0. Program arguments: opt -load callsite/libLLVMPassCS.so -callsite 1. Running pass 'Get call information' on module '<stdin>'. Segmentation fault (core dumped) Could anyone help me with this issue? And if I change it to instance instead of pointer, error: use of deleted function ‘llvm::CallGraph& llvm::CallGraph::operator=(const llvm::CallGraph&)’ llvmCG = llvm::CallGraph(*m); BTW, is there anyway to test my pass runtime behavior without running opt everytime? Thank you all, Yushan -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20181002/076d8067/attachment.html>