Extend -Warray-bounds to detect out-of-bounds accesses to array parameters.
authorMartin Sebor <msebor@redhat.com>
Sat, 19 Sep 2020 23:47:29 +0000 (17:47 -0600)
committerMartin Sebor <msebor@redhat.com>
Sat, 19 Sep 2020 23:56:13 +0000 (17:56 -0600)
commit3f9a497d1b0dd9da87908a11b59bf364ad40ddca
treef1a13f5fcd2db0e36dd3c487b47dd7198151ce56
parentbaad4c48a85a354d2bf1b17e5aff71203c08adea
Extend -Warray-bounds to detect out-of-bounds accesses to array parameters.

gcc/ChangeLog:

PR middle-end/82608
PR middle-end/94195
PR c/50584
PR middle-end/84051
* gimple-array-bounds.cc (get_base_decl): New function.
(get_ref_size): New function.
(trailing_array): New function.
(array_bounds_checker::check_array_ref): Call them.  Handle arrays
declared in function parameters.
(array_bounds_checker::check_mem_ref):  Same.  Handle references to
dynamically allocated arrays.

gcc/testsuite/ChangeLog:

PR middle-end/82608
PR middle-end/94195
PR c/50584
PR middle-end/84051
* c-c++-common/Warray-bounds.c: Adjust.
* gcc.dg/Wbuiltin-declaration-mismatch-9.c: Adjust.
* gcc.dg/Warray-bounds-63.c: New test.
* gcc.dg/Warray-bounds-64.c: New test.
* gcc.dg/Warray-bounds-65.c: New test.
* gcc.dg/Warray-bounds-66.c: New test.
* gcc.dg/Warray-bounds-67.c: New test.
gcc/gimple-array-bounds.cc
gcc/testsuite/c-c++-common/Warray-bounds.c
gcc/testsuite/gcc.dg/Warray-bounds-63.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/Warray-bounds-64.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/Warray-bounds-65.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/Warray-bounds-66.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/Warray-bounds-67.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/Wbuiltin-declaration-mismatch-9.c