public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jeff Law <law@redhat.com>
To: Marc Glisse <marc.glisse@inria.fr>, gcc-patches@gcc.gnu.org
Subject: Re: Warn when returning the address of a temporary (middle-end) v2
Date: Fri, 18 Jul 2014 05:06:00 -0000	[thread overview]
Message-ID: <53C746CC.1000007@redhat.com> (raw)
In-Reply-To: <alpine.DEB.2.02.1406221930380.20514@stedding.saclay.inria.fr>

On 06/22/14 12:20, Marc Glisse wrote:
> 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. I kept the same option as the front-ends, I don't
> know if we want a different one, or maybe a Wmaybe-... version. There
> will be cases where we get a duplicate warning from -Wtarget-lifetime in
> fortran, but none in the testsuite, and I would rather have 2 warnings
> than miss such broken code. The uninit-G testcase is about
> initialization, not returning, so I am changing that, even if it is
> unnecessary with the current version of the patch (only activated at -O2).
>
> Bootstrap+testsuite (--enable-languages=all,obj-c++,ada,go) on
> x86_64-unknown-linux-gnu.
>
> (by the way, contrib/compare_tests is confused when I use all languages,
> it prints "comm: file 1 is not in sorted order" and tons of spurious
> differences)
>
> 2014-06-23  Marc Glisse  <marc.glisse@inria.fr>
>
>      PR c++/60517
> gcc/c/
>      * c-typeck.c (c_finish_return): Return 0 instead of the address of
>      a local variable.
> gcc/cp/
>      * typeck.c (maybe_warn_about_returning_address_of_local): Return
>      whether it is returning the address of a local variable.
>      (check_return_expr): Return 0 instead of the address of a local
>      variable.
> gcc/c-family/
>      * c.opt (-Wreturn-local-addr): Move to common.opt.
> gcc/
>      * common.opt (-Wreturn-local-addr): Moved from c.opt.
>      * gimple-ssa-isolate-paths.c: Include diagnostic-core.h.
>      (isolate_path): New argument to avoid inserting a trap.
>      (find_implicit_erroneous_behaviour): Handle returning the address
>      of a local variable.
>      (find_explicit_erroneous_behaviour): Likewise.
>      (gimple_ssa_isolate_erroneous_paths): Calculate dominance info.
> gcc/testsuite/
>      * c-c++-common/addrtmp.c: New file.
>      * c-c++-common/uninit-G.c: Adapt.
I note you don't catch return &localvar in the isolation code -- it 
looks like you just catch those which potentially flow from PHIs.

I realize you're primarily catching that in the front-ends, but can't we 
have cases which aren't caught by the front end, but after optimizations 
we're able to propagate &somelocal into the return statement?

It generally looks good and I'm ready to approve if the answer to the 
above question is "can't happen".  If it can happen, then we ought to 
handle it in the isolation code as well (ought to be relatively easy).

Jeff


>

  parent reply	other threads:[~2014-07-18  5:05 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 [this message]
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
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=53C746CC.1000007@redhat.com \
    --to=law@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=marc.glisse@inria.fr \
    /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).