From: Martin Sebor <msebor@gmail.com>
To: Jeff Law <law@redhat.com>,
Prathamesh Kulkarni <prathamesh.kulkarni@linaro.org>,
gcc Patches <gcc-patches@gcc.gnu.org>,
Richard Biener <rguenther@suse.de>
Subject: Re: PR80806
Date: Thu, 29 Jun 2017 21:45:00 -0000 [thread overview]
Message-ID: <83c080d9-bac4-7730-5d6b-5d57ac66839b@gmail.com> (raw)
In-Reply-To: <cfcec194-d3bb-abe5-19a3-6d4287a71923@redhat.com>
On 06/29/2017 12:05 PM, Jeff Law wrote:
> 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.
Suppose buf were the small buffer in std::string and sink() some
conditional use of the class, like in this more complicated code:
void foo (std::string&);
void bar (char*);
void test (int i)
{
std::string s; // calls memset (s.buf, 0, sizeof s.buf)
char array[100] = "";
if (i > 100)
foo (s); // needs a large buffer
else
bar (array); // works with a small buffer
}
Variations on this idiom aren't uncommon.
Martin
next prev parent reply other threads:[~2017-06-29 21:45 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-18 18:56 PR80806 Prathamesh Kulkarni
2017-05-22 4:50 ` PR80806 Jeff Law
2017-05-23 13:50 ` PR80806 Prathamesh Kulkarni
2017-05-23 15:59 ` PR80806 Martin Sebor
2017-05-24 5:42 ` PR80806 Martin Sebor
2017-06-29 17:57 ` PR80806 Jeff Law
2017-06-29 18:05 ` PR80806 Jeff Law
2017-06-29 21:45 ` Martin Sebor [this message]
2017-06-29 18:20 ` PR80806 Jeff Law
2017-06-30 8:25 ` PR80806 Richard Biener
2017-06-30 8:33 ` PR80806 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=83c080d9-bac4-7730-5d6b-5d57ac66839b@gmail.com \
--to=msebor@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=law@redhat.com \
--cc=prathamesh.kulkarni@linaro.org \
--cc=rguenther@suse.de \
/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).