Issue 170021
Summary -Warray-bounds does not work when indexing outside of bounds via pointer arithmetic instead of subscript operator
Labels new issue
Assignees
Reporter inicula
    This code shows no errors when compiled with `-Wall -Wextra -Wpedantic -Werror`:

```cpp
#include <cstdio>

int main()
{
    int arr[10] = {1,2,3};
    printf("%d\n", *(arr + 10));
}
```

But the indexing operation is optimized away nonetheless (`-O3 -Wall -Wextra -Wpedantic -Werror`):
```asm
main:
        push rax
        lea     rdi, [rip + .L.str]
        xor     eax, eax
 call    printf@PLT
        xor     eax, eax
        pop     rcx
 ret

.L.str:
        .asciz  "%d\n"
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to