This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Warn when returning the address of a temporary (middle-end) v2


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;
}

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

Thanks
Dave



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]