<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/61935>61935</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang crash due to missing LLVM IR type checks
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
feldentm
</td>
</tr>
</table>
<pre>
Clang asks me to file a bug report, so here are the details:
```
error from subprocess clang for test
call: clang-12 -O3 -o test.1.tests test.1.bc -lc
error message:
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0. Program arguments: /usr/lib/llvm-12/bin/clang -cc1 -triple x86_64-pc-linux-gnu -emit-obj --mrelax-relocations -disable-free -disable-llvm-verifier -discard-value-names -main-file-name test.1.bc -mrelocation-model static -mframe-pointer=none -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib/llvm-12/lib/clang/12.0.1 -O3 -fdebug-compilation-dir /home/feldentm/tyr/conformance/0.7.0/accept/unevaluatedUnion -ferror-limit 19 -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -faddrsig -o /tmp/test-2d1adc.o -x ir test.1.bc
1. Code generation
2. Running pass 'Function Pass Manager' on module 'test.1.bc'.
3. Running pass 'X86 DAG->DAG Instruction Selection' on function '@main'
#0 0x00007f37bb9b3871 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/lib/x86_64-linux-gnu/libLLVM-12.so.1+0xd26871)
#1 0x00007f37bb9b19a0 llvm::sys::RunSignalHandlers() (/usr/lib/x86_64-linux-gnu/libLLVM-12.so.1+0xd249a0)
#2 0x00007f37bb9b3f82 (/usr/lib/x86_64-linux-gnu/libLLVM-12.so.1+0xd26f82)
#3 0x00007f37c34fe420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
#4 0x00007f37bb8d1fc0 llvm::APInt::trunc(unsigned int) const (/usr/lib/x86_64-linux-gnu/libLLVM-12.so.1+0xc44fc0)
#5 0x00007f37bc0f1247 llvm::TargetLowering::SimplifyDemandedBits(llvm::SDValue, llvm::APInt const&, llvm::APInt const&, llvm::KnownBits&, llvm::TargetLowering::TargetLoweringOpt&, unsigned int, bool) const (/usr/lib/x86_64-linux-gnu/libLLVM-12.so.1+0x1464247)
#6 0x00007f37bc0f78d3 llvm::TargetLowering::SimplifyDemandedBits(llvm::SDValue, llvm::APInt const&, llvm::APInt const&, llvm::KnownBits&, llvm::TargetLowering::TargetLoweringOpt&, unsigned int, bool) const (/usr/lib/x86_64-linux-gnu/libLLVM-12.so.1+0x146a8d3)
#7 0x00007f37bc0ed7bd llvm::TargetLowering::SimplifyDemandedBits(llvm::SDValue, llvm::APInt const&, llvm::APInt const&, llvm::KnownBits&, llvm::TargetLowering::TargetLoweringOpt&, unsigned int, bool) const (/usr/lib/x86_64-linux-gnu/libLLVM-12.so.1+0x14607bd)
#8 0x00007f37bc0f16eb llvm::TargetLowering::SimplifyDemandedBits(llvm::SDValue, llvm::APInt const&, llvm::APInt const&, llvm::KnownBits&, llvm::TargetLowering::TargetLoweringOpt&, unsigned int, bool) const (/usr/lib/x86_64-linux-gnu/libLLVM-12.so.1+0x14646eb)
#9 0x00007f37bc0ec441 llvm::TargetLowering::SimplifyDemandedBits(llvm::SDValue, llvm::APInt const&, llvm::KnownBits&, llvm::TargetLowering::TargetLoweringOpt&, unsigned int, bool) const (/usr/lib/x86_64-linux-gnu/libLLVM-12.so.1+0x145f441)
#10 0x00007f37bbf54cbf (/usr/lib/x86_64-linux-gnu/libLLVM-12.so.1+0x12c7cbf)
#11 0x00007f37bbf27d78 (/usr/lib/x86_64-linux-gnu/libLLVM-12.so.1+0x129ad78)
#12 0x00007f37bbef3e73 (/usr/lib/x86_64-linux-gnu/libLLVM-12.so.1+0x1266e73)
#13 0x00007f37bbef2433 llvm::SelectionDAG::Combine(llvm::CombineLevel, llvm::AAResults*, llvm::CodeGenOpt::Level) (/usr/lib/x86_64-linux-gnu/libLLVM-12.so.1+0x1265433)
#14 0x00007f37bc0d2b06 llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/usr/lib/x86_64-linux-gnu/libLLVM-12.so.1+0x1445b06)
#15 0x00007f37bc0d240a llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/usr/lib/x86_64-linux-gnu/libLLVM-12.so.1+0x144540a)
#16 0x00007f37bc0cff96 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/usr/lib/x86_64-linux-gnu/libLLVM-12.so.1+0x1442f96)
#17 0x00007f37bdca6e05 (/usr/lib/x86_64-linux-gnu/libLLVM-12.so.1+0x3019e05)
#18 0x00007f37bbcd560e llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/usr/lib/x86_64-linux-gnu/libLLVM-12.so.1+0x104860e)
#19 0x00007f37bbae74f0 llvm::FPPassManager::runOnFunction(llvm::Function&) (/usr/lib/x86_64-linux-gnu/libLLVM-12.so.1+0xe5a4f0)
#20 0x00007f37bbaed0a3 llvm::FPPassManager::runOnModule(llvm::Module&) (/usr/lib/x86_64-linux-gnu/libLLVM-12.so.1+0xe600a3)
#21 0x00007f37bbae7af8 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/usr/lib/x86_64-linux-gnu/libLLVM-12.so.1+0xe5aaf8)
#22 0x00007f37c1d51ac6 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::DataLayout const&, llvm::Module*, clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream> >) (/usr/lib/x86_64-linux-gnu/libclang-cpp.so.12+0x15a9ac6)
#23 0x00007f37c1ffbffc clang::CodeGenAction::ExecuteAction() (/usr/lib/x86_64-linux-gnu/libclang-cpp.so.12+0x1853ffc)
#24 0x00007f37c2735456 clang::FrontendAction::Execute() (/usr/lib/x86_64-linux-gnu/libclang-cpp.so.12+0x1f8d456)
#25 0x00007f37c26bd331 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/usr/lib/x86_64-linux-gnu/libclang-cpp.so.12+0x1f15331)
#26 0x00007f37c279c8e6 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/usr/lib/x86_64-linux-gnu/libclang-cpp.so.12+0x1ff48e6)
#27 0x0000000000412ab9 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/usr/lib/llvm-12/bin/clang+0x412ab9)
#28 0x0000000000410dbf (/usr/lib/llvm-12/bin/clang+0x410dbf)
#29 0x0000000000410bb6 main (/usr/lib/llvm-12/bin/clang+0x410bb6)
#30 0x00007f37ba771083 __libc_start_main /build/glibc-SzIz7B/glibc-2.31/csu/../csu/libc-start.c:342:3
#31 0x000000000040ddce _start (/usr/lib/llvm-12/bin/clang+0x40ddce)
clang: error: unable to execute command: Segmentation fault (core dumped)
clang: error: clang frontend command failed due to signal (use -v to see invocation)
Ubuntu clang version 12.0.1-++20211029101322+fed41342a82f-1~exp1~20211029221816.4
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
clang: note: diagnostic msg: Error generating preprocessed source(s) - no preprocessable inputs.
```
The issue is that LLVM's llvm::verifyModule does not fully type check the module and it also seems to have issues with structural checks of individual instructions. I've seen similar issues repeatedly with lli but this is the first one with clang. My reaction would be to improve verifyModule instead of making clang more robust; if I knew how to do it, I'd contribute a patch.
What surprises me every time I face such an issue is that it feels as if I were the only one writing compilers for languages that are not exactly copies of C or C++.
Files to reproduce the issue; ll file is just to get the correct error message. [unevaluatedUnion.zip](https://github.com/llvm/llvm-project/files/11152038/unevaluatedUnion.zip)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWk9z27iS_zT0pYsqEqQo6uCD_Ed5rk0qqfi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