<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/68305>68305</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            OpenCL (CLC++2021) compilation to SPIR-V fails
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          davidrohr
      </td>
    </tr>
</table>

<pre>
    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/llvm/llvm-project/files/12816718/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<T, <template-parameter-1-2> >::operator[](size_type) [with T = llvm::Type*; <template-parameter-1-2> = 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<llvm::Module>&) (/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: 

********************
```

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysWFtz4yoS_jXkhZJLQjf7wQ--xGdS5dmkJj5z9i2FoCWzg8ALKJf59VsgJbY8M8nsJKmUbbXor7-mm4aGWisaBTBH-RLl6wvaub02c07vBTd6by4qzZ_mK90ehKROaIUfhNtjJqlqcFJO4gnBiEy1wn-BclrjrVDdIyIzXFMhbT_a7QFXIPUDBmO0wS1YSxuY4Cv8QC3urFDNM2SOK6i1AURW-GEv2B5zwRUipQuIXodKq7EzAvizUoGVfjhq-IHAj7YtbaE37cdcHRGdecLa7cHgezBWaGUnKF6jeNF_XmHaYuocZXvPkGJHTUWl7JHbJzxhEtdCBrJUnVgkQWyxUBiRjWsP2O2pG-hS-w04bgE7PaD7X2GSugYbOGjjULrAA5V8WXVNL504aibNd5SvEZnunTtYlC4Q2SCyaYTbd9WE6RaRjZT3z1_Rwej_AHOIbAIlRDYJmSZFmUwR2fyATGanE7DSbev9ctrTMpp3DLzFfkgRD__hMfgWJSWOrm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