This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PING 2][PATCH] enhance -Wrestrict to handle string built-ins (PR 78918)
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: Martin Sebor <msebor at gmail dot com>
- Cc: Jeff Law <law at redhat dot com>, Richard Biener <richard dot guenther at gmail dot com>, Gcc Patch List <gcc-patches at gcc dot gnu dot org>
- Date: Sun, 17 Dec 2017 05:32:36 -0800
- Subject: Re: [PING 2][PATCH] enhance -Wrestrict to handle string built-ins (PR 78918)
- Authentication-results: sourceware.org; auth=none
- References: <8a0de82f-d68e-9c37-0406-f216e3f92884@gmail.com> <703424cb-db8c-8aae-9bd2-cece5883a5de@gmail.com> <0266f22c-6ac1-f676-123f-c028905519e5@redhat.com> <d76c8b0b-8fbc-8b4e-fe6d-acdaf9efd81b@gmail.com> <CAFiYyc3xAW=4EeAwqrNRx01_8PTq=a3wdsteqMyx_P2qz+SBRw@mail.gmail.com> <1574f108-5456-711e-6533-73c4711c26f2@gmail.com> <CAFiYyc1Hxfn-8PoTkrsNPSerk-c34deM-zO94if4xVcCxe5kDQ@mail.gmail.com> <40984eff-b156-3315-7bb5-558e9e83bf6c@gmail.com> <ea60148d-4e53-2434-7c9f-c6dd26d3363f@gmail.com> <86344144-d7de-9a92-2e65-9d43536c312b@gmail.com> <11adcf4e-2ed0-c441-2ea7-538fb453b956@gmail.com> <5ffed8d2-4957-898f-590f-b09a3d9ca719@redhat.com> <7b05b1da-da02-1385-5ef6-ba0eee6fc7b1@gmail.com> <d08de941-7697-d1ea-4586-dacd01e53c51@gmail.com> <7a5fae23-f63e-98b5-7368-a7cf992ebe20@redhat.com> <303e3cba-f825-dc90-cf24-01e9e3240192@gmail.com> <b0f49335-e97a-aa27-9169-aa5dfe04a166@gmail.com> <f5945471-3be8-3657-fabc-bd1fedd4c057@redhat.com> <6fedb302-439c-78a5-4772-454b31a0a4f8@gmail.com>
On Sat, Dec 16, 2017 at 4:01 PM, Martin Sebor <msebor@gmail.com> wrote:
> On 12/11/2017 03:27 PM, Jeff Law wrote:
>>
>> On 12/08/2017 12:19 PM, Martin Sebor wrote:
>>>
>>> Attached is revision 8 of the patch with the changes suggested
>>> and/or requested below.
>>
>>
>> [ Big snip. ]
>>
>>>
>>>
>>> gcc-78918.diff
>>>
>>>
>>> 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/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/memcpy-6.c: New test.
>>> * gcc.dg/pr69172.c: Adjust.
>>> * gcc.dg/pr79223.c: Same.
>>> * gcc.dg/Wrestrict-2.c: New test.
>>> * gcc.dg/Wrestrict.c: New test.
>>> * gcc.dg/Wsizeof-pointer-memaccess1.c
>>> * gcc.target/i386/chkp-stropt-17.c: New test.
>>> * gcc.dg/torture/Wsizeof-pointer-memaccess1.c: Adjust.
>>
>> OK. Thanks for your patience. I know this was a ton of work and even
>> more waiting.
>
>
> Thanks. In more testing I uncovered a few minor glitches. I've
> fixed those and committed r255755. Attached is the committed patch
> for reference.
>
> Martin
This caused:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83446
--
H.J.