<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/155329>155329</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang] Nonsensical warning for out-of-bounds access to vector type
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
keinflue
</td>
</tr>
</table>
<pre>
https://godbolt.org/z/7s9cqq5xG:
```cpp
int f(int __attribute__((vector_size(8))) v) {
return v[~0UL/8];
}
```
```
<source>:2:10: warning: array index 2305843009213693951 refers past the last possible element for an array in 64-bit address space containing 64-bit (8-byte) elements (max possible 2305843009213693952 elements) [-Warray-bounds]
2 | return v[~0UL/8];
| ^ ~~~~~~
<source>:1:7: note: array 'v' declared here
1 | int f(int __attribute__((vector_size(8))) v) {
| ^
1 warning generated.
Compiler returned: 0
```
The warning makes no sense given that the index represents 4-byte elements and that the limit is known statically to be `2`. For smaller out-of-bounds indices there is no warning at all. (GCC provides a correct warning in all cases with `-Warray-bounds`.)
Adapted from https://github.com/llvm/llvm-project/issues/154713, but this issue is present since Clang 13.0.0.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJysVEGP6yYQ_jWTyygWhmA7Bx-82Zd3qXpq1eMK43FCl4Af4OzuO7zfXuFkkzZPqlSpCBlkhplvvm8YFaM5OKIW5BPI55Wa09GH9pWMG-1Mq94PH-0xpSmC6IDvge8Pfui9TYUPB-D778D3ddzqb9_k-9dswzqo2GXqaQLWGZdwBN7k9eVFpRRMPyd6eQHeAG_OpJMPL9F8J-BNA3x7mXjOH6ifgHWIgdIcHJ5BPv1gv_8CfN-AfAaRT6F-_nvUx73YRT8HTSC-gOg4iK5kIDp8U8EZd8hbFYL6QOMGekcumGw2grEtL0W1FVtZYqCRQsRJxYTpSGjzZvIxmt4SkqUT5SR9QOVuzrDarHuTUA1DoBgxTkoTau-SMjnw53nOet1_J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