llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.83k stars 11.91k forks source link

llvm10.0.1,core dumped Assertion `!NodePtr->isKnownSentinel()' failed. when I use #pragma omp parallel for #66773

Open ffhgfv opened 1 year ago

ffhgfv commented 1 year ago

When I execute the following code

#ifdef MultiThread
        //OP<<"\nMUlti.";
        int MaxThread = omp_get_max_threads();
        omp_set_num_threads(MaxThread);
        #pragma omp parallel for
        //OP << "\nThread: "<< omp_get_thread_num()<< ". Nthreads " <<   omp_get_num_threads()<<". MaxThread: "<<MaxThread;
    #endif

When executed to ”#pragma omp parallel for“,The program will encounter segment errors.Here is the error message

/llvm/llvm-project/prefix/include/llvm/ADT/ilist_iterator.h:139: llvm::ilist_iterator::reference llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void>, false, false>::operator*() const [OptionsT = llvm::ilist_detail::node_options<llvm::Instruction, true, false, void>, IsReverse = false, IsConst = false]: Assertion `!NodePtr->isKnownSentinel()' failed.
 #0 0x000000000065567a llvm::sys::PrintStackTrace(llvm::raw_ostream&) (./kanalyzer+0x65567a)
 #1 0x000000000065302c llvm::sys::RunSignalHandlers() (./kanalyzer+0x65302c)
 #2 0x0000000000653193 SignalHandler(int) (./kanalyzer+0x653193)
 #3 0x00007f19c84d7390 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x11390)
 #4 0x00007f19c75c4438 raise /build/glibc-S7Ft5T/glibc-2.23/signal/../sysdeps/unix/sysv/linux/raise.c:54:0
 #5 0x00007f19c75c603a abort /build/glibc-S7Ft5T/glibc-2.23/stdlib/abort.c:91:0
 #6 0x00007f19c75bcbe7 __assert_fail_base /build/glibc-S7Ft5T/glibc-2.23/assert/assert.c:92:0
 #7 0x00007f19c75bcc92 (/lib/x86_64-linux-gnu/libc.so.6+0x2dc92)
 #8 0x000000000044886b llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void>, false, false>::operator*() const /home/cp/CPscan/llvm/llvm-project/prefix/include/llvm/ADT/ilist_iterator.h:0:5
 #9 0x00000000004465d8 ObtainSplitInst(llvm::BasicBlock*, llvm::Instruction*, std::vector<llvm::Value*, std::allocator<llvm::Value*> >*) /home/cp/CPscan/Kanalyzer/src/lib/llvm-diff.cc:3038:13
#10 0x000000000043b848 rewritting(llvm::Function*, GlobalContext*) /home/cp/CPscan/Kanalyzer/src/lib/llvm-diff.cc:3131:46
#11 0x0000000000439f44 .omp_outlined._debug__.150 /home/cp/CPscan/Kanalyzer/src/lib/llvm-diff.cc:1929:9
#12 0x000000000043ba6f .omp_outlined..151 /home/cp/CPscan/Kanalyzer/src/lib/llvm-diff.cc:1922:5
#13 0x00007f19c7c084b3 __kmp_invoke_microtask (/usr/lib/x86_64-linux-gnu/libomp.so.5+0x994b3)
#14 0x00007f19c7baf029 (/usr/lib/x86_64-linux-gnu/libomp.so.5+0x40029)
#15 0x00007f19c7ba8590 __kmp_fork_call (/usr/lib/x86_64-linux-gnu/libomp.so.5+0x39590)
#16 0x00007f19c7b9cf4f __kmpc_fork_call (/usr/lib/x86_64-linux-gnu/libomp.so.5+0x2df4f)
#17 0x000000000043936f Check_OMP(std::vector<std::pair<llvm::Module*, llvm::Module*>, std::allocator<std::pair<llvm::Module*, llvm::Module*> > >*, GlobalContext*, GlobalContext*) /home/cp/CPscan/Kanalyzer/src/lib/llvm-diff.cc:1937:33
#18 0x00000000005083c2 main /home/cp/CPscan/Kanalyzer/src/lib/Analyzer.cc:175:3
#19 0x00007f19c75af840 __libc_start_main /build/glibc-S7Ft5T/glibc-2.23/csu/../csu/libc-start.c:325:0
#20 0x0000000000425509 _start (./kanalyzer+0x425509)
Stack dump:
0.  Program arguments: ./kanalyzer -sc ./linux-stable-3.3.8.k/net/bridge/br_stp.bc 
Aborted (core dumped)
ffhgfv commented 1 year ago

May I ask if anyone has encountered the same problem? How to solve it?

tbaederr commented 1 year ago

Why are you using such an ancient llvm version?

llvmbot commented 1 year ago

@llvm/issue-subscribers-openmp

When I execute the following code ```c++ #ifdef MultiThread //OP<<"\nMUlti."; int MaxThread = omp_get_max_threads(); omp_set_num_threads(MaxThread); #pragma omp parallel for //OP << "\nThread: "<< omp_get_thread_num()<< ". Nthreads " << omp_get_num_threads()<<". MaxThread: "<<MaxThread; #endif ``` When executed to ”#pragma omp parallel for“,The program will encounter segment errors.Here is the error message ``` /llvm/llvm-project/prefix/include/llvm/ADT/ilist_iterator.h:139: llvm::ilist_iterator::reference llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void>, false, false>::operator*() const [OptionsT = llvm::ilist_detail::node_options<llvm::Instruction, true, false, void>, IsReverse = false, IsConst = false]: Assertion `!NodePtr->isKnownSentinel()' failed. #0 0x000000000065567a llvm::sys::PrintStackTrace(llvm::raw_ostream&) (./kanalyzer+0x65567a) #1 0x000000000065302c llvm::sys::RunSignalHandlers() (./kanalyzer+0x65302c) #2 0x0000000000653193 SignalHandler(int) (./kanalyzer+0x653193) #3 0x00007f19c84d7390 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x11390) #4 0x00007f19c75c4438 raise /build/glibc-S7Ft5T/glibc-2.23/signal/../sysdeps/unix/sysv/linux/raise.c:54:0 #5 0x00007f19c75c603a abort /build/glibc-S7Ft5T/glibc-2.23/stdlib/abort.c:91:0 #6 0x00007f19c75bcbe7 __assert_fail_base /build/glibc-S7Ft5T/glibc-2.23/assert/assert.c:92:0 #7 0x00007f19c75bcc92 (/lib/x86_64-linux-gnu/libc.so.6+0x2dc92) #8 0x000000000044886b llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void>, false, false>::operator*() const /home/cp/CPscan/llvm/llvm-project/prefix/include/llvm/ADT/ilist_iterator.h:0:5 #9 0x00000000004465d8 ObtainSplitInst(llvm::BasicBlock*, llvm::Instruction*, std::vector<llvm::Value*, std::allocator<llvm::Value*> >*) /home/cp/CPscan/Kanalyzer/src/lib/llvm-diff.cc:3038:13 #10 0x000000000043b848 rewritting(llvm::Function*, GlobalContext*) /home/cp/CPscan/Kanalyzer/src/lib/llvm-diff.cc:3131:46 #11 0x0000000000439f44 .omp_outlined._debug__.150 /home/cp/CPscan/Kanalyzer/src/lib/llvm-diff.cc:1929:9 #12 0x000000000043ba6f .omp_outlined..151 /home/cp/CPscan/Kanalyzer/src/lib/llvm-diff.cc:1922:5 #13 0x00007f19c7c084b3 __kmp_invoke_microtask (/usr/lib/x86_64-linux-gnu/libomp.so.5+0x994b3) #14 0x00007f19c7baf029 (/usr/lib/x86_64-linux-gnu/libomp.so.5+0x40029) #15 0x00007f19c7ba8590 __kmp_fork_call (/usr/lib/x86_64-linux-gnu/libomp.so.5+0x39590) #16 0x00007f19c7b9cf4f __kmpc_fork_call (/usr/lib/x86_64-linux-gnu/libomp.so.5+0x2df4f) #17 0x000000000043936f Check_OMP(std::vector<std::pair<llvm::Module*, llvm::Module*>, std::allocator<std::pair<llvm::Module*, llvm::Module*> > >*, GlobalContext*, GlobalContext*) /home/cp/CPscan/Kanalyzer/src/lib/llvm-diff.cc:1937:33 #18 0x00000000005083c2 main /home/cp/CPscan/Kanalyzer/src/lib/Analyzer.cc:175:3 #19 0x00007f19c75af840 __libc_start_main /build/glibc-S7Ft5T/glibc-2.23/csu/../csu/libc-start.c:325:0 #20 0x0000000000425509 _start (./kanalyzer+0x425509) Stack dump: 0. Program arguments: ./kanalyzer -sc ./linux-stable-3.3.8.k/net/bridge/br_stp.bc Aborted (core dumped) ```
EugeneZelenko commented 1 year ago

Could you please try 17 or main branch?

shiltian commented 1 year ago

The crash stack looks very suspicious. Why is there function calls to LLVM libraries in a parallel region? LLVM is not thread safe at all.

ffhgfv commented 1 year ago

I attempted to replicate the work of CPscan Detecting Bugs Caused by Code Pruning in IoT Kernels. LLVM was used in CPscan to analyze. bc files, and openmp was used for parallel optimization of the for loop during the analysis process. These for loops utilized LLVM to expand the loop into if. When I used gdb for debugging, I found that such a crash occurred while parallel processing the for loop.

shiltian commented 1 year ago

You might want to create one LLVM context for each thread because LLVM is not thread safe.

shiltian commented 1 year ago

Is there any update on this issue? Can I close it for now?