This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/77397] New: function initializing global static variables not optimized again fully
- From: "noone at turm-lahnstein dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sun, 28 Aug 2016 12:36:38 +0000
- Subject: [Bug c++/77397] New: function initializing global static variables not optimized again fully
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77397
Bug ID: 77397
Summary: function initializing global static variables not
optimized again fully
Product: gcc
Version: 6.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: noone@turm-lahnstein.de
Target Milestone: ---
Compiling
static int data = 0; static int dummy = data; int main() { }
with g++ -Os leads to a less than perfect assembler code:
.file "main.cpp"
.section .text.startup,"ax",@progbits
.globl main
.type main, @function
main:
.LFB0:
.cfi_startproc
xorl %eax, %eax
ret
.cfi_endproc
.LFE0:
.size main, .-main
.type _GLOBAL__sub_I_main, @function
_GLOBAL__sub_I_main:
.LFB2:
.cfi_startproc
ret
.cfi_endproc
.LFE2:
.size _GLOBAL__sub_I_main, .-_GLOBAL__sub_I_main
.ident "GCC: (GNU) 6.1.0"
.section .note.GNU-stack,"",@progbits
Because the static variables are optimized away, __GLOBAL__sub_I_main (used to
initialize them in the versions prior to 5.0) is not needed at all.
This carelessness is a likely cause for bug 77396.