llvm / llvm-project

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

SPIRV::SPIRVBinary::validate assertion crashed #61720

Open thenumbernine opened 1 year ago

thenumbernine commented 1 year ago

Hello, I crashed LLVM, and it asked me to submit a bug, so here it is:

> llvm-spirv "cache/0c2c3f7472583358/bc/solver.bc" -o "cache/0c2c3f7472583358/spv/solver.spv"
llvm-spirv: ./lib/SPIRV/libSPIRV/SPIRVInstruction.h:636: virtual void SPIRV::SPIRVBinary::validate() const: Assertion `(Op1Ty->isTypeInt() || Op2Ty->isTypeFloat()) && "Invalid type for Binary instruction"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.  Program arguments: llvm-spirv cache/0c2c3f7472583358/bc/solver.bc -o cache/0c2c3f7472583358/spv/solver.spv
1.  Running pass 'LLVMToSPIRV' on module 'cache/0c2c3f7472583358/bc/solver.bc'.
 #0 0x00007fd268451a61 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/lib/x86_64-linux-gnu/libLLVM-14.so.1+0xe51a61)
 #1 0x00007fd26844f78e llvm::sys::RunSignalHandlers() (/lib/x86_64-linux-gnu/libLLVM-14.so.1+0xe4f78e)
 #2 0x00007fd268451f96 (/lib/x86_64-linux-gnu/libLLVM-14.so.1+0xe51f96)
 #3 0x00007fd266e3bcf0 (/lib/x86_64-linux-gnu/libc.so.6+0x3bcf0)
 #4 0x00007fd266e9226b __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #5 0x00007fd266e9226b __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #6 0x00007fd266e9226b pthread_kill ./nptl/pthread_kill.c:89:10
 #7 0x00007fd266e3bc46 raise ./signal/../sysdeps/posix/raise.c:27:6
 #8 0x00007fd266e227fc abort ./stdlib/abort.c:81:7
 #9 0x00007fd266e2271b _nl_load_domain ./intl/loadmsgcat.c:1177:9
#10 0x00007fd266e33596 (/lib/x86_64-linux-gnu/libc.so.6+0x33596)
#11 0x00007fd26e14fa4f SPIRV::SPIRVBinary::validate() const ./build/lib/SPIRV/./lib/SPIRV/libSPIRV/SPIRVInstruction.h:636:7
#12 0x00007fd26e245054 SPIRV::SPIRVInstTemplateBase::create(spv::Op, SPIRV::SPIRVType*, unsigned int, std::vector<unsigned int, std::allocator<unsigned int>> const&, SPIRV::SPIRVBasicBlock*, SPIRV::SPIRVModule*) ./build/lib/SPIRV/./lib/SPIRV/libSPIRV/SPIRVInstruction.h:207:0
#13 0x00007fd26e2541e3 SPIRV::SPIRVModuleImpl::addBinaryInst(spv::Op, SPIRV::SPIRVType*, SPIRV::SPIRVValue*, SPIRV::SPIRVValue*, SPIRV::SPIRVBasicBlock*) ./build/lib/SPIRV/./lib/SPIRV/libSPIRV/SPIRVModule.cpp:1352:0
#14 0x00007fd26e1b2401 SPIRV::LLVMToSPIRVBase::transBinaryInst(llvm::BinaryOperator*, SPIRV::SPIRVBasicBlock*) ./build/lib/SPIRV/./lib/SPIRV/SPIRVWriter.cpp:1030:22
#15 0x00007fd26e1b6994 SPIRV::LLVMToSPIRVBase::transValueWithoutDecoration(llvm::Value*, SPIRV::SPIRVBasicBlock*, bool, SPIRV::LLVMToSPIRVBase::FuncTransMode) ./build/lib/SPIRV/./lib/SPIRV/SPIRVWriter.cpp:1674:20
#16 0x00007fd26e1af065 SPIRV::LLVMToSPIRVBase::transValue(llvm::Value*, SPIRV::SPIRVBasicBlock*, bool, SPIRV::LLVMToSPIRVBase::FuncTransMode) ./build/lib/SPIRV/./lib/SPIRV/SPIRVWriter.cpp:1011:40
#17 0x00007fd26e1c8ba3 llvm::ilist_node_base<false>::getNext() const /usr/lib/llvm-14/include/llvm/ADT/ilist_node_base.h:29:45
#18 0x00007fd26e1c8ba3 llvm::ilist_node_impl<llvm::ilist_detail::node_options<llvm::Instruction, false, false, void>>::getNext() /usr/lib/llvm-14/include/llvm/ADT/ilist_node.h:67:66
#19 0x00007fd26e1c8ba3 llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Instruction, false, false, void>, false, false>::operator++() /usr/lib/llvm-14/include/llvm/ADT/ilist_iterator.h:157:25
#20 0x00007fd26e1c8ba3 SPIRV::LLVMToSPIRVBase::transFunction(llvm::Function*) ./build/lib/SPIRV/./lib/SPIRV/SPIRVWriter.cpp:3976:21
#21 0x00007fd26e1cb4c8 SPIRV::LLVMToSPIRVBase::translate() ./build/lib/SPIRV/./lib/SPIRV/SPIRVWriter.cpp:4040:17
#22 0x00007fd26e1ae20c SPIRV::LLVMToSPIRVBase::runLLVMToSPIRV(llvm::Module&) ./build/lib/SPIRV/./lib/SPIRV/SPIRVWriter.cpp:170:1
#23 0x00007fd26858d306 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/lib/x86_64-linux-gnu/libLLVM-14.so.1+0xf8d306)
#24 0x00007fd26e1ce31c llvm::writeSpirv(llvm::Module*, SPIRV::TranslatorOpts const&, std::ostream&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&) ./build/lib/SPIRV/./lib/SPIRV/SPIRVWriter.cpp:4895:19
#25 0x000055d9813dfc86 convertLLVMToSPIRV ./build/tools/llvm-spirv/./tools/llvm-spirv/llvm-spirv.cpp:328:3
#26 0x000055d9813dfc86 main ./build/tools/llvm-spirv/./tools/llvm-spirv/llvm-spirv.cpp:730:30
#27 0x00007fd266e23510 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#28 0x00007fd266e235c9 call_init ./csu/../csu/libc-start.c:128:20
#29 0x00007fd266e235c9 __libc_start_main ./csu/../csu/libc-start.c:368:5
#30 0x000055d9813e0605 (/usr/bin/llvm-spirv-14+0x26605)
Aborted (core dumped)

Here's how the bytecode was compiled:

> clang -v -Xclang -finclude-default-header --target=spirv64-unknown-unknown -emit-llvm -c -o "cache/0c2c3f7472583358/bc/solver.bc" "cache/0c2c3f7472583358/src/solver.clcpp"
Ubuntu clang version 15.0.6
Target: spirv64-unknown-unknown
Thread model: posix
InstalledDir: /usr/bin
 (in-process)
 "/usr/lib/llvm-15/bin/clang" -cc1 -triple spirv64-unknown-unknown -Wspir-compat -no-opaque-pointers -emit-llvm-bc -emit-llvm-uselists -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name solver.clcpp -mrelocation-model static -mframe-pointer=all -ffp-contract=on -fno-rounding-math -fno-verbose-asm -mconstructor-aliases -mllvm -treat-scalable-fixed-error-as-warning -debugger-tuning=gdb -v -fcoverage-compilation-dir=/home/chris/Projects/lua/hydro-cl -resource-dir /usr/lib/llvm-15/lib/clang/15.0.6 -fdebug-compilation-dir=/home/chris/Projects/lua/hydro-cl -ferror-limit 19 -finclude-default-header -fdeclare-opencl-builtins -fgnuc-version=4.2.1 -fno-threadsafe-statics -fcolor-diagnostics -finclude-default-header -o cache/0c2c3f7472583358/bc/solver.bc -x clcpp cache/0c2c3f7472583358/src/solver.clcpp
clang -cc1 version 15.0.6 based upon LLVM 15.0.6 default target x86_64-pc-linux-gnu
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/lib/llvm-15/lib/clang/15.0.6/include
 /usr/include
End of search list.

The code that was being compiled is 12,000 lines long, IDK if you want me to post that as well.

jcranmer-intel commented 1 year ago

The crash in question is in the LLVM SPIR-V translator tool, located at https://github.com/KhronosGroup/SPIRV-LLVM-Translator, not in llvm itself.

As for tests, it's not really actionable without the original source code. You can run it through creduce to get a much smaller file for reproducing the same failure.