c++: Seed imported bindings [PR 99039]

As mentioned in 99040's fix, we can get inter-module using decls.  If the
using decl is the only reference to an import, we'll have failed to
seed our imports leading to an assertion failure.  The fix is
straight-forwards, check binding contents when seeding imports.

	gcc/cp/
	* module.cc (module_state::write_cluster): Check bindings for
	imported using-decls.
	gcc/testsuite/
	* g++.dg/modules/pr99039_a.C: New.
	* g++.dg/modules/pr99039_b.C: New.
This commit is contained in:
Nathan Sidwell 2021-02-12 08:43:09 -08:00
parent 0c27fe96f8
commit 8c4137c7ea
3 changed files with 48 additions and 6 deletions

View file

@ -3108,7 +3108,8 @@ private:
unsigned section;
#if CHECKING_P
int importedness; /* Checker that imports not occurring
inappropriately. */
inappropriately. +ve imports ok,
-ve imports not ok. */
#endif
public:
@ -14632,13 +14633,36 @@ module_state::write_cluster (elf_out *to, depset *scc[], unsigned size,
{
depset *dep = b->deps[jx];
if (!dep->is_binding ()
&& dep->is_import () && !TREE_VISITED (dep->get_entity ()))
if (dep->is_binding ())
{
/* A cross-module using decl could be here. */
for (unsigned ix = dep->deps.length (); --ix;)
{
depset *bind = dep->deps[ix];
if (bind->get_entity_kind () == depset::EK_USING
&& bind->deps[1]->is_import ())
{
tree import = bind->deps[1]->get_entity ();
if (!TREE_VISITED (import))
{
sec.tree_node (import);
dump (dumper::CLUSTER)
&& dump ("Seeded import %N", import);
}
}
}
/* Also check the namespace itself. */
dep = dep->deps[0];
}
if (dep->is_import ())
{
tree import = dep->get_entity ();
sec.tree_node (import);
dump (dumper::CLUSTER) && dump ("Seeded import %N", import);
if (!TREE_VISITED (import))
{
sec.tree_node (import);
dump (dumper::CLUSTER) && dump ("Seeded import %N", import);
}
}
}
}

View file

@ -0,0 +1,9 @@
// PR c++/99039
// { dg-additional-options -fmodules-ts }
export module format;
// { dg-module-cmi format }
export namespace NS
{
void Format ();
}

View file

@ -0,0 +1,9 @@
// { dg-additional-options -fmodules-ts }
export module hello;
// { dg-module-cmi hello }
import format;
export namespace NS
{
using NS::Format;
}