PR optimization/9630: [3.2/3.3/3.4 regression] crash with -freg-struct-return in C++ code

Steven Bosscher s.bosscher@student.tudelft.nl
Wed Mar 12 18:09:00 GMT 2003


http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=9630

This PR is about wrong code when *not* optimizing.

The expected output of the test case is 2.  With
GCC 3.3 (todays CVS), you get:

# gcc -lstdc++ -freg-struct-return 9630.cc
# a.out
Segmentation fault
# gcc -lstdc++ -freg-struct-return 9630.cc -O
# a.out
2
#

Could it be that this bug happens because libstdc++ was *not*
compiled with --freg-struct-return?

Say, the function that segfaults at -O0 is inlined at -O1.
Then at -O0 you pass the object of class "string" in a reg to
the library function that is not compiled with
-freg-struct-return, so it expects a pointer to the object
on the stack. and it segfaults.

Does that make sense?

I'm asking because I was cutting down a test case (from some
15000 lines to 380 now, see attachment 2 in the PR in GNATS)
when when I accidentally removed the lines:

namespace std
{
  extern template class basic_string<char>;
}

and that makes the segfault magically go away...

Greetz
Steven




More information about the Gcc-bugs mailing list