This is the mail archive of the
mailing list for the GCC project.
Re: Warn when returning the address of a temporary (middle-end) v2
- From: Marc Glisse <marc dot glisse at inria dot fr>
- To: David Malcolm <dmalcolm at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Tue, 29 Jul 2014 21:22:27 +0200 (CEST)
- Subject: Re: Warn when returning the address of a temporary (middle-end) v2
- Authentication-results: sourceware.org; auth=none
- References: <alpine dot DEB dot 2 dot 02 dot 1406221930380 dot 20514 at stedding dot saclay dot inria dot fr> <87fvhmllc5 dot fsf at talisman dot default> <alpine dot DEB dot 2 dot 11 dot 1407291925091 dot 1585 at laptop-mg dot saclay dot inria dot fr> <1406660283 dot 2134 dot 122 dot camel at 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 <email@example.com> writes:
I followed the advice in this discussion:
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";
+ 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
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;
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