c++: Originating and instantiating module

With modules streamed entities have two new properties -- the module
that declares them and the module that instantiates them.  Here
'instantiate' applies to more than just templates -- for instance an
implicit member fn.  These may well be the same module.  This adds the
calls to places that need it.

	gcc/cp/
	* class.c (layout_class_type): Call set_instantiating_module.
	(build_self_reference): Likewise.
	* decl.c (grokfndecl): Call set_originating_module.
	(grokvardecl): Likewise.
	(grokdeclarator): Likewise.
	* pt.c (maybe_new_partial_specialization): Call
	set_instantiating_module, propagate DECL_MODULE_EXPORT_P.
	(lookup_template_class_1): Likewise.
	(tsubst_function_decl): Likewise.
	(tsubst_decl, instantiate_template_1): Likewise.
	(build_template_decl): Propagate module flags.
	(tsubst_template_dcl): Likewise.
	(finish_concept_definition): Call set_originating_module.
	* module.cc (set_instantiating_module, set_originating_module): Stubs.
This commit is contained in:
Nathan Sidwell 2020-12-08 12:34:25 -08:00
parent 4ed1dc1275
commit 570c312c03
4 changed files with 66 additions and 0 deletions

View File

@ -6759,6 +6759,8 @@ layout_class_type (tree t, tree *virtuals_p)
TYPE_CONTEXT (base_t) = t;
DECL_CONTEXT (base_d) = t;
set_instantiating_module (base_d);
/* If the ABI version is not at least two, and the last
field was a bit-field, RLI may not be on a byte
boundary. In particular, rli_size_unit_so_far might
@ -8738,6 +8740,7 @@ build_self_reference (void)
DECL_ARTIFICIAL (decl) = 1;
SET_DECL_SELF_REFERENCE_P (decl);
set_underlying_type (decl);
set_instantiating_module (decl);
if (processing_template_decl)
decl = push_template_decl (decl);

View File

@ -9878,6 +9878,8 @@ grokfndecl (tree ctype,
&& !processing_template_decl)
deduce_noexcept_on_destructor (decl);
set_originating_module (decl);
decl = check_explicit_specialization (orig_declarator, decl,
template_count,
2 * funcdef_flag +
@ -10122,6 +10124,8 @@ grokvardecl (tree type,
TREE_PUBLIC (decl) = DECL_EXTERNAL (decl);
}
set_originating_module (decl);
if (decl_spec_seq_has_spec_p (declspecs, ds_thread))
{
if (DECL_EXTERNAL (decl) || TREE_STATIC (decl))
@ -12965,6 +12969,8 @@ grokdeclarator (const cp_declarator *declarator,
revert this subsequently if it determines that
the clones should share a common implementation. */
DECL_ABSTRACT_P (decl) = true;
set_originating_module (decl);
}
else if (current_class_type
&& constructor_name_p (unqualified_id, current_class_type))
@ -13499,6 +13505,8 @@ grokdeclarator (const cp_declarator *declarator,
; /* We already issued a permerror. */
else if (decl && DECL_NAME (decl))
{
set_originating_module (decl, true);
if (initialized)
/* Kludge: We need funcdef_flag to be true in do_friend for
in-class defaulted functions, but that breaks grokfndecl.

View File

@ -99,6 +99,16 @@ get_originating_module (tree, bool)
return 0;
}
void
set_instantiating_module (tree)
{
}
void
set_originating_module (tree, bool)
{
}
module_state *
preprocess_module (module_state *, unsigned, bool, bool, bool, cpp_reader *)
{

View File

@ -960,6 +960,9 @@ maybe_new_partial_specialization (tree type)
TREE_PRIVATE (d) = (current_access_specifier == access_private_node);
TREE_PROTECTED (d) = (current_access_specifier == access_protected_node);
set_instantiating_module (d);
DECL_MODULE_EXPORT_P (d) = DECL_MODULE_EXPORT_P (tmpl);
return t;
}
@ -4922,6 +4925,17 @@ build_template_decl (tree decl, tree parms, bool member_template_p)
DECL_SOURCE_LOCATION (tmpl) = DECL_SOURCE_LOCATION (decl);
DECL_MEMBER_TEMPLATE_P (tmpl) = member_template_p;
if (modules_p ())
{
/* Propagate module information from the decl. */
DECL_MODULE_EXPORT_P (tmpl) = DECL_MODULE_EXPORT_P (decl);
if (DECL_LANG_SPECIFIC (decl))
{
DECL_MODULE_PURVIEW_P (tmpl) = DECL_MODULE_PURVIEW_P (decl);
gcc_checking_assert (!DECL_MODULE_IMPORT_P (decl));
}
}
return tmpl;
}
@ -9994,6 +10008,12 @@ lookup_template_class_1 (tree d1, tree arglist, tree in_decl, tree context,
= DECL_SOURCE_LOCATION (TYPE_STUB_DECL (template_type));
}
set_instantiating_module (type_decl);
/* Although GEN_TMPL is the TEMPLATE_DECL, it has the same value
of export flag. We want to propagate this because it might
be a friend declaration that pushes a new hidden binding. */
DECL_MODULE_EXPORT_P (type_decl) = DECL_MODULE_EXPORT_P (gen_tmpl);
if (CLASS_TYPE_P (template_type))
{
TREE_PRIVATE (type_decl)
@ -13912,6 +13932,7 @@ tsubst_function_decl (tree t, tree args, tsubst_flags_t complain,
if (!DECL_DELETED_FN (r))
DECL_INITIAL (r) = NULL_TREE;
DECL_CONTEXT (r) = ctx;
set_instantiating_module (r);
/* Handle explicit(dependent-expr). */
if (DECL_HAS_DEPENDENT_EXPLICIT_SPEC_P (t))
@ -14235,6 +14256,24 @@ tsubst_template_decl (tree t, tree args, tsubst_flags_t complain,
TREE_TYPE (r) = TREE_TYPE (inner);
DECL_CONTEXT (r) = DECL_CONTEXT (inner);
if (modules_p ())
{
/* Propagate module information from the decl. */
DECL_MODULE_EXPORT_P (r) = DECL_MODULE_EXPORT_P (inner);
if (DECL_LANG_SPECIFIC (inner))
{
DECL_MODULE_PURVIEW_P (r) = DECL_MODULE_PURVIEW_P (inner);
/* If this is a constrained template, the above tsubst of
inner can find the unconstrained template, which may have
come from an import. This is ok, because we don't
register this instantiation (see below). */
gcc_checking_assert (!DECL_MODULE_IMPORT_P (inner)
|| (TEMPLATE_PARMS_CONSTRAINTS
(DECL_TEMPLATE_PARMS (t))));
DECL_MODULE_IMPORT_P (r) = false;
}
}
DECL_TEMPLATE_INSTANTIATIONS (r) = NULL_TREE;
DECL_TEMPLATE_SPECIALIZATIONS (r) = NULL_TREE;
@ -14789,6 +14828,8 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain)
SET_DECL_ASSEMBLER_NAME (r, NULL_TREE);
if (CODE_CONTAINS_STRUCT (TREE_CODE (t), TS_DECL_WRTL))
SET_DECL_RTL (r, NULL);
set_instantiating_module (r);
/* The initializer must not be expanded until it is required;
see [temp.inst]. */
DECL_INITIAL (r) = NULL_TREE;
@ -20951,6 +20992,8 @@ instantiate_template_1 (tree tmpl, tree orig_args, tsubst_flags_t complain)
DECL_TI_TEMPLATE (fndecl) = tmpl;
DECL_TI_ARGS (fndecl) = targ_ptr;
set_instantiating_module (fndecl);
/* Now we know the specialization, compute access previously
deferred. Do no access control for inheriting constructors,
as we already checked access for the inherited constructor. */
@ -28037,6 +28080,8 @@ finish_concept_definition (cp_expr id, tree init)
DECL_CONTEXT (decl) = current_scope ();
DECL_INITIAL (decl) = init;
set_originating_module (decl, false);
/* Push the enclosing template. */
return push_template_decl (decl);
}