aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorNathan Sidwell <nathan@acm.org>2021-02-09 08:11:58 -0800
committerNathan Sidwell <nathan@acm.org>2021-02-09 08:17:12 -0800
commit92941cea2f05a8cf79fc71aa39fa948dcfb82d7a (patch)
tree00a2763e9a640813f764a0d60f83d7761fb53556 /gcc
parent26a3f288f1895a8c061c0458590542a3d2ee796a (diff)
downloadgcc-92941cea2f05a8cf79fc71aa39fa948dcfb82d7a.zip
gcc-92941cea2f05a8cf79fc71aa39fa948dcfb82d7a.tar.gz
gcc-92941cea2f05a8cf79fc71aa39fa948dcfb82d7a.tar.bz2
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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/module.cc23
-rw-r--r--gcc/testsuite/g++.dg/modules/pr98944_a.C9
-rw-r--r--gcc/testsuite/g++.dg/modules/pr98944_b.C8
-rw-r--r--gcc/testsuite/g++.dg/modules/pr98944_c.C8
-rw-r--r--gcc/testsuite/g++.dg/modules/pr98944_d.C8
5 files changed, 45 insertions, 11 deletions
diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index 41ce201..0749db8 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 0000000..9475317
--- /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 0000000..209eafc
--- /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 0000000..90be60f
--- /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 0000000..25364ab
--- /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; }