]> git.ipfire.org Git - thirdparty/gcc.git/commit
PR tree-optimization/78918 - missing -Wrestrict on memcpy copying over self
authormsebor <msebor@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 16 Dec 2017 23:58:34 +0000 (23:58 +0000)
committermsebor <msebor@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 16 Dec 2017 23:58:34 +0000 (23:58 +0000)
commite6a18b5a63bae3f22acbe9167f88ae98d6095b79
tree8ab48ffcd2c1abce152c9686d64db508a4f40a96
parent43fc29834bd9009a6ff4d3c5834fe8f8baead077
PR tree-optimization/78918 - missing -Wrestrict on memcpy copying over self

gcc/c-family/ChangeLog:

PR tree-optimization/78918
* c-common.c (check_function_restrict): Avoid checking built-ins.
* c.opt (-Wrestrict): Include in -Wall.

gcc/ChangeLog:

PR tree-optimization/78918
* Makefile.in (OBJS): Add gimple-ssa-warn-restrict.o.
* builtins.c (check_sizes): Rename...
(check_access): ...to this.  Rename function arguments for clarity.
(check_memop_sizes): Adjust names.
(expand_builtin_memchr, expand_builtin_memcpy): Same.
(expand_builtin_memmove, expand_builtin_mempcpy): Same.
(expand_builtin_strcat, expand_builtin_stpncpy): Same.
(check_strncat_sizes, expand_builtin_strncat): Same.
(expand_builtin_strncpy, expand_builtin_memset): Same.
(expand_builtin_bzero, expand_builtin_memcmp): Same.
(expand_builtin_memory_chk, maybe_emit_chk_warning): Same.
(maybe_emit_sprintf_chk_warning): Same.
(expand_builtin_strcpy): Adjust.
(expand_builtin_stpcpy): Same.
(expand_builtin_with_bounds): Detect out-of-bounds accesses
in pointer-checking forms of memcpy, memmove, and mempcpy.
(gcall_to_tree_minimal, max_object_size): Define new functions.
* builtins.h (max_object_size): Declare.
* calls.c (alloc_max_size): Call max_object_size instead of
hardcoding ssizetype limit.
(get_size_range): Handle new argument.
* calls.h (get_size_range): Add a new argument.
* cfgexpand.c (expand_call_stmt): Propagate no-warning bit.
* doc/invoke.texi (-Wrestrict): Adjust, add example.
* gimple-fold.c (gimple_fold_builtin_memory_op): Detect overlapping
operations.
(gimple_fold_builtin_memory_chk): Same.
(gimple_fold_builtin_stxcpy_chk): New function.
* gimple-ssa-warn-restrict.c: New source.
* gimple-ssa-warn-restrict.h: New header.
* gimple.c (gimple_build_call_from_tree): Propagate location.
* passes.def (pass_warn_restrict): Add new pass.
* tree-pass.h (make_pass_warn_restrict): Declare.
* tree-ssa-strlen.c (handle_builtin_strcpy): Detect overlapping
operations.
(handle_builtin_strcat): Same.
(strlen_optimize_stmt): Rename...
(strlen_check_and_optimize_stmt): ...to this.  Handle strncat,
stpncpy, strncpy, and their checking forms.

gcc/testsuite/ChangeLog:

PR tree-optimization/78918
* c-c++-common/Warray-bounds.c: New test.
* c-c++-common/Warray-bounds-2.c: New test.
* c-c++-common/Warray-bounds-3.c: New test.
* c-c++-common/Warray-bounds-4.c: New test.
* c-c++-common/Warray-bounds-5.c: New test.
* c-c++-common/Wrestrict-2.c: New test.
* c-c++-common/Wrestrict.c: New test.
* c-c++-common/Wrestrict.s: New test.
* c-c++-common/Wsizeof-pointer-memaccess1.c: Adjust
* c-c++-common/Wsizeof-pointer-memaccess2.c: Same.
* g++.dg/torture/Wsizeof-pointer-memaccess1.C: Same.
* g++.dg/torture/Wsizeof-pointer-memaccess2.C: Same.
* gcc.dg/range.h: New header.
* gcc.dg/memcpy-6.c: New test.
* gcc.dg/pr69172.c: Adjust.
* gcc.dg/pr79223.c: Same.
* gcc.dg/pr81345.c: Adjust.
* gcc.dg/Wobjsize-1.c: Same.
* gcc.dg/Wrestrict-2.c: New test.
* gcc.dg/Wrestrict.c: New test.
* gcc.dg/Wsizeof-pointer-memaccess1.c: Adjust.
* gcc.dg/builtin-stpncpy.c: Same.
* gcc.dg/builtin-stringop-chk-1.c: Same.
* gcc.target/i386/chkp-stropt-17.c: New test.
* gcc.dg/torture/Wsizeof-pointer-memaccess1.c: Adjust.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@255755 138bc75d-0d04-0410-961f-82ee72b054a4
42 files changed:
gcc/ChangeLog
gcc/Makefile.in
gcc/builtins.c
gcc/builtins.h
gcc/c-family/ChangeLog
gcc/c-family/c-common.c
gcc/c-family/c.opt
gcc/calls.c
gcc/calls.h
gcc/cfgexpand.c
gcc/doc/invoke.texi
gcc/gimple-fold.c
gcc/gimple-ssa-warn-restrict.c [new file with mode: 0644]
gcc/gimple-ssa-warn-restrict.h [new file with mode: 0644]
gcc/passes.def
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/Warray-bounds-2.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/Warray-bounds-3.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/Warray-bounds-4.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/Warray-bounds-5.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/Warray-bounds.c
gcc/testsuite/c-c++-common/Wrestrict-2.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/Wrestrict.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/Wsizeof-pointer-memaccess1.c
gcc/testsuite/c-c++-common/Wsizeof-pointer-memaccess2.c
gcc/testsuite/g++.dg/torture/Wsizeof-pointer-memaccess1.C
gcc/testsuite/g++.dg/torture/Wsizeof-pointer-memaccess2.C
gcc/testsuite/gcc.dg/Wobjsize-1.c
gcc/testsuite/gcc.dg/Wrestrict-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/Wrestrict.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/Wsizeof-pointer-memaccess1.c
gcc/testsuite/gcc.dg/builtin-stpncpy.c
gcc/testsuite/gcc.dg/builtin-stringop-chk-1.c
gcc/testsuite/gcc.dg/memcpy-6.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr69172.c
gcc/testsuite/gcc.dg/pr79223.c
gcc/testsuite/gcc.dg/pr81345.c
gcc/testsuite/gcc.dg/range.h [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/Wsizeof-pointer-memaccess1.c
gcc/testsuite/gcc.target/i386/chkp-stropt-17.c [new file with mode: 0644]
gcc/tree-pass.h
gcc/tree-ssa-strlen.c