PR c/53562 - Add -Werror= support for -D_FORTIFY_SOURCE / __builtin___memcpy_chk
authorMartin Sebor <msebor@redhat.com>
Thu, 8 Dec 2016 00:01:33 +0000 (00:01 +0000)
committerMartin Sebor <msebor@gcc.gnu.org>
Thu, 8 Dec 2016 00:01:33 +0000 (17:01 -0700)
commitee92e7bafb52d267f52e4c48edada5f279bcf591
tree1468c5482ab4b2c6c5a92894f2e96f47a742b995
parentfc3f36f9a1642338da8c0428ea5dc140402556c9
PR c/53562 - Add -Werror= support for -D_FORTIFY_SOURCE / __builtin___memcpy_chk

PR c/53562 - Add -Werror= support for -D_FORTIFY_SOURCE / __builtin___memcpy_chk
PR middle-end/77784 - duplicate warning for snprintf when n > object size
PR middle-end/78149 - missing warning on strncpy buffer overflow due to an excessive bound
PR middle-end/78138 - missing warnings on buffer overflow with non-constant source length

gcc/c-family/ChangeLog:

PR c/53562
PR middle-end/77784
PR middle-end/78149
PR middle-end/78138
* c.opt (-Wstringop-overflow): New option.

gcc/ChangeLog:

PR middle-end/77784
PR middle-end/78149
PR middle-end/78138

* builtins.c (expand_builtin_strcat, expand_builtin_strncat): New
functions.
(compute_dest_size, get_size_range, check_sizes, check_strncat_sizes)
(check_memop_sizes): Same.
(expand_builtin_memcpy): Call check memop_sizes.
(expand_builtin_mempcpy): Same.
(expand_builtin_memset): Same,
(expand_builtin_bzero): Same.
(expand_builtin_memory_chk): Call check_sizes.
(expand_builtin_strcpy): Same.
(expand_builtin_strncpy): Same.
(maybe_emit_sprintf_chk_warning): Same.
(expand_builtin): Handle strcat and strncat.
(fini_object_sizes): Reset pointers.
(compute_object_size): New function.
* gimple-ssa-sprintf.c (pass_sprintf_length::handle_gimple_call):
Avoid issuing warnings also issued during built-in expansion.
* doc/invoke.texi (Warning Options): Document -Wstringop-overflow.

gcc/testsuite/ChangeLog:

PR middle-end/77784
PR middle-end/78149
PR middle-end/78138

* c-c++-common/Wsizeof-pointer-memaccess2.c: Adjust expected diagnostic.
* g++.dg/ext/builtin-object-size3.C (bar): Same.
* g++.dg/ext/strncpy-chk1.C: Same.
* g++.dg/opt/memcpy1.C: Same.
* g++.dg/torture/Wsizeof-pointer-memaccess1.C: Same.
* gcc.c-torture/compile/pr55569.c: Disable -Wstringop-overflow.
* gcc.dg/Wobjsize-1.c: Adjust expected diagnostic.
* gcc.dg/attr-alloc_size.c: Same.
* gcc.dg/builtin-stringop-chk-1.c: Adjust expected diagnostic.
* gcc.dg/builtin-stringop-chk-2.c: Same.
* gcc.dg/builtin-stringop-chk-4.c: New test.
* gcc.dg/builtin-strncat-chk-1.c: Adjust expected diagnostic.
* gcc.dg/memcpy-2.c: Same.
* gcc.dg/pr40340-1.c: Same.
* gcc.dg/pr40340-2.c (main): Same.
* gcc.dg/pr40340-5.c (main): Same.
* gcc.dg/torture/Wsizeof-pointer-memaccess1.c: Same.
* gcc.dg/torture/pr71132.c: Disable -Wstringop-overflow.
* gcc.dg/tree-ssa/builtin-sprintf-warn-1.c: Adjust text of expected
warning.
* gfortran.dg/char_length_3.f90: Prune expected warnings.
* gfortran.dg/pr38868.f: Add expected warnings.

From-SVN: r243419
33 files changed:
gcc/ChangeLog
gcc/builtins.c
gcc/c-family/ChangeLog
gcc/c-family/c.opt
gcc/doc/invoke.texi
gcc/gimple-ssa-sprintf.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/Wsizeof-pointer-memaccess2.c
gcc/testsuite/g++.dg/ext/builtin-object-size3.C
gcc/testsuite/g++.dg/ext/strncpy-chk1.C
gcc/testsuite/g++.dg/opt/memcpy1.C
gcc/testsuite/g++.dg/torture/Wsizeof-pointer-memaccess1.C
gcc/testsuite/g++.dg/torture/Wsizeof-pointer-memaccess2.C
gcc/testsuite/gcc.c-torture/compile/pr55569.c
gcc/testsuite/gcc.dg/Wobjsize-1.c
gcc/testsuite/gcc.dg/attr-alloc_size.c
gcc/testsuite/gcc.dg/builtin-stringop-chk-1.c
gcc/testsuite/gcc.dg/builtin-stringop-chk-2.c
gcc/testsuite/gcc.dg/builtin-stringop-chk-4.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/builtin-stringop-chk-5.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/builtin-stringop-chk-6.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/builtin-strncat-chk-1.c
gcc/testsuite/gcc.dg/fstack-protector-strong.c
gcc/testsuite/gcc.dg/memcpy-2.c
gcc/testsuite/gcc.dg/pr40340-1.c
gcc/testsuite/gcc.dg/pr40340-2.c
gcc/testsuite/gcc.dg/pr40340-5.c
gcc/testsuite/gcc.dg/torture/Wsizeof-pointer-memaccess1.c
gcc/testsuite/gcc.dg/torture/pr71132.c
gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-1.c
gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-3.c
gcc/testsuite/gfortran.dg/char_length_3.f90
gcc/testsuite/gfortran.dg/pr38868.f