How to find out the instruction that is causing this error?

Hello Everyone
I am new to LLVM toolset. I am developing an instrumentation pass to enforce memory safety in C programs for Risc-V backend. While compiling the code with pass enabled, I get this error (attached diagram).
Can anyone help me with how to debug this error and find the faulting instruction? On a general side, are there any specific tools to help debug these errors?

Thank you so much
Sai

It seems to be failing on an unreachable instruction in IR LLVM Language Reference Manual — LLVM 15.0.0git documentation during the conversion to SelectionDAG.

If you pass -mllvm -debug you should be able to see which basic block was being worked on before the crash. unreachable is a terminator instruction and a basic block should only have one terminator.

The -mllvm -debug is not working for mine. I had set it to Release type while building LLVM. I tried building LLVM with Debug type, but it was not successfull. Following are the configuration I tried to build: (LLVM 11).

cmake -G Ninja -DCMAKE_BUILD_TYPE="Debug" -DCMAKE_INSTALL_PREFIX=$LLVM_PATH -DLLVM_ENABLE_LIBXML2=FALSE -DLLVM_ENABLE_OCAMLDOC=FALSE -DLLVM_ENABLE_BINDINGS=FALSE -DLLVM_INCLUDE_EXAMPLES=FALSE -DLLVM_INCLUDE_DOCS=FALSE -DLLVM_INCLUDE_BENCHMARKS=FALSE -DLLVM_OPTIMIZED_TABLEGEN=FALSE -DLLVM_BUILD_TESTS=False -DGCC_INSTALL_PREFIX=$RISCV/bin -DDEFAULT_SYSROOT=$RISCV/riscv64-unknown-elf -DLLVM_TARGETS_TO_BUILD=RISCV -DLLVM_DEFAULT_TARGET_TRIPLE="riscv64-unknown-elf" -DLLVM_ENABLE_PROJECTS="llvm;clang;lld" ../llv

What error did you get?

I usually build -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=ON that makes -debug work without it being a completely unoptimized build.

This is the error I am getting when I try to build LLVM with Debug type:

[0/1] Re-running CMake...
-- clang project is enabled
-- clang-tools-extra project is disabled
-- compiler-rt project is disabled
-- debuginfo-tests project is disabled
-- libc project is disabled
-- libclc project is disabled
-- libcxx project is disabled
-- libcxxabi project is disabled
-- libunwind project is disabled
-- lld project is enabled
-- lldb project is disabled
-- mlir project is disabled
-- openmp project is disabled
-- parallel-libs project is disabled
-- polly project is disabled
-- pstl project is disabled
-- flang project is disabled
-- Native target X86 is not selected; lli will not JIT code
-- Threads enabled.
-- Doxygen disabled.
-- Go bindings disabled.
-- Ninja version: 1.10.0
-- OCaml bindings disabled.
-- LLVM host triple: x86_64-unknown-linux-gnu
-- LLVM default target triple: riscv64-unknown-elf
-- Building with -fPIC
-- Constructing LLVMBuild project information
-- Targeting RISCV
-- Clang version: 11.1.0
-- LLD version: 11.1.0
-- Configuring done
-- Generating done
-- Build files have been written to: /home/sai/Shakti-TEE-Practical/llvm-project/_build
[14/1563] Building RISCVGenInstrInfo.inc...
FAILED: lib/Target/RISCV/RISCVGenInstrInfo.inc 
cd /home/sai/Shakti-TEE-Practical/llvm-project/_build && /home/sai/Shakti-TEE-Practical/llvm-project/_build/bin/llvm-tblgen -gen-instr-info -I /home/sai/Shakti-TEE-Practical/llvm-project/llvm/lib/Target/RISCV -I /home/sai/Shakti-TEE-Practical/llvm-project/_build/include -I /home/sai/Shakti-TEE-Practical/llvm-project/llvm/include -I /home/sai/Shakti-TEE-Practical/llvm-project/llvm/lib/Target /home/sai/Shakti-TEE-Practical/llvm-project/llvm/lib/Target/RISCV/RISCV.td --write-if-changed -o lib/Target/RISCV/RISCVGenInstrInfo.inc -d lib/Target/RISCV/RISCVGenInstrInfo.inc.d
Type set is empty for each HW mode:
possible type contradiction in the pattern below (use -print-records with llvm-tblgen to see all expanded records).
CHECKCAP: 	(intrinsic_void 6523:{ *:[iPTR] }, (imm:{ *:[] m1:[] m2:[] })<<P:Predicate_simm12>>:$imm12)
UNREACHABLE executed at /home/sai/Shakti-TEE-Practical/llvm-project/llvm/utils/TableGen/CodeGenDAGPatterns.cpp:838!
 #0 0x0000556885810c9b llvm::sys::PrintStackTrace(llvm::raw_ostream&) /home/sai/Shakti-TEE-Practical/llvm-project/llvm/lib/Support/Unix/Signals.inc:564:22
 #1 0x0000556885810d32 PrintStackTraceSignalHandler(void*) /home/sai/Shakti-TEE-Practical/llvm-project/llvm/lib/Support/Unix/Signals.inc:625:1
 #2 0x000055688580ea85 llvm::sys::RunSignalHandlers() /home/sai/Shakti-TEE-Practical/llvm-project/llvm/lib/Support/Signals.cpp:68:20
 #3 0x00005568858105e3 SignalHandler(int) /home/sai/Shakti-TEE-Practical/llvm-project/llvm/lib/Support/Unix/Signals.inc:406:1
 #4 0x00007fb40cf653c0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x143c0)
 #5 0x00007fb40ca2603b raise /build/glibc-sMfBJT/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #6 0x00007fb40ca05859 abort /build/glibc-sMfBJT/glibc-2.31/stdlib/abort.c:81:7
 #7 0x00005568857718f7 bindingsErrorHandler(void*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool) /home/sai/Shakti-TEE-Practical/llvm-project/llvm/lib/Support/ErrorHandling.cpp:219:55
 #8 0x00005568853fc7a8 llvm::TypeInfer::ValidateOnExit::~ValidateOnExit() /home/sai/Shakti-TEE-Practical/llvm-project/llvm/utils/TableGen/CodeGenDAGPatterns.cpp:840:1
 #9 0x00005568853f78a2 llvm::TypeInfer::MergeInTypeInfo(llvm::TypeSetByHwMode&, llvm::TypeSetByHwMode const&) /home/sai/Shakti-TEE-Practical/llvm-project/llvm/utils/TableGen/CodeGenDAGPatterns.cpp:346:31
#10 0x000055688541cf96 llvm::TreePatternNode::UpdateNodeType(unsigned int, llvm::MVT::SimpleValueType, llvm::TreePattern&) /home/sai/Shakti-TEE-Practical/llvm-project/llvm/utils/TableGen/CodeGenDAGPatterns.h:998:39
#11 0x00005568854064e5 llvm::TreePatternNode::ApplyTypeConstraints(llvm::TreePattern&, bool) (.localalias) /home/sai/Shakti-TEE-Practical/llvm-project/llvm/utils/TableGen/CodeGenDAGPatterns.cpp:2436:18
#12 0x0000556885409c50 llvm::TreePattern::InferAllTypes(llvm::StringMap<llvm::SmallVector<llvm::TreePatternNode*, 1u>, llvm::MallocAllocator> const*) /home/sai/Shakti-TEE-Practical/llvm-project/llvm/utils/TableGen/CodeGenDAGPatterns.cpp:2965:18
#13 0x0000556885410da2 llvm::CodeGenDAGPatterns::ParseOnePattern(llvm::Record*, llvm::TreePattern&, llvm::TreePattern&, std::vector<llvm::Record*, std::allocator<llvm::Record*> > const&) /home/sai/Shakti-TEE-Practical/llvm-project/llvm/utils/TableGen/CodeGenDAGPatterns.cpp:4156:30
#14 0x000055688540f4ab llvm::CodeGenDAGPatterns::ParseInstructions() /home/sai/Shakti-TEE-Practical/llvm-project/llvm/utils/TableGen/CodeGenDAGPatterns.cpp:3874:60
#15 0x000055688540a750 llvm::CodeGenDAGPatterns::CodeGenDAGPatterns(llvm::RecordKeeper&, std::function<void (llvm::TreePattern*)>) /home/sai/Shakti-TEE-Practical/llvm-project/llvm/utils/TableGen/CodeGenDAGPatterns.cpp:3068:24
#16 0x000055688565904d (anonymous namespace)::InstrInfoEmitter::InstrInfoEmitter(llvm::RecordKeeper&) /home/sai/Shakti-TEE-Practical/llvm-project/llvm/utils/TableGen/InstrInfoEmitter.cpp:46:73
#17 0x000055688565e2e2 llvm::EmitInstrInfo(llvm::RecordKeeper&, llvm::raw_ostream&) /home/sai/Shakti-TEE-Practical/llvm-project/llvm/utils/TableGen/InstrInfoEmitter.cpp:865:27
#18 0x0000556885708f8b (anonymous namespace)::LLVMTableGenMain(llvm::raw_ostream&, llvm::RecordKeeper&) /home/sai/Shakti-TEE-Practical/llvm-project/llvm/utils/TableGen/TableGen.cpp:168:5
#19 0x000055688583a5e4 llvm::TableGenMain(char const*, bool (*)(llvm::raw_ostream&, llvm::RecordKeeper&)) /home/sai/Shakti-TEE-Practical/llvm-project/llvm/lib/TableGen/Main.cpp:108:3
#20 0x0000556885709772 main /home/sai/Shakti-TEE-Practical/llvm-project/llvm/utils/TableGen/TableGen.cpp:287:22
#21 0x00007fb40ca070b3 __libc_start_main /build/glibc-sMfBJT/glibc-2.31/csu/../csu/libc-start.c:342:3
#22 0x000055688536b11e _start (/home/sai/Shakti-TEE-Practical/llvm-project/_build/bin/llvm-tblgen+0x2111e)
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
Stack dump:
0.	Program arguments: /home/sai/Shakti-TEE-Practical/llvm-project/_build/bin/llvm-tblgen -gen-instr-info -I /home/sai/Shakti-TEE-Practical/llvm-project/llvm/lib/Target/RISCV -I /home/sai/Shakti-TEE-Practical/llvm-project/_build/include -I /home/sai/Shakti-TEE-Practical/llvm-project/llvm/include -I /home/sai/Shakti-TEE-Practical/llvm-project/llvm/lib/Target /home/sai/Shakti-TEE-Practical/llvm-project/llvm/lib/Target/RISCV/RISCV.td --write-if-changed -o lib/Target/RISCV/RISCVGenInstrInfo.inc -d lib/Target/RISCV/RISCVGenInstrInfo.inc.d 
Aborted (core dumped)
[15/1563] Building RISCVGenDAGISel.inc...
FAILED: lib/Target/RISCV/RISCVGenDAGISel.inc 
cd /home/sai/Shakti-TEE-Practical/llvm-project/_build && /home/sai/Shakti-TEE-Practical/llvm-project/_build/bin/llvm-tblgen -gen-dag-isel -I /home/sai/Shakti-TEE-Practical/llvm-project/llvm/lib/Target/RISCV -I /home/sai/Shakti-TEE-Practical/llvm-project/_build/include -I /home/sai/Shakti-TEE-Practical/llvm-project/llvm/include -I /home/sai/Shakti-TEE-Practical/llvm-project/llvm/lib/Target /home/sai/Shakti-TEE-Practical/llvm-project/llvm/lib/Target/RISCV/RISCV.td --write-if-changed -o lib/Target/RISCV/RISCVGenDAGISel.inc -d lib/Target/RISCV/RISCVGenDAGISel.inc.d
Type set is empty for each HW mode:
possible type contradiction in the pattern below (use -print-records with llvm-tblgen to see all expanded records).
CHECKCAP: 	(intrinsic_void 6523:{ *:[iPTR] }, (imm:{ *:[] m1:[] m2:[] })<<P:Predicate_simm12>>:$imm12)
UNREACHABLE executed at /home/sai/Shakti-TEE-Practical/llvm-project/llvm/utils/TableGen/CodeGenDAGPatterns.cpp:838!
 #0 0x00005588ea17ec9b llvm::sys::PrintStackTrace(llvm::raw_ostream&) /home/sai/Shakti-TEE-Practical/llvm-project/llvm/lib/Support/Unix/Signals.inc:564:22
 #1 0x00005588ea17ed32 PrintStackTraceSignalHandler(void*) /home/sai/Shakti-TEE-Practical/llvm-project/llvm/lib/Support/Unix/Signals.inc:625:1
 #2 0x00005588ea17ca85 llvm::sys::RunSignalHandlers() /home/sai/Shakti-TEE-Practical/llvm-project/llvm/lib/Support/Signals.cpp:68:20
 #3 0x00005588ea17e5e3 SignalHandler(int) /home/sai/Shakti-TEE-Practical/llvm-project/llvm/lib/Support/Unix/Signals.inc:406:1
 #4 0x00007fe2996323c0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x143c0)
 #5 0x00007fe2990f303b raise /build/glibc-sMfBJT/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #6 0x00007fe2990d2859 abort /build/glibc-sMfBJT/glibc-2.31/stdlib/abort.c:81:7
 #7 0x00005588ea0df8f7 bindingsErrorHandler(void*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool) /home/sai/Shakti-TEE-Practical/llvm-project/llvm/lib/Support/ErrorHandling.cpp:219:55
 #8 0x00005588e9d6a7a8 llvm::TypeInfer::ValidateOnExit::~ValidateOnExit() /home/sai/Shakti-TEE-Practical/llvm-project/llvm/utils/TableGen/CodeGenDAGPatterns.cpp:840:1
 #9 0x00005588e9d658a2 llvm::TypeInfer::MergeInTypeInfo(llvm::TypeSetByHwMode&, llvm::TypeSetByHwMode const&) /home/sai/Shakti-TEE-Practical/llvm-project/llvm/utils/TableGen/CodeGenDAGPatterns.cpp:346:31
#10 0x00005588e9d8af96 llvm::TreePatternNode::UpdateNodeType(unsigned int, llvm::MVT::SimpleValueType, llvm::TreePattern&) /home/sai/Shakti-TEE-Practical/llvm-project/llvm/utils/TableGen/CodeGenDAGPatterns.h:998:39
#11 0x00005588e9d744e5 llvm::TreePatternNode::ApplyTypeConstraints(llvm::TreePattern&, bool) (.localalias) /home/sai/Shakti-TEE-Practical/llvm-project/llvm/utils/TableGen/CodeGenDAGPatterns.cpp:2436:18
#12 0x00005588e9d77c50 llvm::TreePattern::InferAllTypes(llvm::StringMap<llvm::SmallVector<llvm::TreePatternNode*, 1u>, llvm::MallocAllocator> const*) /home/sai/Shakti-TEE-Practical/llvm-project/llvm/utils/TableGen/CodeGenDAGPatterns.cpp:2965:18
#13 0x00005588e9d7eda2 llvm::CodeGenDAGPatterns::ParseOnePattern(llvm::Record*, llvm::TreePattern&, llvm::TreePattern&, std::vector<llvm::Record*, std::allocator<llvm::Record*> > const&) /home/sai/Shakti-TEE-Practical/llvm-project/llvm/utils/TableGen/CodeGenDAGPatterns.cpp:4156:30
#14 0x00005588e9d7d4ab llvm::CodeGenDAGPatterns::ParseInstructions() /home/sai/Shakti-TEE-Practical/llvm-project/llvm/utils/TableGen/CodeGenDAGPatterns.cpp:3874:60
#15 0x00005588e9d78750 llvm::CodeGenDAGPatterns::CodeGenDAGPatterns(llvm::RecordKeeper&, std::function<void (llvm::TreePattern*)>) /home/sai/Shakti-TEE-Practical/llvm-project/llvm/utils/TableGen/CodeGenDAGPatterns.cpp:3068:24
#16 0x00005588e9e8f8ec (anonymous namespace)::DAGISelEmitter::DAGISelEmitter(llvm::RecordKeeper&) /home/sai/Shakti-TEE-Practical/llvm-project/llvm/utils/TableGen/DAGISelEmitter.cpp:28:51
#17 0x00005588e9e90306 llvm::EmitDAGISel(llvm::RecordKeeper&, llvm::raw_ostream&) /home/sai/Shakti-TEE-Practical/llvm-project/llvm/utils/TableGen/DAGISelEmitter.cpp:186:25
#18 0x00005588ea07707b (anonymous namespace)::LLVMTableGenMain(llvm::raw_ostream&, llvm::RecordKeeper&) /home/sai/Shakti-TEE-Practical/llvm-project/llvm/utils/TableGen/TableGen.cpp:192:5
#19 0x00005588ea1a85e4 llvm::TableGenMain(char const*, bool (*)(llvm::raw_ostream&, llvm::RecordKeeper&)) /home/sai/Shakti-TEE-Practical/llvm-project/llvm/lib/TableGen/Main.cpp:108:3
#20 0x00005588ea077772 main /home/sai/Shakti-TEE-Practical/llvm-project/llvm/utils/TableGen/TableGen.cpp:287:22
#21 0x00007fe2990d40b3 __libc_start_main /build/glibc-sMfBJT/glibc-2.31/csu/../csu/libc-start.c:342:3
#22 0x00005588e9cd911e _start (/home/sai/Shakti-TEE-Practical/llvm-project/_build/bin/llvm-tblgen+0x2111e)
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
Stack dump:
0.	Program arguments: /home/sai/Shakti-TEE-Practical/llvm-project/_build/bin/llvm-tblgen -gen-dag-isel -I /home/sai/Shakti-TEE-Practical/llvm-project/llvm/lib/Target/RISCV -I /home/sai/Shakti-TEE-Practical/llvm-project/_build/include -I /home/sai/Shakti-TEE-Practical/llvm-project/llvm/include -I /home/sai/Shakti-TEE-Practical/llvm-project/llvm/lib/Target /home/sai/Shakti-TEE-Practical/llvm-project/llvm/lib/Target/RISCV/RISCV.td --write-if-changed -o lib/Target/RISCV/RISCVGenDAGISel.inc -d lib/Target/RISCV/RISCVGenDAGISel.inc.d 
Aborted (core dumped)
[16/1563] Building RISCVGenGlobalISel.inc...
FAILED: lib/Target/RISCV/RISCVGenGlobalISel.inc 
cd /home/sai/Shakti-TEE-Practical/llvm-project/_build && /home/sai/Shakti-TEE-Practical/llvm-project/_build/bin/llvm-tblgen -gen-global-isel -I /home/sai/Shakti-TEE-Practical/llvm-project/llvm/lib/Target/RISCV -I /home/sai/Shakti-TEE-Practical/llvm-project/_build/include -I /home/sai/Shakti-TEE-Practical/llvm-project/llvm/include -I /home/sai/Shakti-TEE-Practical/llvm-project/llvm/lib/Target /home/sai/Shakti-TEE-Practical/llvm-project/llvm/lib/Target/RISCV/RISCV.td --write-if-changed -o lib/Target/RISCV/RISCVGenGlobalISel.inc -d lib/Target/RISCV/RISCVGenGlobalISel.inc.d
Type set is empty for each HW mode:
possible type contradiction in the pattern below (use -print-records with llvm-tblgen to see all expanded records).
CHECKCAP: 	(intrinsic_void 6523:{ *:[iPTR] }, (imm:{ *:[] m1:[] m2:[] })<<P:Predicate_simm12>>:$imm12)
UNREACHABLE executed at /home/sai/Shakti-TEE-Practical/llvm-project/llvm/utils/TableGen/CodeGenDAGPatterns.cpp:838!
 #0 0x000055d4b7161c9b llvm::sys::PrintStackTrace(llvm::raw_ostream&) /home/sai/Shakti-TEE-Practical/llvm-project/llvm/lib/Support/Unix/Signals.inc:564:22
 #1 0x000055d4b7161d32 PrintStackTraceSignalHandler(void*) /home/sai/Shakti-TEE-Practical/llvm-project/llvm/lib/Support/Unix/Signals.inc:625:1
 #2 0x000055d4b715fa85 llvm::sys::RunSignalHandlers() /home/sai/Shakti-TEE-Practical/llvm-project/llvm/lib/Support/Signals.cpp:68:20
 #3 0x000055d4b71615e3 SignalHandler(int) /home/sai/Shakti-TEE-Practical/llvm-project/llvm/lib/Support/Unix/Signals.inc:406:1
 #4 0x00007f4e063c53c0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x143c0)
 #5 0x00007f4e05e8603b raise /build/glibc-sMfBJT/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #6 0x00007f4e05e65859 abort /build/glibc-sMfBJT/glibc-2.31/stdlib/abort.c:81:7
 #7 0x000055d4b70c28f7 bindingsErrorHandler(void*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool) /home/sai/Shakti-TEE-Practical/llvm-project/llvm/lib/Support/ErrorHandling.cpp:219:55
 #8 0x000055d4b6d4d7a8 llvm::TypeInfer::ValidateOnExit::~ValidateOnExit() /home/sai/Shakti-TEE-Practical/llvm-project/llvm/utils/TableGen/CodeGenDAGPatterns.cpp:840:1
 #9 0x000055d4b6d488a2 llvm::TypeInfer::MergeInTypeInfo(llvm::TypeSetByHwMode&, llvm::TypeSetByHwMode const&) /home/sai/Shakti-TEE-Practical/llvm-project/llvm/utils/TableGen/CodeGenDAGPatterns.cpp:346:31
#10 0x000055d4b6d6df96 llvm::TreePatternNode::UpdateNodeType(unsigned int, llvm::MVT::SimpleValueType, llvm::TreePattern&) /home/sai/Shakti-TEE-Practical/llvm-project/llvm/utils/TableGen/CodeGenDAGPatterns.h:998:39
#11 0x000055d4b6d574e5 llvm::TreePatternNode::ApplyTypeConstraints(llvm::TreePattern&, bool) (.localalias) /home/sai/Shakti-TEE-Practical/llvm-project/llvm/utils/TableGen/CodeGenDAGPatterns.cpp:2436:18
#12 0x000055d4b6d5ac50 llvm::TreePattern::InferAllTypes(llvm::StringMap<llvm::SmallVector<llvm::TreePatternNode*, 1u>, llvm::MallocAllocator> const*) /home/sai/Shakti-TEE-Practical/llvm-project/llvm/utils/TableGen/CodeGenDAGPatterns.cpp:2965:18
#13 0x000055d4b6d61da2 llvm::CodeGenDAGPatterns::ParseOnePattern(llvm::Record*, llvm::TreePattern&, llvm::TreePattern&, std::vector<llvm::Record*, std::allocator<llvm::Record*> > const&) /home/sai/Shakti-TEE-Practical/llvm-project/llvm/utils/TableGen/CodeGenDAGPatterns.cpp:4156:30
#14 0x000055d4b6d604ab llvm::CodeGenDAGPatterns::ParseInstructions() /home/sai/Shakti-TEE-Practical/llvm-project/llvm/utils/TableGen/CodeGenDAGPatterns.cpp:3874:60
#15 0x000055d4b6d5b750 llvm::CodeGenDAGPatterns::CodeGenDAGPatterns(llvm::RecordKeeper&, std::function<void (llvm::TreePattern*)>) /home/sai/Shakti-TEE-Practical/llvm-project/llvm/utils/TableGen/CodeGenDAGPatterns.cpp:3068:24
#16 0x000055d4b6f35263 (anonymous namespace)::GlobalISelEmitter::GlobalISelEmitter(llvm::RecordKeeper&) /home/sai/Shakti-TEE-Practical/llvm-project/llvm/utils/TableGen/GlobalISelEmitter.cpp:3548:33
#17 0x000055d4b6f44e5e llvm::EmitGlobalISel(llvm::RecordKeeper&, llvm::raw_ostream&) /home/sai/Shakti-TEE-Practical/llvm-project/llvm/utils/TableGen/GlobalISelEmitter.cpp:5856:28
#18 0x000055d4b705a58b (anonymous namespace)::LLVMTableGenMain(llvm::raw_ostream&, llvm::RecordKeeper&) /home/sai/Shakti-TEE-Practical/llvm-project/llvm/utils/TableGen/TableGen.cpp:246:5
#19 0x000055d4b718b5e4 llvm::TableGenMain(char const*, bool (*)(llvm::raw_ostream&, llvm::RecordKeeper&)) /home/sai/Shakti-TEE-Practical/llvm-project/llvm/lib/TableGen/Main.cpp:108:3
#20 0x000055d4b705a772 main /home/sai/Shakti-TEE-Practical/llvm-project/llvm/utils/TableGen/TableGen.cpp:287:22
#21 0x00007f4e05e670b3 __libc_start_main /build/glibc-sMfBJT/glibc-2.31/csu/../csu/libc-start.c:342:3
#22 0x000055d4b6cbc11e _start (/home/sai/Shakti-TEE-Practical/llvm-project/_build/bin/llvm-tblgen+0x2111e)
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
Stack dump:
0.	Program arguments: /home/sai/Shakti-TEE-Practical/llvm-project/_build/bin/llvm-tblgen -gen-global-isel -I /home/sai/Shakti-TEE-Practical/llvm-project/llvm/lib/Target/RISCV -I /home/sai/Shakti-TEE-Practical/llvm-project/_build/include -I /home/sai/Shakti-TEE-Practical/llvm-project/llvm/include -I /home/sai/Shakti-TEE-Practical/llvm-project/llvm/lib/Target /home/sai/Shakti-TEE-Practical/llvm-project/llvm/lib/Target/RISCV/RISCV.td --write-if-changed -o lib/Target/RISCV/RISCVGenGlobalISel.inc -d lib/Target/RISCV/RISCVGenGlobalISel.inc.d 
Aborted (core dumped)
[31/1563] Building CXX object lib/Passes/CMakeFiles/LLVMPasses.dir/PassBuilder.cpp.o
ninja: build stopped: subcommand failed.

So you need to fix your RISCVInstrInfo.td (or similar) changes to not have a type contradiction in the operands. TableGen isn’t great at errors here, some things that should be proper errors are unreachables or assertions. With an assertion-less TableGen it then accepts bogus input and produces bogus output from it that then goes onto crash LLVM when used at run time. It is always recommended that a TableGen with assertions be used for any development; fully-optimised TableGen binaries should only be used in order to speed up builds of known-good LLVM trees.

Thank you. I will look into RISCVInstrInfo.td changes and fix up those.

Hello @topperc
When I compile my code with my custom pass enabled, some debug assertions fail. This is mainly due to the way my custom pass is written.
Is there a way to find out the reason behind these UnreachableInst error without enabling debug mode?

I recommend building with cmake -DLLVM_ENABLE_ASSERTIONS=ON which will enable debug printing without having to a full debug build.

Thanks for the suggestion @topperc. I will try following this approach.