<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/136379>136379</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
-Warray-bounds misses unsafe pointer arithmetic
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
shuffle2
</td>
</tr>
</table>
<pre>
I would expect the following to issue a warning:
```c
void g(uint64_t a, uint64_t b) {
printf("%lx %lx\n", a, b);
}
int main(int argc, char **argv) {
uint8_t a;
// one-past the end is valid (as long as not deref'd)
g((uint64_t)&a, (uint64_t)(&a + 1));
// >1 past end is invalid
// XXX clang has -Warray-bounds, but it does not warn on the below.
// clang's -Wunsafe-buffer-usage *does* warn on it, though.
// -Wunsafe-buffer-usage doesn't seem usable in real world tho for C code. (lots of false positives).
g((uint64_t)&a, (uint64_t)(&a + 2));
return 0;
}
```
gcc detects this as I'd expect, clang does not: https://godbolt.org/z/WEYTzMGGb
It's unclear to me if -Wunsafe-buffer-usage is the expected solution here - this flag seems unhelpful for plain C code. https://clang.llvm.org/docs/SafeBuffers.html makes it sound like the flag is mainly for use in C++ code, to detect locations that should be converted to c++-specific code patterns.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJykVE-To7YT_TTi0mUXCGPsAwfsWW_N4Xf6pWonp1QjGlBWSJT-2Dv76VMSHieeJKdUucAI-vXr168bnZOjJmpYdWLVS4bBT8Y2bgrDoIhnnenfm1e4maB6oB8LCQ9-IhiMUuYm9QjegHQuECDc0GqpR1a2LG_ZPl9_guXt1cgeRsYPQWq_3_3mARk_w-OpY_wIrD6xvAUAWKzUfmD8wDhnvFI_IF1Zddbp5LyGxyhWxiBWv8Rr3krtYUapGT_Ev2hHEb8UE1pgvGW8RTten7NFFodEqfw4-rjxC-MXMJo2C7q1ctI9SAdXVLIHxg_oQBk9AjrQxkNPlgbG6z5yW1HGV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