public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/40391]  New: Segfault with -O, iostream, anonymous namespace on PPC
@ 2009-06-09 19:04 fp at mc dot com
  2009-06-09 19:05 ` [Bug c++/40391] " fp at mc dot com
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: fp at mc dot com @ 2009-06-09 19:04 UTC (permalink / raw)
  To: gcc-bugs

When compiling the attached code with gcc 4.2.1 with -O, the result fails on
PPC linux:

host> ppc86xx-linux-c++ -O -g -o iostest iostest.cxx
target> ./iostest
Segmentation fault

The code works fine:
- When built without optimization
- On x86 linux (also using gcc 4.2.1)
- With #define WORKAROUND (to avoid using an anonymous namespace)


-- 
           Summary: Segfault with -O, iostream, anonymous namespace on PPC
           Product: gcc
           Version: 4.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: fp at mc dot com
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: powerpc-timesys-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40391


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/40391] Segfault with -O, iostream, anonymous namespace on PPC
  2009-06-09 19:04 [Bug c++/40391] New: Segfault with -O, iostream, anonymous namespace on PPC fp at mc dot com
@ 2009-06-09 19:05 ` fp at mc dot com
  2009-06-09 19:13 ` [Bug middle-end/40391] " pinskia at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: fp at mc dot com @ 2009-06-09 19:05 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from fp at mc dot com  2009-06-09 19:05 -------
Created an attachment (id=17972)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=17972&action=view)
iostest.zip

ZIP file containing source and preprocessed code.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40391


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug middle-end/40391] Segfault with -O, iostream, anonymous namespace on PPC
  2009-06-09 19:04 [Bug c++/40391] New: Segfault with -O, iostream, anonymous namespace on PPC fp at mc dot com
  2009-06-09 19:05 ` [Bug c++/40391] " fp at mc dot com
@ 2009-06-09 19:13 ` pinskia at gcc dot gnu dot org
  2009-06-09 20:12 ` rguenth at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-06-09 19:13 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2009-06-09 19:12 -------
anonymous namespaces enable more inlining so ...


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c++                         |middle-end
           Keywords|                            |wrong-code


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40391


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug middle-end/40391] Segfault with -O, iostream, anonymous namespace on PPC
  2009-06-09 19:04 [Bug c++/40391] New: Segfault with -O, iostream, anonymous namespace on PPC fp at mc dot com
  2009-06-09 19:05 ` [Bug c++/40391] " fp at mc dot com
  2009-06-09 19:13 ` [Bug middle-end/40391] " pinskia at gcc dot gnu dot org
@ 2009-06-09 20:12 ` rguenth at gcc dot gnu dot org
  2009-06-10 10:33 ` jwakely dot gcc at gmail dot com
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-06-09 20:12 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from rguenth at gcc dot gnu dot org  2009-06-09 20:11 -------
GCC 4.2 is no longer maintained, and GCC 4.2.4 is the latest bugfix release
from the 4.2 series.  Please reproduce with at least GCC 4.3.3.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40391


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug middle-end/40391] Segfault with -O, iostream, anonymous namespace on PPC
  2009-06-09 19:04 [Bug c++/40391] New: Segfault with -O, iostream, anonymous namespace on PPC fp at mc dot com
                   ` (2 preceding siblings ...)
  2009-06-09 20:12 ` rguenth at gcc dot gnu dot org
@ 2009-06-10 10:33 ` jwakely dot gcc at gmail dot com
  2009-06-10 10:42 ` jwakely dot gcc at gmail dot com
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jwakely dot gcc at gmail dot com @ 2009-06-10 10:33 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from jwakely dot gcc at gmail dot com  2009-06-10 10:33 -------
The code is invalid

MyStream::
MyStream ()
  : std::iostream (&m_buf),
    m_buf ()
{
}

m_buf has not been cosntructed when you pass it to the base constructor, so
m_buf.init() is called on an uncosntructed streambuf.

You shoudl either pass a null pointer to the base class, then call m_buf.init()
in the MyStream constructor body, or use the base-from-member idiom to
initialise m_buf before the base class.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40391


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug middle-end/40391] Segfault with -O, iostream, anonymous namespace on PPC
  2009-06-09 19:04 [Bug c++/40391] New: Segfault with -O, iostream, anonymous namespace on PPC fp at mc dot com
                   ` (3 preceding siblings ...)
  2009-06-10 10:33 ` jwakely dot gcc at gmail dot com
@ 2009-06-10 10:42 ` jwakely dot gcc at gmail dot com
  2009-06-10 12:50 ` fp at mc dot com
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jwakely dot gcc at gmail dot com @ 2009-06-10 10:42 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from jwakely dot gcc at gmail dot com  2009-06-10 10:42 -------
(In reply to comment #4)
> 
> You shoudl either pass a null pointer to the base class, then call m_buf.init()

Oops, I got that a bit wrong, don't pass a null pointer to the base
constructor.

You should either call the default constructor of the base class, then call
this->init(&m_buf) ...

> in the MyStream constructor body, or use the base-from-member idiom to
> initialise m_buf before the base class.



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40391


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug middle-end/40391] Segfault with -O, iostream, anonymous namespace on PPC
  2009-06-09 19:04 [Bug c++/40391] New: Segfault with -O, iostream, anonymous namespace on PPC fp at mc dot com
                   ` (4 preceding siblings ...)
  2009-06-10 10:42 ` jwakely dot gcc at gmail dot com
@ 2009-06-10 12:50 ` fp at mc dot com
  2009-06-10 12:52 ` fp at mc dot com
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: fp at mc dot com @ 2009-06-10 12:50 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from fp at mc dot com  2009-06-10 12:50 -------
Jonathan,

thank you for identifying the bug in my original code.

According to my copy of ISO 14992:1998, std::iostream does not have a default
constructor.  However, my reading of the standard leads me to believe that it
is valid to pass a null pointer.  The description for basic_ios::init()
(27.4.4.1) says that, as a postcondition, rdstate() is "goodbit if sb is not a
null pointer, otherwise badbit".

libstdc++ does provide a default constructor for std::iostream.

However, either way, passing a null std::streambuf pointer to std::iostream
(which I believe is valid), or calling the "gcc extension" default constructor,
both still lead to a crash.

I've looked at the source code for std::iostream and its base classes and it
does not appear to dereference sb, it merely assigns the pointer to a meber
variable and tests it for non-null.

I am updating the test case.

Can someone please do me a favor and test this with a more current version of
gcc?


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40391


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug middle-end/40391] Segfault with -O, iostream, anonymous namespace on PPC
  2009-06-09 19:04 [Bug c++/40391] New: Segfault with -O, iostream, anonymous namespace on PPC fp at mc dot com
                   ` (5 preceding siblings ...)
  2009-06-10 12:50 ` fp at mc dot com
@ 2009-06-10 12:52 ` fp at mc dot com
  2009-06-10 13:09 ` jwakely dot gcc at gmail dot com
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: fp at mc dot com @ 2009-06-10 12:52 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from fp at mc dot com  2009-06-10 12:51 -------
Created an attachment (id=17974)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=17974&action=view)
iostest.zip

Fixes test case to avoid invalid code.  (Passes null pointer to base class then
calls this->init(&m_buf).)


-- 

fp at mc dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #17972|0                           |1
        is obsolete|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40391


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug middle-end/40391] Segfault with -O, iostream, anonymous namespace on PPC
  2009-06-09 19:04 [Bug c++/40391] New: Segfault with -O, iostream, anonymous namespace on PPC fp at mc dot com
                   ` (6 preceding siblings ...)
  2009-06-10 12:52 ` fp at mc dot com
@ 2009-06-10 13:09 ` jwakely dot gcc at gmail dot com
  2009-06-10 13:18 ` fp at mc dot com
  2009-06-10 13:20 ` fp at mc dot com
  9 siblings, 0 replies; 11+ messages in thread
From: jwakely dot gcc at gmail dot com @ 2009-06-10 13:09 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from jwakely dot gcc at gmail dot com  2009-06-10 13:09 -------
(In reply to comment #6)
> According to my copy of ISO 14992:1998, std::iostream does not have a default
> constructor.  However, my reading of the standard leads me to believe that it
> is valid to pass a null pointer.  The description for basic_ios::init()
> (27.4.4.1) says that, as a postcondition, rdstate() is "goodbit if sb is not a
> null pointer, otherwise badbit".

You're right, I should have checked before replying.

> Can someone please do me a favor and test this with a more current version of
> gcc?

I can't test on ppc. Where is the segfault? gdb or valgrind should tell you.



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40391


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug middle-end/40391] Segfault with -O, iostream, anonymous namespace on PPC
  2009-06-09 19:04 [Bug c++/40391] New: Segfault with -O, iostream, anonymous namespace on PPC fp at mc dot com
                   ` (7 preceding siblings ...)
  2009-06-10 13:09 ` jwakely dot gcc at gmail dot com
@ 2009-06-10 13:18 ` fp at mc dot com
  2009-06-10 13:20 ` fp at mc dot com
  9 siblings, 0 replies; 11+ messages in thread
From: fp at mc dot com @ 2009-06-10 13:18 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from fp at mc dot com  2009-06-10 13:18 -------
gdb reports

Program received signal SIGSEGV, Segmentation fault.
0x10001384 in make ()
    at
/opt/timesys/toolchains/lib/gcc/powerpc-timesys-linux-gnu/4.2.1/../../../../powerpc-timesys-linux-gnu/include/c++/4.2.1/ostream:366
366           basic_ostream() { }

which doesn't look very helpful.  I'll attach the result from "disassemble".


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40391


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug middle-end/40391] Segfault with -O, iostream, anonymous namespace on PPC
  2009-06-09 19:04 [Bug c++/40391] New: Segfault with -O, iostream, anonymous namespace on PPC fp at mc dot com
                   ` (8 preceding siblings ...)
  2009-06-10 13:18 ` fp at mc dot com
@ 2009-06-10 13:20 ` fp at mc dot com
  9 siblings, 0 replies; 11+ messages in thread
From: fp at mc dot com @ 2009-06-10 13:20 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from fp at mc dot com  2009-06-10 13:20 -------
Created an attachment (id=17975)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=17975&action=view)
disassemble.txt

Assembly dump of the function that crashes.  gdb reports that the crash occurs
at address 0x10001384.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40391


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2009-06-10 13:20 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-09 19:04 [Bug c++/40391] New: Segfault with -O, iostream, anonymous namespace on PPC fp at mc dot com
2009-06-09 19:05 ` [Bug c++/40391] " fp at mc dot com
2009-06-09 19:13 ` [Bug middle-end/40391] " pinskia at gcc dot gnu dot org
2009-06-09 20:12 ` rguenth at gcc dot gnu dot org
2009-06-10 10:33 ` jwakely dot gcc at gmail dot com
2009-06-10 10:42 ` jwakely dot gcc at gmail dot com
2009-06-10 12:50 ` fp at mc dot com
2009-06-10 12:52 ` fp at mc dot com
2009-06-10 13:09 ` jwakely dot gcc at gmail dot com
2009-06-10 13:18 ` fp at mc dot com
2009-06-10 13:20 ` fp at mc dot com

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).