Gcc 11 segfault / internal compiler error while building LLVM

I am not able to debug LLVM source code earlier there was no such error but now it is showing It cannot build due to some internal compiler error.

Error:
ninja: Entering directory `build’
[155/2196] Building CXX object lib/Transforms/Scalar/CMakeFiles/LLVMScalarOpts.dir/SROA.cpp.o
In file included from /home/ayush/Desktop/mtp/llvm-project/llvm/lib/Transforms/Scalar/SROA.cpp:25:
/home/ayush/Desktop/mtp/llvm-project/llvm/include/llvm/Transforms/Scalar/SROA.h:96:7: warning: ‘llvm::SROAPass’ declared with greater visibility than the type of its field ‘llvm::SROAPass::SelectsToRewrite’ [-Wattributes]
96 | class SROAPass : public PassInfoMixin {
| ^~~~~~~~
[269/2196] Building CXX object lib/Analysis/CMakeFiles/LLVMAnalysis.dir/DemandedBits.cpp.o
FAILED: lib/Analysis/CMakeFiles/LLVMAnalysis.dir/DemandedBits.cpp.o
/usr/bin/c++ -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D_LIBCPP_ENABLE_HARDENED_MODE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/ayush/Desktop/mtp/llvm-project/build/lib/Analysis -I/home/ayush/Desktop/mtp/llvm-project/llvm/lib/Analysis -I/home/ayush/Desktop/mtp/llvm-project/build/include -I/home/ayush/Desktop/mtp/llvm-project/llvm/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -g -fno-exceptions -funwind-tables -fno-rtti -std=c++17 -MD -MT lib/Analysis/CMakeFiles/LLVMAnalysis.dir/DemandedBits.cpp.o -MF lib/Analysis/CMakeFiles/LLVMAnalysis.dir/DemandedBits.cpp.o.d -o lib/Analysis/CMakeFiles/LLVMAnalysis.dir/DemandedBits.cpp.o -c /home/ayush/Desktop/mtp/llvm-project/llvm/lib/Analysis/DemandedBits.cpp
during RTL pass: ira
In file included from /home/ayush/Desktop/mtp/llvm-project/llvm/include/llvm/Analysis/DemandedBits.h:24,
from /home/ayush/Desktop/mtp/llvm-project/llvm/lib/Analysis/DemandedBits.cpp:21:
/home/ayush/Desktop/mtp/llvm-project/llvm/include/llvm/ADT/APInt.h: In member function ‘void llvm::APInt::flipAllBits()’:
/home/ayush/Desktop/mtp/llvm-project/llvm/include/llvm/ADT/APInt.h:1406:3: internal compiler error: Segmentation fault
1406 | }
| ^
0x7f39d684251f ???
./signal/…/sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0
0x7f39d6829d8f __libc_start_call_main
…/sysdeps/nptl/libc_start_call_main.h:58
0x7f39d6829e3f __libc_start_main_impl
…/csu/libc-start.c:392
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <file:///usr/share/doc/gcc-11/README.Bugs> for instructions.
[270/2196] Building CXX object lib/Analysis/CMakeFiles/LLVMAnalysis.dir/DominanceFrontier.cpp.o
FAILED: lib/Analysis/CMakeFiles/LLVMAnalysis.dir/DominanceFrontier.cpp.o
/usr/bin/c++ -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D_LIBCPP_ENABLE_HARDENED_MODE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/ayush/Desktop/mtp/llvm-project/build/lib/Analysis -I/home/ayush/Desktop/mtp/llvm-project/llvm/lib/Analysis -I/home/ayush/Desktop/mtp/llvm-project/build/include -I/home/ayush/Desktop/mtp/llvm-project/llvm/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -g -fno-exceptions -funwind-tables -fno-rtti -std=c++17 -MD -MT lib/Analysis/CMakeFiles/LLVMAnalysis.dir/DominanceFrontier.cpp.o -MF lib/Analysis/CMakeFiles/LLVMAnalysis.dir/DominanceFrontier.cpp.o.d -o lib/Analysis/CMakeFiles/LLVMAnalysis.dir/DominanceFrontier.cpp.o -c /home/ayush/Desktop/mtp/llvm-project/llvm/lib/Analysis/DominanceFrontier.cpp
during RTL pass: ira
In file included from /usr/include/c++/11/map:60,
from /home/ayush/Desktop/mtp/llvm-project/llvm/include/llvm/Analysis/DominanceFrontier.h:26,
from /home/ayush/Desktop/mtp/llvm-project/llvm/lib/Analysis/DominanceFrontier.cpp:9:
/usr/include/c++/11/bits/stl_tree.h: In member function ‘std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::end() [with _Key = llvm::BasicBlock*; _Val = std::pair<llvm::BasicBlock* const, std::set<llvm::BasicBlock*, std::lessllvm::BasicBlock*, std::allocatorllvm::BasicBlock* > >; _KeyOfValue = std::_Select1st<std::pair<llvm::BasicBlock* const, std::set<llvm::BasicBlock*, std::lessllvm::BasicBlock*, std::allocatorllvm::BasicBlock* > > >; _Compare = std::lessllvm::BasicBlock*; _Alloc = std::allocator<std::pair<llvm::BasicBlock* const, std::set<llvm::BasicBlock*, std::lessllvm::BasicBlock*, std::allocatorllvm::BasicBlock* > > >]’:
/usr/include/c++/11/bits/stl_tree.h:1004:52: internal compiler error: Segmentation fault
1004 | { return iterator(&this->_M_impl._M_header); }
| ^
0x7f223ce4251f ???
./signal/…/sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0
0x7f223ce29d8f __libc_start_call_main
…/sysdeps/nptl/libc_start_call_main.h:58
0x7f223ce29e3f __libc_start_main_impl
…/csu/libc-start.c:392
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <file:///usr/share/doc/gcc-11/README.Bugs> for instructions.
[282/2196] Building CXX object lib/Analysis/CMakeFiles/LLVMAnalysis.dir/IRSimilarityIdentifier.cpp.o
ninja: build stopped: subcommand failed.

You host compiler (GCC) segfaulted. This is not an LLVM issue, it is a bug in GCC (or a problem with your machine, like bad RAM).

but GCC version in my machine is gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
and RAM is 32GB
can you give me solution ?

  • build without using all the threads ninja -j X where X is half your number of cores maybe
  • Upgrade gcc to a newer version
  • Use clang instead!
  • Check your RAM with a RAM test maybe?

All in all this is not a LLVM issue, so if it is reproducible consistently then maybe file a bug with gcc?