From 92941cea2f05a8cf79fc71aa39fa948dcfb82d7a Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Tue, 9 Feb 2021 08:11:58 -0800 Subject: [PATCH] c++: Fix indirect partitions [PR 98944] The most recent reimplementation of module loading initialization changed the behaviour of setting an import's location, and broke some partition handling. PR c++/98944 gcc/cp/ * module.cc (module_state::is_rooted): Rename to ... (module_state::has_location): ... here. Adjust callers. (module_state::read_partitions): Adjust validity check. Don't overwrite a known location. gcc/testsuite/ * g++.dg/modules/pr98944_a.C: New. * g++.dg/modules/pr98944_b.C: New. * g++.dg/modules/pr98944_c.C: New. * g++.dg/modules/pr98944_d.C: New. --- gcc/cp/module.cc | 23 ++++++++++++----------- gcc/testsuite/g++.dg/modules/pr98944_a.C | 9 +++++++++ gcc/testsuite/g++.dg/modules/pr98944_b.C | 8 ++++++++ gcc/testsuite/g++.dg/modules/pr98944_c.C | 8 ++++++++ gcc/testsuite/g++.dg/modules/pr98944_d.C | 8 ++++++++ 5 files changed, 45 insertions(+), 11 deletions(-) create mode 100644 gcc/testsuite/g++.dg/modules/pr98944_a.C create mode 100644 gcc/testsuite/g++.dg/modules/pr98944_b.C create mode 100644 gcc/testsuite/g++.dg/modules/pr98944_c.C create mode 100644 gcc/testsuite/g++.dg/modules/pr98944_d.C diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index 41ce2011525..0749db8fe94 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -3608,8 +3608,8 @@ class GTY((chain_next ("%h.parent"), for_user)) module_state { } public: - /* Is this not a real module? */ - bool is_rooted () const + /* Is this a real module? */ + bool has_location () const { return loc != UNKNOWN_LOCATION; } @@ -4416,7 +4416,7 @@ dumper::operator () (const char *format, ...) const char *str = "(none)"; if (module_state *m = va_arg (args, module_state *)) { - if (!m->is_rooted ()) + if (!m->has_location ()) str = "(detached)"; else str = m->get_flatname (); @@ -14441,16 +14441,17 @@ module_state::read_partitions (unsigned count) dump () && dump ("Reading elided partition %s (crc=%x)", name, crc); module_state *imp = get_module (name); - if (!imp || !imp->is_partition () || imp->is_rooted () - || get_primary (imp) != this) + if (!imp /* Partition should be ... */ + || !imp->is_partition () /* a partition ... */ + || imp->loadedness != ML_NONE /* that is not yet loaded ... */ + || get_primary (imp) != this) /* whose primary is this. */ { sec.set_overrun (); break; } - /* Attach the partition without loading it. We'll have to load - for real if it's indirectly imported. */ - imp->loc = floc; + if (!imp->has_location ()) + imp->loc = floc; imp->crc = crc; if (!imp->filename && fname[0]) imp->filename = xstrdup (fname); @@ -18857,7 +18858,7 @@ direct_import (module_state *import, cpp_reader *reader) timevar_start (TV_MODULE_IMPORT); unsigned n = dump.push (import); - gcc_checking_assert (import->is_direct () && import->is_rooted ()); + gcc_checking_assert (import->is_direct () && import->has_location ()); if (import->loadedness == ML_NONE) if (!import->do_import (reader, true)) gcc_unreachable (); @@ -18904,7 +18905,7 @@ import_module (module_state *import, location_t from_loc, bool exporting_p, linemap_module_reparent (line_table, import->loc, from_loc); } gcc_checking_assert (!import->module_p); - gcc_checking_assert (import->is_direct () && import->is_rooted ()); + gcc_checking_assert (import->is_direct () && import->has_location ()); direct_import (import, reader); } @@ -18934,7 +18935,7 @@ declare_module (module_state *module, location_t from_loc, bool exporting_p, } gcc_checking_assert (module->module_p); - gcc_checking_assert (module->is_direct () && module->is_rooted ()); + gcc_checking_assert (module->is_direct () && module->has_location ()); /* Yer a module, 'arry. */ module_kind &= ~MK_GLOBAL; diff --git a/gcc/testsuite/g++.dg/modules/pr98944_a.C b/gcc/testsuite/g++.dg/modules/pr98944_a.C new file mode 100644 index 00000000000..9475317dc82 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/pr98944_a.C @@ -0,0 +1,9 @@ +// PR 98944, the example in [module.unit]/4 +// { dg-additional-options -fmodules-ts } + +// tu3 + +module A:Internals; +// { dg-module-cmi A:Internals } + +int bar(); diff --git a/gcc/testsuite/g++.dg/modules/pr98944_b.C b/gcc/testsuite/g++.dg/modules/pr98944_b.C new file mode 100644 index 00000000000..209eafccc76 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/pr98944_b.C @@ -0,0 +1,8 @@ +// { dg-additional-options -fmodules-ts } + +// tu2 +export module A:Foo; +// { dg-module-cmi A:Foo } + +import :Internals; +export int foo() { return 2 * (bar() + 1); } diff --git a/gcc/testsuite/g++.dg/modules/pr98944_c.C b/gcc/testsuite/g++.dg/modules/pr98944_c.C new file mode 100644 index 00000000000..90be60f2629 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/pr98944_c.C @@ -0,0 +1,8 @@ +// { dg-additional-options -fmodules-ts } + +// tu1 +export module A; +// { dg-module-cmi A } + +export import :Foo; +export int baz(); diff --git a/gcc/testsuite/g++.dg/modules/pr98944_d.C b/gcc/testsuite/g++.dg/modules/pr98944_d.C new file mode 100644 index 00000000000..25364ab9aae --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/pr98944_d.C @@ -0,0 +1,8 @@ +// { dg-additional-options -fmodules-ts } + +// tu4 +module A; + +import :Internals; +int bar() { return baz() - 10; } +int baz() { return 30; } -- 2.30.2