public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Marc Glisse <marc.glisse@inria.fr>
To: David Malcolm <dmalcolm@redhat.com>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: Warn when returning the address of a temporary (middle-end) v2
Date: Tue, 29 Jul 2014 19:28:00 -0000	[thread overview]
Message-ID: <alpine.DEB.2.11.1407292113570.23393@stedding.saclay.inria.fr> (raw)
In-Reply-To: <1406660283.2134.122.camel@surprise>

On Tue, 29 Jul 2014, David Malcolm wrote:

> On Tue, 2014-07-29 at 19:36 +0200, Marc Glisse wrote:
>> On Sun, 27 Jul 2014, Richard Sandiford wrote:
>>
>>> Marc Glisse <marc.glisse@inria.fr> writes:
>>>> Hello,
>>>>
>>>> I followed the advice in this discussion:
>>>> https://gcc.gnu.org/ml/gcc-patches/2014-04/msg00269.html
>>>>
>>>> and here is a new patch. I made an effort to isolate a path in at least
>>>> one subcase so it doesn't look too strange that the warning is in this
>>>> file. Computing the dominance info just to tweak the warning message may
>>>> be a bit excessive.
>>>
>>> How about only calculating it once you've decided to issue a message?
>>>
>>>> +		      if (always_executed)
>>>> +			msg = "function returns address of local variable";
>>>> +		      else
>>>> +			msg = "function may return address of local variable";
>>>
>>> I think you need _(...) here, unless some magic makes that unnecessary now.
>>
>> Current version, which passed bootstrap+testsuite on x86_64-linux-gnu.
>> (the original discussion is at
>> https://gcc.gnu.org/ml/gcc-patches/2014-06/msg01692.html )
>
> This is possibly a dumb question, but what happens for a static local,
> rather than an auto local? e.g.
>
> int *f (void)
> {
>    static int i;
>    return &i;
> }

is_global_var returns true and we don't warn.

> (e.g. should the test case cover this?)

I can add it if you want. I already test a global variable (function h) 
and I expect this is likely already covered elsewhere, but it would make 
the testcase more complete, so I'll do that.


I just noticed an issue with my patch: since I am using a compound 
expression in the front-ends to preserve side-effects, I am now sometimes 
getting this extra warning:

warning: left-hand operand of comma expression has no effect [-Wunused-value]

(I am surprised the testsuite didn't tell me about it)

I will probably have to use the compound expr only if there are side 
effects.

-- 
Marc Glisse

  parent reply	other threads:[~2014-07-29 19:22 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-22 18:20 Marc Glisse
2014-06-29  9:22 ` Marc Glisse
2014-06-30 21:04   ` Jeff Law
2014-06-30 21:37     ` Marc Glisse
2014-07-02 12:19       ` Alan Modra
2014-07-02 12:41         ` Marc Glisse
2014-07-02 22:39         ` Jeff Law
2014-07-02 22:46       ` Jeff Law
2014-07-18  5:06 ` Jeff Law
2014-07-22  9:04   ` Marc Glisse
2014-07-31  4:54     ` Jeff Law
2014-07-27 18:20 ` Richard Sandiford
2014-07-27 19:09   ` Marc Glisse
2014-07-27 20:45     ` Andreas Schwab
2014-07-27 21:05       ` Marc Glisse
2014-07-29 19:00   ` Marc Glisse
2014-07-29 19:13     ` David Malcolm
2014-07-29 19:22       ` Marek Polacek
2014-07-29 19:47         ` David Malcolm
2014-07-29 19:28       ` Marc Glisse [this message]
2014-07-30 12:00       ` Marc Glisse
2014-07-31  4:58         ` Jeff Law

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=alpine.DEB.2.11.1407292113570.23393@stedding.saclay.inria.fr \
    --to=marc.glisse@inria.fr \
    --cc=dmalcolm@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    /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).