Extend -Wstringop-overflow to detect out-of-bounds accesses to array parameters.
authorMartin Sebor <msebor@redhat.com>
Sat, 19 Sep 2020 23:37:05 +0000 (17:37 -0600)
committerMartin Sebor <msebor@redhat.com>
Sat, 19 Sep 2020 23:37:05 +0000 (17:37 -0600)
commitbaad4c48a85a354d2bf1b17e5aff71203c08adea
treeb29b89090fb1eb5436ff4183d0b11ba2dc765a4a
parent72be80e47d059f33ff11f5015b9494c42b4e0a12
Extend -Wstringop-overflow to detect out-of-bounds accesses to array parameters.

gcc/ChangeLog:

PR c/50584
* builtins.c (warn_for_access): Add argument.  Distinguish between
reads and writes.
(check_access): Add argument.  Distinguish between reads and writes.
(gimple_call_alloc_size): Set range even on failure.
(gimple_parm_array_size): New function.
(compute_objsize): Call it.
(check_memop_access): Pass check_access an additional argument.
(expand_builtin_memchr, expand_builtin_strcat): Same.
(expand_builtin_strcpy, expand_builtin_stpcpy_1): Same.
(expand_builtin_stpncpy, check_strncat_sizes): Same.
(expand_builtin_strncat, expand_builtin_strncpy): Same.
(expand_builtin_memcmp): Same.
* builtins.h (compute_objsize): Declare a new overload.
(gimple_parm_array_size): Declare.
(check_access): Add argument.
* calls.c (append_attrname): Simplify.
(maybe_warn_rdwr_sizes): Handle internal attribute access.
* tree-ssa-uninit.c (maybe_warn_pass_by_reference): Avoid adding
quotes.

gcc/testsuite/ChangeLog:

PR c/50584
* c-c++-common/Wsizeof-pointer-memaccess1.c: Disable new expected
warnings.
* g++.dg/ext/attr-access.C: Update text of expected warnings.
* gcc.dg/Wstringop-overflow-23.c: Same.
* gcc.dg/Wstringop-overflow-24.c: Same.
* gcc.dg/attr-access-none.c: Same.
* gcc.dg/dfp/composite-type.c: Prune expected warnings.
* gcc.dg/torture/pr57147-1.c: Add a member to an otherwise empty
struct to avoid a warning.
* gcc.dg/torture/pr57147-3.c: Same.
* gcc.dg/Warray-bounds-30.c: Adjust.
* gcc.dg/attr-access-none.c: Same.
* gcc.dg/Wstringop-overflow-40.c: New test.
* gcc.dg/attr-access-2.c: New test.
15 files changed:
gcc/builtins.c
gcc/builtins.h
gcc/calls.c
gcc/testsuite/c-c++-common/Wsizeof-pointer-memaccess1.c
gcc/testsuite/g++.dg/ext/attr-access.C
gcc/testsuite/gcc.dg/Warray-bounds-30.c
gcc/testsuite/gcc.dg/Wstringop-overflow-23.c
gcc/testsuite/gcc.dg/Wstringop-overflow-24.c
gcc/testsuite/gcc.dg/Wstringop-overflow-40.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/attr-access-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/attr-access-none.c
gcc/testsuite/gcc.dg/dfp/composite-type.c
gcc/testsuite/gcc.dg/torture/pr57147-1.c
gcc/testsuite/gcc.dg/torture/pr57147-3.c
gcc/tree-ssa-uninit.c