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

    <tr>
        <th>Summary</th>
        <td>
            [HLSL] Investigate how to handle erroring/warning of out-of-bounds vector access
        </td>
    </tr>

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

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

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

<pre>
    Currently, Clang does not emit a warning or error upon encountering an out-of-bounds vector index.
This does not match DXC behavior, which emits an error 

https://godbolt.org/z/3Mfjvn5Ex
```hlsl
export float test(float4 v4) {
    return v4[5];
}
/* DXC output
<source>:2:15: error: vector element index '5' is out of bounds
    return v4[5];
 ^
*/
```

https://godbolt.org/z/zGc9ox5d1
```hlsl
export float2 test(float4 v4) {
    float2 res = { v4[4], v4[5] };
    return res;
}
/* DXC output
error: validation errors
<source>:3:5: error: Instructions should not read uninitialized value.
note: at 'ret <2 x float> undef' in block '#0' of function '?test@@YA?AV?$vector@M$01@@V?$vector@M$03@@@Z'.
Validation failed.
*/
```

Should we match DXC behavior and error upon encountering an out-of-bounds vector index? Or should we simply create a warning?
Should we error/warn only for HLSL, or for all languages? Perhaps error for HLSL but warn for all other languages?

An error for out-of-bounds vector indexing has attempted to be implemented before (#128952), but it broke builds (see https://github.com/llvm/llvm-project/pull/128952#issuecomment-2717565787).

We should also consider what @efriedma-quic mentioned (https://github.com/llvm/llvm-project/pull/128952#discussion_r2004302122) about generally not wanting to have differing semantic rules based on whether or not a value is constant.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJykVVuP2zYT_TXjl8EaEimtVg9-ULyr7wuQoAVSpJeXghJHFhOadHmxd_Pri5F2u0maJr0Ahm1yODNnzpwhVYzm4Ih2UL-A-najcpp92L0c_Uw6eLcZvH7Y7XMI5JJ9ALHHvVXugNpTROcT0tEkVHhRw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