[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Bug#630441: g++-4.6 miscompilation



Philip Ashmore <contact@philipashmore.com> writes:
> "reference to a char *" should read "reference to a char * on the stack"

gcc does warn about obvious instances of this; do you know why it
doesn't in this case?

For instance in this case:

   #include <string.h>
   char *f ()
   {
     char a[10];
     return strcpy (a, "hello");
   }

It doesn't warn, I suppose because the call to strcpy hides the
connection between "a" and the return value.

However, arguably it _could_ detect this, because strcpy is actually
inlined -- and then removed entirely, presumably because it notices
that the copy target disappears before it's ever used.

So the resulting assembly code is the same as just "return a;"!

hmm, I wonder if this is worth a gcc bug report...
(clang trunk shows exactly the same behavior)

-miles

-- 
Yossarian was moved very deeply by the absolute simplicity of
this clause of Catch-22 and let out a respectful whistle.
"That's some catch, that Catch-22," he observed.
"It's the best there is," Doc Daneeka agreed.


Reply to: