Consider the following file: struct X { X() { } }; struct Y { Y() { } }; X x1, x2, x3; Y y1, y2, y3; Compiling this to assembly code with -Os, we can see that the compiler is correctly optimizing away the do-nothing constructors: nothing is being done for any of these six global objects. However, the compiler still generates a do-nothing mod_init function. The relevant part of the assembly file is: .mod_init_func .align 2 .long __GLOBAL__I_x1 ... __GLOBAL__I_x1: LFB9: blr LFE9: At least we're only getting one do-nothing function per translation unit, instead of one per class or one per global. But it would be nice if we didn't get it at all.
Confirmed. The same holds for x86-linux, so I remove the target fields for this PR. W.
The same can be true of the C code too, I reported this once before for C in a another bug which caused an ICE for some target.
radr://2961456
These constructors are not trivial as defined by the C++ standard :).
*** Bug 36310 has been marked as a duplicate of this bug. ***
Subject: Bug 17736 Author: hubicka Date: Sat Aug 21 09:46:15 2010 New Revision: 163439 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=163439 Log: PR c++/45307 PR c++/17736 * cgraph.h (cgraph_only_called_directly_p, cgraph_can_remove_if_no_direct_calls_and_refs_p): Handle static cdtors. * cgraphunit.c (cgraph_decide_is_function_needed): Static cdtors are not needed. (cgraph_finalize_function): Static cdtors are reachable. (cgraph_mark_functions_to_output): Use cgraph_only_called_directly_p. * gcc.dg/ipa/ctor-empty-1.c: Add testcase. * g++.dg/tree-ssa/empty-2.C: Check that constructor got optimized out. Added: trunk/gcc/testsuite/gcc.dg/ipa/ctor-empty-1.c Modified: trunk/gcc/ChangeLog trunk/gcc/cgraph.c trunk/gcc/cgraph.h trunk/gcc/cgraphunit.c trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/g++.dg/tree-ssa/empty-2.C
We now remove pure constructors