public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++/modules: Prevent treating suppressed debug info as extern template [PR112820]
@ 2023-12-03 12:46 Nathaniel Shead
  2024-01-02 22:52 ` Nathaniel Shead
  2024-01-04 20:39 ` Patrick Palka
  0 siblings, 2 replies; 11+ messages in thread
From: Nathaniel Shead @ 2023-12-03 12:46 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jason Merrill, Nathan Sidwell

Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk?

-- >8 --

The TYPE_DECL_SUPPRESS_DEBUG and DECL_EXTERNAL flags use the same
underlying bit. This is causing confusion when attempting to determine
the interface for a streamed-in class type, since the modules code
currently assumes that all DECL_EXTERNAL types are extern templates.
However, when -g is specified then TYPE_DECL_SUPPRESS_DEBUG (and hence
DECL_EXTERNAL) is marked on various other kinds of declarations, such as
vtables, which causes them to never be emitted.

This patch constrains the checks for DECL_EXTERNAL for this to only
consider template instantiations, thus avoiding the issue.

	PR c++/102607
	PR c++/112820

gcc/cp/ChangeLog:

	* module.cc (trees_in::read_class_def): Only set interface for
	template instantiations.

gcc/testsuite/ChangeLog:

	* g++.dg/modules/debug-2_a.C: New test.
	* g++.dg/modules/debug-2_b.C: New test.
	* g++.dg/modules/debug-2_c.C: New test.
	* g++.dg/modules/debug-3_a.C: New test.
	* g++.dg/modules/debug-3_b.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
---
 gcc/cp/module.cc                         | 4 +++-
 gcc/testsuite/g++.dg/modules/debug-2_a.C | 9 +++++++++
 gcc/testsuite/g++.dg/modules/debug-2_b.C | 8 ++++++++
 gcc/testsuite/g++.dg/modules/debug-2_c.C | 9 +++++++++
 gcc/testsuite/g++.dg/modules/debug-3_a.C | 8 ++++++++
 gcc/testsuite/g++.dg/modules/debug-3_b.C | 9 +++++++++
 6 files changed, 46 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/modules/debug-2_a.C
 create mode 100644 gcc/testsuite/g++.dg/modules/debug-2_b.C
 create mode 100644 gcc/testsuite/g++.dg/modules/debug-2_c.C
 create mode 100644 gcc/testsuite/g++.dg/modules/debug-3_a.C
 create mode 100644 gcc/testsuite/g++.dg/modules/debug-3_b.C

diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index 33fcf396875..257f39421d0 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -12041,7 +12041,9 @@ trees_in::read_class_def (tree defn, tree maybe_template)
   bool installing = maybe_dup && !TYPE_SIZE (type);
   if (installing)
     {
-      if (DECL_EXTERNAL (defn) && TYPE_LANG_SPECIFIC (type))
+      if (DECL_EXTERNAL (defn)
+	  && TYPE_LANG_SPECIFIC (type)
+	  && CLASSTYPE_TEMPLATE_INSTANTIATION (type))
 	{
 	  /* We don't deal with not-really-extern, because, for a
 	     module you want the import to be the interface, and for a
diff --git a/gcc/testsuite/g++.dg/modules/debug-2_a.C b/gcc/testsuite/g++.dg/modules/debug-2_a.C
new file mode 100644
index 00000000000..eed0905542b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/debug-2_a.C
@@ -0,0 +1,9 @@
+// PR c++/112820
+// { dg-additional-options "-fmodules-ts -g" }
+// { dg-module-cmi io }
+
+export module io;
+
+export struct error {
+  virtual const char* what() const noexcept;
+};
diff --git a/gcc/testsuite/g++.dg/modules/debug-2_b.C b/gcc/testsuite/g++.dg/modules/debug-2_b.C
new file mode 100644
index 00000000000..fc9afbc02e0
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/debug-2_b.C
@@ -0,0 +1,8 @@
+// PR c++/112820
+// { dg-additional-options "-fmodules-ts -g" }
+
+module io;
+
+const char* error::what() const noexcept {
+  return "bla";
+}
diff --git a/gcc/testsuite/g++.dg/modules/debug-2_c.C b/gcc/testsuite/g++.dg/modules/debug-2_c.C
new file mode 100644
index 00000000000..37117f69dcd
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/debug-2_c.C
@@ -0,0 +1,9 @@
+// PR c++/112820
+// { dg-module-do link }
+// { dg-additional-options "-fmodules-ts -g" }
+
+import io;
+
+int main() {
+  error{};
+}
diff --git a/gcc/testsuite/g++.dg/modules/debug-3_a.C b/gcc/testsuite/g++.dg/modules/debug-3_a.C
new file mode 100644
index 00000000000..9e33d8260fd
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/debug-3_a.C
@@ -0,0 +1,8 @@
+// PR c++/102607
+// { dg-additional-options "-fmodules-ts -g" }
+// { dg-module-cmi mod }
+
+export module mod;
+export struct B {
+  virtual ~B() = default;
+};
diff --git a/gcc/testsuite/g++.dg/modules/debug-3_b.C b/gcc/testsuite/g++.dg/modules/debug-3_b.C
new file mode 100644
index 00000000000..03c78b71b5d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/debug-3_b.C
@@ -0,0 +1,9 @@
+// PR c++/102607
+// { dg-module-do link }
+// { dg-additional-options "-fmodules-ts -g" }
+
+import mod;
+int main() {
+  struct D : B {};
+  (void)D{};
+}
-- 
2.42.0


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2024-01-22 11:04 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-03 12:46 [PATCH] c++/modules: Prevent treating suppressed debug info as extern template [PR112820] Nathaniel Shead
2024-01-02 22:52 ` Nathaniel Shead
2024-01-04 20:39 ` Patrick Palka
2024-01-08  9:57   ` [PATCH v2] c++/modules: Differentiate extern templates and TYPE_DECL_SUPPRESS_DEBUG [PR112820] Nathaniel Shead
2024-01-08 11:50     ` Richard Biener
2024-01-08 15:27     ` Patrick Palka
2024-01-15 23:10       ` Jason Merrill
2024-01-16 12:14         ` Nathaniel Shead
2024-01-17  6:33         ` [PATCH v3] c++/modules: Fix handling of extern templates in modules [PR112820] Nathaniel Shead
2024-01-17 15:51           ` Jason Merrill
2024-01-22 11:04             ` Nathaniel Shead

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).