[Bug c++/64899] New: Illegal dynamic initialization
wolfgang.roehrl@gi-de.com
gcc-bugzilla@gcc.gnu.org
Mon Feb 2 13:27:00 GMT 2015
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
More information about the Gcc-bugs
mailing list