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

    <tr>
        <th>Summary</th>
        <td>
            Crash on clang15 when using opencl-c.h without __opencl_c_images support
        </td>
    </tr>

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

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

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

<pre>
    

Command:
```
/usr/lib/llvm-15/bin/clang -cc1 -include /usr/lib/llvm-15/lib/clang/15.0.2/include/opencl-c.h ./test.cl -cl-std=CL3.0 -cl-ext=-__opencl_c_images,-__opencl_c_read_write_images,-__opencl_c_3d_image_writes,-cl_khr_3d_image_writes
```

Generate errors:
```
In file included from <built-in>:1:
/usr/lib/llvm-15/lib/clang/15.0.2/include/opencl-c.h:15178:46: error: use of type '__read_only image2d_t' requires __opencl_c_images support
float4 __ovld __purefn read_imagef(read_only image2d_t, sampler_t, int2);
                                             ^
/usr/lib/llvm-15/lib/clang/15.0.2/include/opencl-c.h:15178:57: error: use of type 'sampler_t' requires __opencl_c_images support
float4 __ovld __purefn read_imagef(read_only image2d_t, sampler_t, int2);
                                                        ^
/usr/lib/llvm-15/lib/clang/15.0.2/include/opencl-c.h:15179:46: error: use of type '__read_only image2d_t' requires __opencl_c_images support
float4 __ovld __purefn read_imagef(read_only image2d_t, sampler_t, float2);
                                             ^
/usr/lib/llvm-15/lib/clang/15.0.2/include/opencl-c.h:15179:57: error: use of type 'sampler_t' requires __opencl_c_images support
float4 __ovld __purefn read_imagef(read_only image2d_t, sampler_t, float2);


```
The issue occurs even on an empty kernel.

The issue did not happen when __opencl_c_images support is provided.

I found out that the issue is probably caused by https://reviews.llvm.org/D103911
Not every function in opencl-c.h with uses images are under one of the ifdef
- __opencl_c_images,
- __opencl_c_read_write_images,
- __opencl_c_3d_image_writes,
- cl_khr_3d_image_writes

This is probably the cause of the error.


**My reproduction steps:**

```
docker run -it ubuntu:20.04 bash
apt-get update
apt install lsb-release wget software-properties-common gnupg
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
./llvm.sh 15
echo "kernel void test_kernel() {}" > test.cl
/usr/lib/llvm-15/bin/clang -cc1 -include /usr/lib/llvm-15/lib/clang/15.0.2/include/opencl-c.h ./test.cl -cl-std=CL3.0 -cl-ext=-__opencl_c_images,-__opencl_c_read_write_images,-__opencl_c_3d_image_writes,-cl_khr_3d_image_writes 
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJztVkuP2zYQ_jXyZSBBD0u2DjpkvbtFgLan3g1KHFnM0pTKhx3313dE2lk76w1QoAESIIJA8TEzmvnm45DtyE9NlD5G6YfQbsb9nikeFedxVKXnNwzzZ2c0tVK0cysP-zgrqdcKRW0nmdpB3HUZxEJ10nGEd1XC2KvQNyuTNMmpc9aj3jgh9eMuGSChoUVjk06SeRkbSy4-bn4vktSP8bOlcbzdBp1ttxV7tkMT5ZvrSY2Mb49aWLy_XvAwH2T8Ks2_DPrNyl1wfPsbKtTMIqDWozbvIflRQS8kwjlcDr0e9xAVm9YJaQm9qHgi3exV_3_AcTZYZqs1fZcVNcHHueMMwtiDPU1zxlbbANWo5Al83DnfWpoHjX87odHAG6jBuGkatQ3e9nJkdjlLHSSnz-Q09gq8VS_fR_n67j82YNh-kqjDQChL0dRR8RAMw395ovLpu4BXrr4F3pX_Pxtg3xm7-icinjf0Y1Gv_sGp9xay6CmP1mn0obo_vC2Jfw1UDo1xFFHXOW0AD6hgVMAU4H6yJ3hBrVAm1-X2VYkLDmq0MLCJooXjQM27kZMOTHo8CCq9N_Y-Qj86xWF0FuzA5ubyg6DSspZA6Bghz6E9wWDt5Kt8_kyvxoPAo0nmNCejnjP7mKVFnWXB_J_kIIWlT9A71VlB0QmK8fWkOwo7zFk1cHaYaQRyCDUhEXI9O9Rzyoq3GL8NknJxZ-3e4XdH7O0ZeBH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