KhronosGroup / KhronosGroup/SPIRV-LLVM-Translator
OpenCL (CLC++2021) compilation to SPIR-V fails
- Dominant language
- LLVM
- Stars
- 625
- Forks
- 279
- Avg merge
- 3d 5h
- Merged PRs (30d)
- 34
Description
I opened this issue as an LLVM issue first, but LLVM experts indicated the problem is with the SPIRV-LLVM-Translator:
https://github.com/llvm/llvm-project/issues/68305
Thus I am opening it also here:
Compilation with clang 17.0.2 (on Gentoo Linux) fails with the below error message. I was using clang 15 before, which didn't fail. I also tried clang 16 now, which failed with the same error, I didn't try other versions.
I am attaching a tarball with my .cl file, and with the 2 files in /tmp that clang asked me to attach to the bug report:
[bugreport.tar.gz](https://github.com/KhronosGroup/SPIRV-LLVM-Translator/files/13070840/bugreport.tar.gz)
Command to reproduce:
```
clang-17 -O0 --target=spirv64 -ferror-limit=1000 -Dcl_clang_storage_class_specifiers -Wno-invalid-constexpr -Wno-unused-command-line-argument -cl-std=CLC++2021 -Xclang -fdenormal-fp-math-f32=ieee -cl-mad-enable -cl-no-signed-zeros -c foo.cl -o foo.spirv
```
Error message:
```
llvm-spirv: /usr/lib/llvm/17/include/llvm/ADT/SmallVector.h:294: T& llvm::SmallVectorTemplateCommon >::operator[](size_type) [with T = llvm::Type*; = void; reference = llvm::Type*&; size_type = long unsigned int]: Assertion `idx < size()' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: /usr/lib/llvm/17/bin/llvm-spirv /tmp/foo-21cdb2.bc -o /home/qon/foo.spirv
#0 0x00007f161a086fae llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/lib/llvm/17/lib64/libLLVM-17.so+0xc86fae)
#1 0x00007f161a084c44 llvm::sys::RunSignalHandlers() (/usr/lib/llvm/17/lib64/libLLVM-17.so+0xc84c44)
#2 0x00007f161a084db6 (/usr/lib/llvm/17/lib64/libLLVM-17.so+0xc84db6)
#3 0x00007f1618e641b0 (/lib64/libc.so.6+0x391b0)
#4 0x00007f1618eb208c (/lib64/libc.so.6+0x8708c)
#5 0x00007f1618e64112 gsignal (/lib64/libc.so.6+0x39112)
#6 0x00007f1618e4d4f2 abort (/lib64/libc.so.6+0x224f2)
#7 0x00007f1618e4d415 (/lib64/libc.so.6+0x22415)
#8 0x00007f1618e5cd32 (/lib64/libc.so.6+0x31d32)
#9 0x00007f16213da2bf SPIRV::BuiltinCallMutator::doConversion() (/usr/lib/llvm/17/lib64/libLLVMSPIRVLib.so.17+0x1da2bf)
#10 0x00007f16213a03ef (/usr/lib/llvm/17/lib64/libLLVMSPIRVLib.so.17+0x1a03ef)
#11 0x00007f16213a90fb SPIRV::OCLToSPIRVBase::transBuiltin(llvm::CallInst*, OCLUtil::OCLBuiltinTransInfo&) (/usr/lib/llvm/17/lib64/libLLVMSPIRVLib.so.17+0x1a90fb)
#12 0x00007f16213aa280 SPIRV::OCLToSPIRVBase::visitCallBuiltinSimple(llvm::CallInst*, llvm::StringRef, llvm::StringRef) (/usr/lib/llvm/17/lib64/libLLVMSPIRVLib.so.17+0x1aa280)
#13 0x00007f16213b189c SPIRV::OCLToSPIRVBase::visitCallInst(llvm::CallInst&) (/usr/lib/llvm/17/lib64/libLLVMSPIRVLib.so.17+0x1b189c)
#14 0x00007f16213a0841 SPIRV::OCLToSPIRVBase::runOCLToSPIRV(llvm::Module&) (/usr/lib/llvm/17/lib64/libLLVMSPIRVLib.so.17+0x1a0841)
#15 0x00007f16213a0b6e SPIRV::OCLToSPIRVPass::run(llvm::Module&, llvm::AnalysisManager&) (/usr/lib/llvm/17/lib64/libLLVMSPIRVLib.so.17+0x1a0b6e)
#16 0x00007f16214b021d (/usr/lib/llvm/17/lib64/libLLVMSPIRVLib.so.17+0x2b021d)
#17 0x00007f16214f4f27 (/usr/lib/llvm/17/lib64/libLLVMSPIRVLib.so.17+0x2f4f27)
#18 0x000055b379753efd (/usr/lib/llvm/17/bin/llvm-spirv+0x13efd)
#19 0x000055b37974d0c2 (/usr/lib/llvm/17/bin/llvm-spirv+0xd0c2)
#20 0x00007f1618e4eb8a (/lib64/libc.so.6+0x23b8a)
#21 0x00007f1618e4ec45 __libc_start_main (/lib64/libc.so.6+0x23c45)
#22 0x000055b37974d471 (/usr/lib/llvm/17/bin/llvm-spirv+0xd471)
clang-17: error: unable to execute command: Aborted
clang-17: error: llvm-spirv command failed due to signal (use -v to see invocation)
clang version 17.0.2
Target: spirv64
Thread model: posix
InstalledDir: /usr/lib/llvm/17/bin
clang-17: note: diagnostic msg:
********************
PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-17: note: diagnostic msg: /tmp/foo-f70c1d.cl
clang-17: note: diagnostic msg: /tmp/foo-f70c1d.sh
clang-17: note: diagnostic msg:
********************
```
Contributor guide
Research direction
Start with the attached bugreport.tar.gz and reproduce the failure using the clang-17 command in the issue. Trace the stack from SPIRV::BuiltinCallMutator::doConversion through OCLToSPIRVBase::transBuiltin to identify the failing translation path. Done means the command no longer aborts and produces foo.spirv.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100