From: Jeff Law <law@redhat.com>
To: Martin Sebor <msebor@gmail.com>,
Gcc Patch List <gcc-patches@gcc.gnu.org>,
Jakub Jelinek <jakub@redhat.com>
Subject: Re: [PATCH] correct -Wrestrict handling of arrays of arrays (PR 84095)
Date: Fri, 16 Feb 2018 23:39:00 -0000 [thread overview]
Message-ID: <549771ff-19bd-0a29-81bb-7c0e2c15ed23@redhat.com> (raw)
In-Reply-To: <b3bf7346-2f95-2057-7da4-cf4a000627d5@gmail.com>
On 02/15/2018 10:47 AM, Martin Sebor wrote:
> On 02/13/2018 11:14 PM, Jeff Law wrote:
>> On 02/01/2018 04:45 PM, Martin Sebor wrote:
>>> The previous patch didn't resolve all the false positives
>>> in the Linux kernel. The attached is an update that fixes
>>> the remaining one having to do with multidimensional array
>>> members:
>>>
>>> Â struct S { char a[2][4]; };
>>>
>>> Â void f (struct S *p, int i)
>>> Â {
>>> Â Â Â strcpy (p->a[0], "012");
>>> Â Â Â strcpy (p->a[i] + 1, p->a[0]);Â Â // false positive here
>>> Â }
>>>
>>> In the process of fixing this I also made a couple of minor
>>> restructuring changes to the builtin_memref constructor to
>>> in order to make the code easier to follow: I broke it out
>>> into a couple of helper functions and called those.
>>>
>>> As with the first revision of the patch, this one is also
>>> meant to be applied on top of
>>>
>>> Â https://gcc.gnu.org/ml/gcc-patches/2018-01/msg01488.html
>>>
>>> Sorry about the late churn. Even though I tested the original
>>> implementation with the Linux kernel the bugs were only exposed
>>> non-default configurations that I didn't build.
>>>
>>> Jakub, you had concerns about the code in the constructor
>>> and about interpreting the offsets in the diagnostics.
>>> I tried to address those in the patch. Please review
>>> the changes and let me know if you have any further comments.
>>>
>>> Thanks
>>> Martin
>>>
>>> On 01/30/2018 04:19 PM, Martin Sebor wrote:
>>>> Testing GCC 8 with recent Linux kernel sources has uncovered
>>>> a bug in the handling of arrays of arrays by the -Wrestrict
>>>> checker where it fails to take references to different array
>>>> elements into consideration, issuing false positives.
>>>>
>>>> The attached patch corrects this mistake.
>>>>
>>>> In addition, to make warnings involving excessive offset bounds
>>>> more meaningful (less confusing), I've made a cosmetic change
>>>> to constrain them to the bounds of the accessed object. I've
>>>> done this in response to multiple comments indicating that
>>>> the warnings are hard to interpret. This change is meant to
>>>> be applied on top of the patch for bug 83698 (submitted mainly
>>>> to improve the readability of the offsets):
>>>>
>>>> Â https://gcc.gnu.org/ml/gcc-patches/2018-01/msg01488.html
>>>>
>>>> Martin
>>>
>>>
>>> gcc-84095.diff
>>>
>>>
>>> PR middle-end/84095 - false-positive -Wrestrict warnings for memcpy
>>> within array
>>>
>>> gcc/ChangeLog:
>>>
>>> Â Â Â Â PR middle-end/84095
>>> Â Â Â Â * gimple-ssa-warn-restrict.c
>>> (builtin_memref::extend_offset_range): New.
>>>     (builtin_memref::set_base_and_offset): Same. Handle inner
>>> references.
>>> Â Â Â Â (builtin_memref::builtin_memref): Factor out parts into
>>> Â Â Â Â set_base_and_offset and call it.
>>>
>>> gcc/testsuite/ChangeLog:
>>>
>>> Â Â Â Â PR middle-end/84095
>>> Â Â Â Â * c-c++-common/Warray-bounds-3.c: Adjust text of expected warnings.
>>> Â Â Â Â * c-c++-common/Wrestrict.c: Same.
>>> Â Â Â Â * gcc.dg/Wrestrict-6.c: Same.
>>> Â Â Â Â * gcc.dg/Warray-bounds-27.c: New test.
>>> Â Â Â Â * gcc.dg/Wrestrict-8.c: New test.
>>> Â Â Â Â * gcc.dg/Wrestrict-9.c: New test.
>>> Â Â Â Â * gcc.dg/pr84095.c: New test.
>>>
>>> diff --git a/gcc/gimple-ssa-warn-restrict.c
>>> b/gcc/gimple-ssa-warn-restrict.c
>>> index 528eb5b..367e05f 100644
>>> --- a/gcc/gimple-ssa-warn-restrict.c
>>> +++ b/gcc/gimple-ssa-warn-restrict.c
>>
>>> +Â Â Â Â Â else if (gimple_nop_p (stmt))
>>> +Â Â Â expr = SSA_NAME_VAR (expr);
>>> +Â Â Â Â Â else
>>> +Â Â Â {
>>> +Â Â Â Â Â base = expr;
>>> +Â Â Â Â Â return;
>>> Â Â Â Â }
>> This looks odd. Can you explain what you're trying to do here?
>>
>> I'm not offhand why you'd ever want to extract SSA_NAME_VAR. In general
>> it's primary use is for dumps and debugging info. I won't quite go so
>> far as to say using it for anything else is wrong, but it's certainly
>> something you ought to explain.
>
> It appears to be dead code. Nothing in the GCC test suite hits
> this code. It's most likely a vestige of an approach I tried
> that didn't work and that I ended up doing differently and forgot
> to remove. I'll remove it before committing.
>
>> The rest looks fairly reasonable. It's a bit hard to follow, but I
>> don't think we should do another round of refactoring at this stage.
>
> Is the patch good to commit then with the unused code above
> removed?
Yes. Again, sorry for the delays.
jeff
next prev parent reply other threads:[~2018-02-16 23:39 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-30 23:37 Martin Sebor
2018-02-01 23:45 ` Martin Sebor
2018-02-09 2:46 ` Martin Sebor
2018-02-14 6:14 ` Jeff Law
2018-02-15 17:48 ` Martin Sebor
2018-02-16 23:39 ` Jeff Law [this message]
2018-02-23 3:17 ` Siddhesh Poyarekar
2018-02-23 15:52 ` Martin Sebor
2018-02-23 16:19 ` Siddhesh Poyarekar
2018-02-23 16:49 ` Jakub Jelinek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=549771ff-19bd-0a29-81bb-7c0e2c15ed23@redhat.com \
--to=law@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.com \
--cc=msebor@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).