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: no...@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.