public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++ modules: ICE with class NTTP argument [PR100616]
@ 2022-09-22 18:25 Patrick Palka
  2022-09-22 19:13 ` Nathan Sidwell
  0 siblings, 1 reply; 10+ messages in thread
From: Patrick Palka @ 2022-09-22 18:25 UTC (permalink / raw)
  To: gcc-patches; +Cc: jason, nathan, Patrick Palka

When streaming in the artificial VAR_DECL synthesized for a class NTTP
argument, we end up crashing from complete_vars because the call to
maybe_register_incomplete_var from add_module_namespace_decl for this
VAR_DECL pushes an unexpected NULL_TREE type onto the incomplete_vars
vector.

This patch fixes this by checking for NULL_TREE before pushing onto
the vector.  This avoids the crash, but I noticed we still appear to
mishandle these artificial VAR_DECLs across translation units: the lookup
from get_template_parm_object for an existing VAR_DECL for the given
class NTTP argument fails to find the streamed-in VAR_DECL from the
other translation unit, so we end up creating a second VAR_DECL, but
that causes specialization equivalency issues in the XFAIL'd part of the
below test.  I'm afraid I don't understand why the lookup fails here
despite having done add_module_namespace_decl during stream-in, but
fixing the ICE seems like a safe and useful step towards enabling class
NTTP arguments used in modules.

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

	PR c++/100616

gcc/cp/ChangeLog:

	* decl.cc (maybe_register_incomplete_var): Check result of
	outermost_open_class.

gcc/testsuite/ChangeLog:

	* g++.dg/modules/pr100616_a.C: New test.
	* g++.dg/modules/pr100616_b.C: New test.
---
 gcc/cp/decl.cc                            |  8 +++++---
 gcc/testsuite/g++.dg/modules/pr100616_a.C |  8 ++++++++
 gcc/testsuite/g++.dg/modules/pr100616_b.C | 10 ++++++++++
 3 files changed, 23 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/modules/pr100616_a.C
 create mode 100644 gcc/testsuite/g++.dg/modules/pr100616_b.C

diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 80467c19254..722b64793ed 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -18235,9 +18235,11 @@ maybe_register_incomplete_var (tree var)
 	{
 	  /* When the outermost open class is complete we can resolve any
 	     pointers-to-members.  */
-	  tree context = outermost_open_class ();
-	  incomplete_var iv = {var, context};
-	  vec_safe_push (incomplete_vars, iv);
+	  if (tree context = outermost_open_class ())
+	    {
+	      incomplete_var iv = {var, context};
+	      vec_safe_push (incomplete_vars, iv);
+	    }
 	}
     }
 }
diff --git a/gcc/testsuite/g++.dg/modules/pr100616_a.C b/gcc/testsuite/g++.dg/modules/pr100616_a.C
new file mode 100644
index 00000000000..788af2eb533
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/pr100616_a.C
@@ -0,0 +1,8 @@
+// PR c++/100616
+// { dg-additional-options "-std=c++20 -fmodules-ts" }
+// { dg-module-cmi pr100616 }
+export module pr100616;
+
+template<auto> struct C { };
+struct A { };
+C<A{}> c1;
diff --git a/gcc/testsuite/g++.dg/modules/pr100616_b.C b/gcc/testsuite/g++.dg/modules/pr100616_b.C
new file mode 100644
index 00000000000..8037ceda3ed
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/pr100616_b.C
@@ -0,0 +1,10 @@
+// PR c++/100616
+// { dg-additional-options "-std=c++20 -fmodules-ts" }
+module pr100616;
+
+C<A{}> c2;
+
+// FIXME: We don't reuse the artificial VAR_DECL for the class NTTP argument A{}
+// from the other translation unit, which causes these types to be different.
+using ty_a = decltype(c1);
+using ty_a = decltype(c2); // { dg-bogus "conflicting" "" { xfail *-*-* } }
-- 
2.38.0.rc0.52.gdda7228a83


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

end of thread, other threads:[~2022-09-28 20:51 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-22 18:25 [PATCH] c++ modules: ICE with class NTTP argument [PR100616] Patrick Palka
2022-09-22 19:13 ` Nathan Sidwell
2022-09-23 13:32   ` Patrick Palka
2022-09-26 14:08     ` Nathan Sidwell
2022-09-26 14:46       ` Nathan Sidwell
2022-09-26 18:26         ` Patrick Palka
2022-09-26 19:05           ` Patrick Palka
2022-09-27 11:49             ` Nathan Sidwell
2022-09-28 14:42               ` Patrick Palka
2022-09-28 20:51                 ` Nathan Sidwell

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).