public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/55893] New: C++11: runtime segfault with static const object with virtual destructor
@ 2013-01-07  7:17 f.heckenbach@fh-soft.de
  2013-01-07  7:21 ` [Bug c++/55893] " f.heckenbach@fh-soft.de
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: f.heckenbach@fh-soft.de @ 2013-01-07  7:17 UTC (permalink / raw)
  To: gcc-bugs


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

             Bug #: 55893
           Summary: C++11: runtime segfault with static const object with
                    virtual destructor
    Classification: Unclassified
           Product: gcc
           Version: 4.7.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: f.heckenbach@fh-soft.de


Created attachment 29093
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=29093
Test case


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

* [Bug c++/55893] C++11: runtime segfault with static const object with virtual destructor
  2013-01-07  7:17 [Bug c++/55893] New: C++11: runtime segfault with static const object with virtual destructor f.heckenbach@fh-soft.de
@ 2013-01-07  7:21 ` f.heckenbach@fh-soft.de
  2013-01-07  7:41 ` pinskia at gcc dot gnu.org
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: f.heckenbach@fh-soft.de @ 2013-01-07  7:21 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #1 from Frank Heckenbach <f.heckenbach@fh-soft.de> 2013-01-07 07:21:01 UTC ---
Submitted to early. Here's the description:

The attached test case segfault at runtime:

% g++-4.7 -std=c++11 bug.cpp && ./a.out 
Segmentation fault

As far as I can see, that's because tmp is allocated in read-only storage, but
the destructor tries to write to it to update the vtable pointer.

It only happens in C++11 mode.


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

* [Bug c++/55893] C++11: runtime segfault with static const object with virtual destructor
  2013-01-07  7:17 [Bug c++/55893] New: C++11: runtime segfault with static const object with virtual destructor f.heckenbach@fh-soft.de
  2013-01-07  7:21 ` [Bug c++/55893] " f.heckenbach@fh-soft.de
@ 2013-01-07  7:41 ` pinskia at gcc dot gnu.org
  2013-01-07  9:45 ` [Bug c++/55893] [4.7/4.8 Regression][C++11] " rguenth at gcc dot gnu.org
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2013-01-07  7:41 UTC (permalink / raw)
  To: gcc-bugs


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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2013-01-07
     Ever Confirmed|0                           |1

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> 2013-01-07 07:40:21 UTC ---
Confirmed, also fails on the trunk.
    .section    .rodata
    .align 8
    .type    _ZZ4mainE3tmp, @object
    .size    _ZZ4mainE3tmp, 8
_ZZ4mainE3tmp:
    .quad    _ZTV3foo+16
    .weak    _ZTI3foo


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

* [Bug c++/55893] [4.7/4.8 Regression][C++11] runtime segfault with static const object with virtual destructor
  2013-01-07  7:17 [Bug c++/55893] New: C++11: runtime segfault with static const object with virtual destructor f.heckenbach@fh-soft.de
  2013-01-07  7:21 ` [Bug c++/55893] " f.heckenbach@fh-soft.de
  2013-01-07  7:41 ` pinskia at gcc dot gnu.org
@ 2013-01-07  9:45 ` rguenth at gcc dot gnu.org
  2013-01-07 23:28 ` daniel.kruegler at googlemail dot com
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2013-01-07  9:45 UTC (permalink / raw)
  To: gcc-bugs


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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2
      Known to work|                            |4.6.3
   Target Milestone|---                         |4.7.3
            Summary|C++11: runtime segfault     |[4.7/4.8 Regression][C++11]
                   |with static const object    |runtime segfault with
                   |with virtual destructor     |static const object with
                   |                            |virtual destructor
      Known to fail|                            |4.7.0

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> 2013-01-07 09:45:21 UTC ---
Works with 4.6.


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

* [Bug c++/55893] [4.7/4.8 Regression][C++11] runtime segfault with static const object with virtual destructor
  2013-01-07  7:17 [Bug c++/55893] New: C++11: runtime segfault with static const object with virtual destructor f.heckenbach@fh-soft.de
                   ` (2 preceding siblings ...)
  2013-01-07  9:45 ` [Bug c++/55893] [4.7/4.8 Regression][C++11] " rguenth at gcc dot gnu.org
@ 2013-01-07 23:28 ` daniel.kruegler at googlemail dot com
  2013-01-08 13:43 ` jakub at gcc dot gnu.org
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2013-01-07 23:28 UTC (permalink / raw)
  To: gcc-bugs


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

Daniel Krügler <daniel.kruegler at googlemail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |daniel.kruegler at
                   |                            |googlemail dot com

--- Comment #4 from Daniel Krügler <daniel.kruegler at googlemail dot com> 2013-01-07 23:27:57 UTC ---
The same problem also occurs in gcc 4.8.0 20121209 (experimental)


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

* [Bug c++/55893] [4.7/4.8 Regression][C++11] runtime segfault with static const object with virtual destructor
  2013-01-07  7:17 [Bug c++/55893] New: C++11: runtime segfault with static const object with virtual destructor f.heckenbach@fh-soft.de
                   ` (3 preceding siblings ...)
  2013-01-07 23:28 ` daniel.kruegler at googlemail dot com
@ 2013-01-08 13:43 ` jakub at gcc dot gnu.org
  2013-01-08 19:38 ` jason at gcc dot gnu.org
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-01-08 13:43 UTC (permalink / raw)
  To: gcc-bugs


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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org,
                   |                            |jason at gcc dot gnu.org

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-01-08 13:42:30 UTC ---
Caused by http://gcc.gnu.org/PR49673 I believe.  Perhaps instead of testing
whether TYPE_NEEDS_CONSTRUCTING we need to check if the type has non-trivial
destructor (is a user destructor on const qualified vars allowed to store into
the var anywhere?) or just a special case virtual dtors that do change the
vtable pointer?


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

* [Bug c++/55893] [4.7/4.8 Regression][C++11] runtime segfault with static const object with virtual destructor
  2013-01-07  7:17 [Bug c++/55893] New: C++11: runtime segfault with static const object with virtual destructor f.heckenbach@fh-soft.de
                   ` (4 preceding siblings ...)
  2013-01-08 13:43 ` jakub at gcc dot gnu.org
@ 2013-01-08 19:38 ` jason at gcc dot gnu.org
  2013-01-09  4:15 ` f.heckenbach@fh-soft.de
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: jason at gcc dot gnu.org @ 2013-01-08 19:38 UTC (permalink / raw)
  To: gcc-bugs


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

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
         AssignedTo|unassigned at gcc dot       |jason at gcc dot gnu.org
                   |gnu.org                     |


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

* [Bug c++/55893] [4.7/4.8 Regression][C++11] runtime segfault with static const object with virtual destructor
  2013-01-07  7:17 [Bug c++/55893] New: C++11: runtime segfault with static const object with virtual destructor f.heckenbach@fh-soft.de
                   ` (5 preceding siblings ...)
  2013-01-08 19:38 ` jason at gcc dot gnu.org
@ 2013-01-09  4:15 ` f.heckenbach@fh-soft.de
  2013-01-09 18:56 ` jason at gcc dot gnu.org
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: f.heckenbach@fh-soft.de @ 2013-01-09  4:15 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #6 from Frank Heckenbach <f.heckenbach@fh-soft.de> 2013-01-09 04:15:35 UTC ---
(In reply to comment #5)
> Caused by http://gcc.gnu.org/PR49673 I believe.  Perhaps instead of testing
> whether TYPE_NEEDS_CONSTRUCTING we need to check if the type has non-trivial
> destructor (is a user destructor on const qualified vars allowed to store into
> the var anywhere?)

According to
http://stackoverflow.com/questions/2271046/if-changing-a-const-object-is-undefined-behavior-then-how-do-constructors-and-de
(see references in the accepted answer), it is.

So perhaps, if any user destructor exists (direct or indirect through base
classes or fields), the object cannot be stored in read-only data (unless the
compiler can prove that it's still safe). If none exists, then updating the
vtable pointer is unneeded and it can be stored in read-only data.


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

* [Bug c++/55893] [4.7/4.8 Regression][C++11] runtime segfault with static const object with virtual destructor
  2013-01-07  7:17 [Bug c++/55893] New: C++11: runtime segfault with static const object with virtual destructor f.heckenbach@fh-soft.de
                   ` (6 preceding siblings ...)
  2013-01-09  4:15 ` f.heckenbach@fh-soft.de
@ 2013-01-09 18:56 ` jason at gcc dot gnu.org
  2013-01-09 18:56 ` jason at gcc dot gnu.org
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: jason at gcc dot gnu.org @ 2013-01-09 18:56 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #7 from Jason Merrill <jason at gcc dot gnu.org> 2013-01-09 18:55:21 UTC ---
Author: jason
Date: Wed Jan  9 18:55:12 2013
New Revision: 195062

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=195062
Log:
    PR c++/55893
    * decl.c (cp_finish_decl): Clear TREE_READONLY if the variable
    needs destruction.

Added:
    trunk/gcc/testsuite/g++.dg/init/const9.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/decl.c


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

* [Bug c++/55893] [4.7/4.8 Regression][C++11] runtime segfault with static const object with virtual destructor
  2013-01-07  7:17 [Bug c++/55893] New: C++11: runtime segfault with static const object with virtual destructor f.heckenbach@fh-soft.de
                   ` (7 preceding siblings ...)
  2013-01-09 18:56 ` jason at gcc dot gnu.org
@ 2013-01-09 18:56 ` jason at gcc dot gnu.org
  2013-01-09 18:58 ` jason at gcc dot gnu.org
  2013-01-15  8:41 ` jakub at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: jason at gcc dot gnu.org @ 2013-01-09 18:56 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #8 from Jason Merrill <jason at gcc dot gnu.org> 2013-01-09 18:55:42 UTC ---
Author: jason
Date: Wed Jan  9 18:55:34 2013
New Revision: 195063

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=195063
Log:
    PR c++/55893
    * decl.c (cp_finish_decl): Clear TREE_READONLY if the variable
    needs destruction.

Added:
    branches/gcc-4_7-branch/gcc/testsuite/g++.dg/init/const9.C
Modified:
    branches/gcc-4_7-branch/gcc/cp/ChangeLog
    branches/gcc-4_7-branch/gcc/cp/decl.c


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

* [Bug c++/55893] [4.7/4.8 Regression][C++11] runtime segfault with static const object with virtual destructor
  2013-01-07  7:17 [Bug c++/55893] New: C++11: runtime segfault with static const object with virtual destructor f.heckenbach@fh-soft.de
                   ` (8 preceding siblings ...)
  2013-01-09 18:56 ` jason at gcc dot gnu.org
@ 2013-01-09 18:58 ` jason at gcc dot gnu.org
  2013-01-15  8:41 ` jakub at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: jason at gcc dot gnu.org @ 2013-01-09 18:58 UTC (permalink / raw)
  To: gcc-bugs


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

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED

--- Comment #9 from Jason Merrill <jason at gcc dot gnu.org> 2013-01-09 18:58:00 UTC ---
Fixed.


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

* [Bug c++/55893] [4.7/4.8 Regression][C++11] runtime segfault with static const object with virtual destructor
  2013-01-07  7:17 [Bug c++/55893] New: C++11: runtime segfault with static const object with virtual destructor f.heckenbach@fh-soft.de
                   ` (9 preceding siblings ...)
  2013-01-09 18:58 ` jason at gcc dot gnu.org
@ 2013-01-15  8:41 ` jakub at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-01-15  8:41 UTC (permalink / raw)
  To: gcc-bugs


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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pavel.zbitskiy at gmail dot
                   |                            |com

--- Comment #10 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-01-15 08:41:00 UTC ---
*** Bug 55988 has been marked as a duplicate of this bug. ***


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

end of thread, other threads:[~2013-01-15  8:41 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-07  7:17 [Bug c++/55893] New: C++11: runtime segfault with static const object with virtual destructor f.heckenbach@fh-soft.de
2013-01-07  7:21 ` [Bug c++/55893] " f.heckenbach@fh-soft.de
2013-01-07  7:41 ` pinskia at gcc dot gnu.org
2013-01-07  9:45 ` [Bug c++/55893] [4.7/4.8 Regression][C++11] " rguenth at gcc dot gnu.org
2013-01-07 23:28 ` daniel.kruegler at googlemail dot com
2013-01-08 13:43 ` jakub at gcc dot gnu.org
2013-01-08 19:38 ` jason at gcc dot gnu.org
2013-01-09  4:15 ` f.heckenbach@fh-soft.de
2013-01-09 18:56 ` jason at gcc dot gnu.org
2013-01-09 18:56 ` jason at gcc dot gnu.org
2013-01-09 18:58 ` jason at gcc dot gnu.org
2013-01-15  8:41 ` jakub at gcc dot gnu.org

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