if (c_dialect_objc ())
objc_write_global_declarations ();
- if (module_determine_import_inits ())
+ bool has_module_inits = module_determine_import_inits ();
+ if (has_module_inits)
{
input_location = locus_at_end_of_parsing;
tree body = start_partial_init_fini_fn (true, DEFAULT_INIT_PRIORITY,
// Make sure there's a default priority entry.
if (!static_init_fini_fns[true])
static_init_fini_fns[true] = priority_map_t::create_ggc ();
- static_init_fini_fns[true]->get_or_insert (DEFAULT_INIT_PRIORITY);
- }
+ if (static_init_fini_fns[true]->get_or_insert (DEFAULT_INIT_PRIORITY))
+ has_module_inits = true;
+ }
/* Generate initialization and destruction functions for all
priorities for which they are required. They have C-language
}
pop_lang_context ();
- fini_modules (parse_in, module_cookie);
+ fini_modules (parse_in, module_cookie, has_module_inits);
/* Generate any missing aliases. */
maybe_apply_pending_pragma_weaks ();
bool exported_p : 1; /* directness != MD_NONE && exported. */
bool cmi_noted_p : 1; /* We've told the user about the CMI, don't
do it again */
- bool call_init_p : 1; /* This module's global initializer needs
+ bool active_init_p : 1; /* This module's global initializer needs
calling. */
bool inform_cmi_p : 1; /* Inform of a read/write. */
bool visited_p : 1; /* A walk-once flag. */
exported_p = false;
cmi_noted_p = false;
- call_init_p = false;
+ active_init_p = false;
partition_p = partition;
unsigned ordinary_locs;
unsigned macro_locs;
unsigned ordinary_loc_align;
+ unsigned active_init;
public:
module_state_config ()
:dialect_str (get_dialect ()),
num_imports (0), num_partitions (0), num_entities (0),
- ordinary_locs (0), macro_locs (0), ordinary_loc_align (0)
+ ordinary_locs (0), macro_locs (0), ordinary_loc_align (0),
+ active_init (0)
{
}
cfg.u (config.ordinary_locs);
cfg.u (config.macro_locs);
- cfg.u (config.ordinary_loc_align);
+ cfg.u (config.ordinary_loc_align);
+
+ cfg.u (config.active_init);
/* Now generate CRC, we'll have incorporated the inner CRC because
of its serialization above. */
config.macro_locs = cfg.u ();
config.ordinary_loc_align = cfg.u ();
+ config.active_init = cfg.u ();
+
done:
return cfg.end (from ());
}
if (ok && have_locs && !read_macro_maps ())
ok = false;
+ /* Note whether there's an active initializer. */
+ active_init_p = !is_header () && bool (config.active_init);
+
gcc_assert (slurp->current == ~0u);
return ok;
}
if (!modules || header_module_p ())
return false;
- /* Determine call_init_p. We need the same bitmap allocation
+ /* Prune active_init_p. We need the same bitmap allocation
scheme as for the imports member. */
function_depth++; /* Disable GC. */
- bitmap indirect_imports (BITMAP_GGC_ALLOC ());
+ bitmap covered_imports (BITMAP_GGC_ALLOC ());
bool any = false;
{
module_state *import = (*modules)[ix];
- if (!import->is_header ()
- && !bitmap_bit_p (indirect_imports, ix))
+ if (!import->active_init_p)
+ ;
+ else if (bitmap_bit_p (covered_imports, ix))
+ import->active_init_p = false;
+ else
{
- /* Everything this imports is therefore indirectly
- imported. */
- bitmap_ior_into (indirect_imports, import->imports);
- /* We don't have to worry about the self-import bit,
- because of the single pass. */
-
- import->call_init_p = true;
+ /* Everything this imports is therefore handled by its
+ initializer, so doesn't need initializing by us. */
+ bitmap_ior_into (covered_imports, import->imports);
any = true;
}
}
for (unsigned ix = modules->length (); --ix;)
{
module_state *import = (*modules)[ix];
- if (import->call_init_p)
+ if (import->active_init_p)
{
tree name = mangle_module_global_init (ix);
tree fndecl = build_lang_decl (FUNCTION_DECL, name, fntype);
// the module static initializer is a NOP or not.
static void
-late_finish_module (cpp_reader *reader, module_processing_cookie *cookie)
+late_finish_module (cpp_reader *reader, module_processing_cookie *cookie,
+ bool init_fn_non_empty)
{
timevar_start (TV_MODULE_EXPORT);
unsigned n = dump.push (state);
state->announce ("finishing");
+ cookie->config.active_init = init_fn_non_empty;
if (cookie->began)
state->write_end (&cookie->out, reader, cookie->config, cookie->crc);
}
void
-fini_modules (cpp_reader *reader, void *cookie)
+fini_modules (cpp_reader *reader, void *cookie, bool has_inits)
{
if (cookie)
late_finish_module (reader,
- static_cast<module_processing_cookie *> (cookie));
+ static_cast<module_processing_cookie *> (cookie),
+ has_inits);
/* We're done with the macro tables now. */
vec_free (macro_exports);