https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98364
Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|WAITING |NEW Summary|[modules] global |[modules] unnneded global |constructor emission |constructors are emitted | |for a module Severity|normal |enhancement --- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> --- Confirmed: ;; Function (static initializers for hello.cc) (_ZGIW5helloEv) ;; enabled by -tree-original { static bool __in_chrg; static bool __in_chrg; if (__in_chrg) { return; } <<cleanup_point <<< Unknown tree: expr_stmt (void) (__in_chrg = 1) >>>>>; } In main-hello.cc.005t.original. The code comes from start_objects in cp/decl2.c: if (module_init > 0) { // 'static bool __in_chrg = false; // if (__inchrg) return; // __inchrg = true tree var = build_lang_decl (VAR_DECL, in_charge_identifier, boolean_type_node); DECL_CONTEXT (var) = fndecl; DECL_ARTIFICIAL (var) = true; TREE_STATIC (var) = true; pushdecl (var); cp_finish_decl (var, NULL_TREE, false, NULL_TREE, 0); tree if_stmt = begin_if_stmt (); finish_if_stmt_cond (var, if_stmt); finish_return_stmt (NULL_TREE); finish_then_clause (if_stmt); finish_if_stmt (if_stmt); tree assign = build2 (MODIFY_EXPR, boolean_type_node, var, boolean_true_node); TREE_SIDE_EFFECTS (assign) = true; finish_expr_stmt (assign); } if (module_init) module_add_import_initializers (); Maybe if there are no initializers, maybe we should not create the global init.