public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/64899] New: Illegal dynamic initialization
@ 2015-02-02 13:27 wolfgang.roehrl@gi-de.com
  2015-02-02 13:40 ` [Bug c++/64899] " jakub at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: wolfgang.roehrl@gi-de.com @ 2015-02-02 13:27 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64899

            Bug ID: 64899
           Summary: Illegal dynamic initialization
           Product: gcc
           Version: 4.8.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: wolfgang.roehrl@gi-de.com

Hi,
I would like to post a bug report for the GNU C/C++ compiler 4.8.3.
We use the compiler to generate code for a PowerPC processor.

Invokation line for the GNU C++ compiler:

ccppc -c -x c++ -std=c++11 -Wall -Werror -g -mcpu=8540 -meabi
      -ftls-model=local-exec -msdata=sysv -fno-common -mspe -mabi=spe
      -mfloat-gprs=double -mbig -mmultiple -mno-string -misel -mstrict-align
      -fverbose-asm -fno-exceptions -fno-rtti -fgcse-sm -fno-section-anchors
      -ftemplate-backtrace-limit=20 -G 8 -O3
      -I<some include paths>
      -D<some #define's>
      X.CPP -oX.O


// file X.CPP

struct S
{
    constexpr S ()
    : m_ptrNext(nullptr)
    , m_wait(true)
    {}

    S* m_ptrNext;
    bool m_wait;
};



S s_Obj;
S s_Tab[2];



An inspection of the generated assembler file (see below) shows that only s_Obj
is statically initialized (constant initialization) whereas the array s_Tab[]
is dynamically initialized. (The dynamic initialization can be disastreous if
s_Tab[] is used for thread synchronisation.)

I think that both s_Obj and s_Tab[] should also be statically initialized since
S::S() is a constexpr constructor (C++11 standard, 3.6.2/2).


Following is the generated assembler file:

        .section         .text.startup,"ax",@progbits
        .align 2
        .type            _GLOBAL__sub_I_s_Obj, @function
_GLOBAL__sub_I_s_Obj:                    <--- dynamic initialization of s_Tab[]
        lis 10,s_Tab@ha   # tmp121,
        li 7,0            # tmp122,
        la 9,s_Tab@l(10)  # tmp120,, tmp121
        li 8,1            # tmp125,
        stw 7,s_Tab@l(10) # MEM[(struct S *)&s_Tab].m_ptrNext, tmp122
        stb 8,4(9)        # MEM[(struct S *)&s_Tab].m_wait, tmp125
        stw 7,8(9)        # MEM[(struct S *)&s_Tab + 8B].m_ptrNext, tmp122
        stb 8,12(9)       # MEM[(struct S *)&s_Tab + 8B].m_wait, tmp125
        blr
        .size             _GLOBAL__sub_I_s_Obj, .-_GLOBAL__sub_I_s_Obj

        .section          .ctors,"aw",@progbits
        .align 2
        .long             _GLOBAL__sub_I_s_Obj

        .globl            s_Tab
        .lcomm            s_Tab,16,8
        .type             s_Tab, @object

        .globl            s_Obj
        .section          .sdata,"aw",@progbits
        .align 2
        .type             s_Obj, @object
        .size             s_Obj, 8
s_Obj:                                   <--- statically initialized s_Obj
 # m_ptrNext:
        .long             0
 # m_wait:
        .byte             1
        .zero             3


Kind regards
W. Roehrl


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

* [Bug c++/64899] Illegal dynamic initialization
  2015-02-02 13:27 [Bug c++/64899] New: Illegal dynamic initialization wolfgang.roehrl@gi-de.com
@ 2015-02-02 13:40 ` jakub at gcc dot gnu.org
  2015-02-02 16:59 ` jason at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: jakub at gcc dot gnu.org @ 2015-02-02 13:40 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64899

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 #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Not sure if the C++ standard gives you any guarantees it won't be initialized
dynamically.


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

* [Bug c++/64899] Illegal dynamic initialization
  2015-02-02 13:27 [Bug c++/64899] New: Illegal dynamic initialization wolfgang.roehrl@gi-de.com
  2015-02-02 13:40 ` [Bug c++/64899] " jakub at gcc dot gnu.org
@ 2015-02-02 16:59 ` jason at gcc dot gnu.org
  2015-02-09 19:16 ` jason at gcc dot gnu.org
  2015-02-09 20:25 ` jason at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: jason at gcc dot gnu.org @ 2015-02-02 16:59 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64899

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2015-02-02
     Ever confirmed|0                           |1

--- Comment #2 from Jason Merrill <jason at gcc dot gnu.org> ---
(In reply to Jakub Jelinek from comment #1)
> Not sure if the C++ standard gives you any guarantees it won't be
> initialized dynamically.

It does; 3.6.2 says that it gets constant initialization.


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

* [Bug c++/64899] Illegal dynamic initialization
  2015-02-02 13:27 [Bug c++/64899] New: Illegal dynamic initialization wolfgang.roehrl@gi-de.com
  2015-02-02 13:40 ` [Bug c++/64899] " jakub at gcc dot gnu.org
  2015-02-02 16:59 ` jason at gcc dot gnu.org
@ 2015-02-09 19:16 ` jason at gcc dot gnu.org
  2015-02-09 20:25 ` jason at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: jason at gcc dot gnu.org @ 2015-02-09 19:16 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64899

--- Comment #3 from Jason Merrill <jason at gcc dot gnu.org> ---
Author: jason
Date: Mon Feb  9 19:15:55 2015
New Revision: 220544

URL: https://gcc.gnu.org/viewcvs?rev=220544&root=gcc&view=rev
Log:
    PR c++/64899
    * init.c (build_vec_init): Handle default-initialized array with
    constexpr default constructor.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-array10.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/init.c


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

* [Bug c++/64899] Illegal dynamic initialization
  2015-02-02 13:27 [Bug c++/64899] New: Illegal dynamic initialization wolfgang.roehrl@gi-de.com
                   ` (2 preceding siblings ...)
  2015-02-09 19:16 ` jason at gcc dot gnu.org
@ 2015-02-09 20:25 ` jason at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: jason at gcc dot gnu.org @ 2015-02-09 20:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64899

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED
           Assignee|unassigned at gcc dot gnu.org      |jason at gcc dot gnu.org
   Target Milestone|---                         |5.0

--- Comment #4 from Jason Merrill <jason at gcc dot gnu.org> ---
Fixed for GCC 5.


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

end of thread, other threads:[~2015-02-09 20:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-02 13:27 [Bug c++/64899] New: Illegal dynamic initialization wolfgang.roehrl@gi-de.com
2015-02-02 13:40 ` [Bug c++/64899] " jakub at gcc dot gnu.org
2015-02-02 16:59 ` jason at gcc dot gnu.org
2015-02-09 19:16 ` jason at gcc dot gnu.org
2015-02-09 20:25 ` jason 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).