From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29849 invoked by alias); 26 Oct 2012 13:14:06 -0000 Received: (qmail 29664 invoked by uid 48); 26 Oct 2012 13:13:40 -0000 From: "zhroma at ispras dot ru" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/55081] New: [4.8 regression?] Non-optimized static array elements initialization Date: Fri, 26 Oct 2012 13:14:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: zhroma at ispras dot ru X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2012-10/txt/msg02441.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55081 Bug #: 55081 Summary: [4.8 regression?] Non-optimized static array elements initialization Classification: Unclassified Product: gcc Version: 4.8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned@gcc.gnu.org ReportedBy: zhroma@ispras.ru Created attachment 28536 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28536 Preprocessed minimized testcase. In some cases g++ 4.8 revision 192141 and later generate initialization block for local static array with constant elements, while earlier g++ versions insert constants into assembly data section (gcc-base is rev192140, gcc-peak is rev192141, tested on 64bit Linux): $ cat test.cpp struct R { int field; }; long* foo() { R r; static long array[] = { sizeof(char), (reinterpret_cast(&(r.field)) - reinterpret_cast(&r))+1, }; return array; } $ gcc-base/bin/g++ -O2 test.cpp -S -o 1.s $ gcc-peak/bin/g++ -O2 test.cpp -S -o 2.s $ diff -u 1.s 2.s --- 1.s +++ 2.s @@ -6,8 +6,27 @@ _Z3foov: .LFB0: .cfi_startproc + cmpb $0, _ZGVZ3foovE5array(%rip) + je .L11 movl $_ZZ3foovE5array, %eax ret + .p2align 4,,10 + .p2align 3 +.L11: + subq $8, %rsp + .cfi_def_cfa_offset 16 + movl $_ZGVZ3foovE5array, %edi + call __cxa_guard_acquire + testl %eax, %eax + je .L3 + movl $_ZGVZ3foovE5array, %edi + movq $1, _ZZ3foovE5array(%rip) + call __cxa_guard_release +.L3: + movl $_ZZ3foovE5array, %eax + addq $8, %rsp + .cfi_def_cfa_offset 8 + ret .cfi_endproc .LFE0: .size _Z3foov, .-_Z3foov @@ -16,7 +35,9 @@ .type _ZZ3foovE5array, @object .size _ZZ3foovE5array, 16 _ZZ3foovE5array: + .zero 8 .quad 1 - .quad 1 + .local _ZGVZ3foovE5array + .comm _ZGVZ3foovE5array,8,8 .ident "GCC: (GNU) 4.8.0 20121005 (experimental)" .section .note.GNU-stack,"",@progbits So, the value of array[0] (sizeof(char) equals 1) is generated on the first function call instead of emitting it to assemlby data section directly. If I remove second constant element static long array[] = { sizeof(char), }; .. or reimplement it in the following way static long array[] = { sizeof(char), __builtin_offsetof(R, field)+1, }; the problem disappears. As I understand, the patch rev192141 goal is new warning. Maybe it should not affect codegen so much? Additional information. The problem described above lead to Webkit build failure. There is the following step while generating assembly for Webkit JavaScriptCore low-level interpreter: it generates dummy executable containing a function with static array: static const unsigned extractorTable[308992] = { unsigned(-1639711386), (reinterpret_cast(&(reinterpret_cast (0x4000)-unsigned(267773781), sizeof(ValueProfile), // and so on... }; And later this dummy executable file (its data section) is parsed to find all these sizeof-and-offset values. This certainly seems strange, but when Webkit is cross-compiled it helps to find offsets without running anything on target. After gcc revision 192141 that executable-parsing script fails to get all sizeof(...) values - they are zeros in gcc-generated assembly data section.