]> git.ipfire.org Git - thirdparty/gcc.git/commit
Correct handling of variable offset minus constant in -Warray-bounds [PR100137]
authorMartin Sebor <msebor@redhat.com>
Wed, 7 Jul 2021 20:05:25 +0000 (14:05 -0600)
committerMartin Sebor <msebor@redhat.com>
Wed, 7 Jul 2021 20:06:59 +0000 (14:06 -0600)
commita110855667782dac7b674d3e328b253b3b3c919b
tree4d7212fdc8b29304d8defd03eefdb6ca842daa2f
parent6278065af07634278ba30029d92a82b089969baa
Correct handling of variable offset minus constant in -Warray-bounds [PR100137]

Resolves:
PR tree-optimization/100137 - -Warray-bounds false positive on varying offset plus negative
PR tree-optimization/99121 - ICE in -Warray-bounds on a multidimensional
PR tree-optimization/97027 - missing warning on buffer overflow storing a larger scalar into a smaller array

gcc/ChangeLog:

PR tree-optimization/100137
PR tree-optimization/99121
PR tree-optimization/97027
* builtins.c (access_ref::access_ref): Also set offmax.
(access_ref::offset_in_range): Define new function.
(access_ref::add_offset): Set offmax.
(access_ref::inform_access): Handle access_none.
(handle_mem_ref): Clear ostype.
(compute_objsize_r): Handle ASSERT_EXPR.
* builtins.h (struct access_ref): Add offmax member.
* gimple-array-bounds.cc (array_bounds_checker::check_mem_ref): Use
compute_objsize() and simplify.

gcc/testsuite/ChangeLog:

PR tree-optimization/100137
PR tree-optimization/99121
PR tree-optimization/97027
* c-c++-common/Warray-bounds-3.c: Remove xfail
* c-c++-common/Warray-bounds-4.c: Add an expected warning.
* c-c++-common/Warray-bounds-9.c: New test.
* c-c++-common/Warray-bounds-10.c: New test.
* g++.dg/asan/asan_test.C: Suppress expected warnings.
* g++.dg/pr95768.C: Same.
* g++.dg/warn/Warray-bounds-10.C: Adjust text of expected messages.
* g++.dg/warn/Warray-bounds-11.C: Same.
* g++.dg/warn/Warray-bounds-12.C: Same.
* g++.dg/warn/Warray-bounds-13.C: Same.
* g++.dg/warn/Warray-bounds-17.C: Same.
* g++.dg/warn/Warray-bounds-20.C: Same.
* gcc.dg/Warray-bounds-29.c: Same.
* gcc.dg/Warray-bounds-30.c: Add xfail.
* gcc.dg/Warray-bounds-31.c: Adjust text of expected messages.
* gcc.dg/Warray-bounds-32.c: Same.
* gcc.dg/Warray-bounds-52.c: Same.
* gcc.dg/Warray-bounds-53.c: Same.
* gcc.dg/Warray-bounds-58.c: Remove xfail.
* gcc.dg/Warray-bounds-63.c: Adjust text of expected messages.
* gcc.dg/Warray-bounds-66.c: Same.
* gcc.dg/Warray-bounds-69.c: Same.
* gcc.dg/Wstringop-overflow-34.c: Same.
* gcc.dg/Wstringop-overflow-47.c: Same.
* gcc.dg/Wstringop-overflow-61.c: Same.
* gcc.dg/Warray-bounds-77.c: New test.
* gcc.dg/Warray-bounds-78.c: New test.
* gcc.dg/Warray-bounds-79.c: New test.
31 files changed:
gcc/builtins.c
gcc/builtins.h
gcc/gimple-array-bounds.cc
gcc/testsuite/c-c++-common/Warray-bounds-10.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/Warray-bounds-3.c
gcc/testsuite/c-c++-common/Warray-bounds-4.c
gcc/testsuite/c-c++-common/Warray-bounds-9.c [new file with mode: 0644]
gcc/testsuite/g++.dg/asan/asan_test.C
gcc/testsuite/g++.dg/pr95768.C
gcc/testsuite/g++.dg/warn/Warray-bounds-10.C
gcc/testsuite/g++.dg/warn/Warray-bounds-11.C
gcc/testsuite/g++.dg/warn/Warray-bounds-12.C
gcc/testsuite/g++.dg/warn/Warray-bounds-13.C
gcc/testsuite/g++.dg/warn/Warray-bounds-17.C
gcc/testsuite/g++.dg/warn/Warray-bounds-20.C
gcc/testsuite/gcc.dg/Warray-bounds-29.c
gcc/testsuite/gcc.dg/Warray-bounds-30.c
gcc/testsuite/gcc.dg/Warray-bounds-31.c
gcc/testsuite/gcc.dg/Warray-bounds-32.c
gcc/testsuite/gcc.dg/Warray-bounds-52.c
gcc/testsuite/gcc.dg/Warray-bounds-53.c
gcc/testsuite/gcc.dg/Warray-bounds-58.c
gcc/testsuite/gcc.dg/Warray-bounds-63.c
gcc/testsuite/gcc.dg/Warray-bounds-66.c
gcc/testsuite/gcc.dg/Warray-bounds-69.c
gcc/testsuite/gcc.dg/Warray-bounds-77.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/Warray-bounds-78.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/Warray-bounds-79.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/Wstringop-overflow-34.c
gcc/testsuite/gcc.dg/Wstringop-overflow-47.c
gcc/testsuite/gcc.dg/Wstringop-overflow-61.c