This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: PR80806
- From: Jeff Law <law at redhat dot com>
- To: Martin Sebor <msebor at gmail dot com>, Prathamesh Kulkarni <prathamesh dot kulkarni at linaro dot org>, gcc Patches <gcc-patches at gcc dot gnu dot org>, Richard Biener <rguenther at suse dot de>
- Date: Thu, 29 Jun 2017 12:05:29 -0600
- Subject: Re: PR80806
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=law at redhat dot com
- Dkim-filter: OpenDKIM Filter v2.11.0 mx1.redhat.com E7A6FC0CC64B
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E7A6FC0CC64B
- References: <CAAgBjMkiA6FwzYYVDBA7vymvRDhd_a08vamPf_42JQ5DV5SQ8g@mail.gmail.com> <2dae09d9-8b97-d178-6af0-a5c56a66b9a8@gmail.com> <ef1f5b43-57b2-b2d2-7bbd-80e7c51ddd80@redhat.com>
On 06/29/2017 11:57 AM, Jeff Law wrote:
> On 05/23/2017 09:58 AM, Martin Sebor wrote:
>> On 05/18/2017 12:55 PM, Prathamesh Kulkarni wrote:
>>> Hi,
>>> The attached patch tries to fix PR80806 by warning when a variable is
>>> set using memset (and friends) but not used. I chose to warn in dse
>>> pass since dse would detect if the variable passed as 1st argument is
>>> a dead store. Does this approach look OK ?
>>
>> Detecting -Wunused-but-set-variable in the optimizer means that
>> the warning will not be issued without optimization. It also
>> means that the warning will trigger in cases where the variable
>> is used conditionally and the condition is subject to constant
>> propagation. For instance:
> Yea. There's definitely tradeoffs for implementing warnings early vs
> late. There's little doubt we could construct testcases where an early
> warning would miss cases that could be caught by a late warning.
>
>
>>
>> void sink (void*);
>>
>> void test (int i)
>> {
>> char buf[10]; // -Wunused-but-set-variable
>> memset (buf, 0, sizeof(buf));
>>
>> if (i)
>> sink (buf);
>> }
>>
>> void f (void)
>> {
>> test (0);
>> }
>>
>> I suspect this would be considered a false positive by most users.
>> In my view, it would be more in line with the design of the warning
>> to enhance the front end to detect this case, and it would avoid
>> these issues.
> Given no knowledge of sink() here, don't we have to assume that buf is
> used? So, yea, I'd probably consider that a false positive.
Oh, wait, I missed the constant propagation. That makes this one less
clear cut in my mind -- it means its context sensitive. I could easily
argue either way on this one.
Jeff