Skip to content

-Warray-bounds does not work when indexing outside of bounds via pointer arithmetic instead of subscript operator #170021

@inicula

Description

@inicula

This code shows no errors when compiled with -Wall -Wextra -Wpedantic -Werror:

#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):

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"

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions