public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Patrick Palka <ppalka@redhat.com>
To: gcc-patches@gcc.gnu.org
Cc: jason@redhat.com, nathan@acm.org, Patrick Palka <ppalka@redhat.com>
Subject: [PATCH] c++ modules: verify_type failure with typedef enum [PR106848]
Date: Thu, 13 Oct 2022 11:39:21 -0400	[thread overview]
Message-ID: <20221013153921.3795800-1-ppalka@redhat.com> (raw)

Here during stream in we end up having created a type variant for the enum
before we read the enum's definition, and thus the variant inherited stale
TYPE_VALUES and TYPE_MIN/MAX_VALUES, which leads to an ICE (with -g).  The
stale variant got created from set_underlying_type during earlier stream in
of the (redundant) typedef for the enum.

This patch works around this by setting TYPE_VALUES and TYPE_MIN/MAX_VALUES
for all variants when reading in an enum definition.  Does this look like
the right approach?  Or perhaps we need to arrange that we read the enum
definition before reading in the typedef decl?  Note that seems to be an
issue only when the typedef name and enum names are the same (thus the
typedef is redundant), otherwise we seem to read the enum definition first
as desired.

	PR c++/106848

gcc/cp/ChangeLog:

	* module.cc (trees_in::read_enum_def): Set the TYPE_VALUES,
	TYPE_MIN_VALUE and TYPE_MAX_VALUE of all type variants.

gcc/testsuite/ChangeLog:

	* g++.dg/modules/enum-9_a.H: New test.
	* g++.dg/modules/enum-9_b.C: New test.
---
 gcc/cp/module.cc                        | 9 ++++++---
 gcc/testsuite/g++.dg/modules/enum-9_a.H | 5 +++++
 gcc/testsuite/g++.dg/modules/enum-9_b.C | 6 ++++++
 3 files changed, 17 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/modules/enum-9_a.H
 create mode 100644 gcc/testsuite/g++.dg/modules/enum-9_b.C

diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index 7ffeefa7c1f..97fb80bcd44 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -12303,9 +12303,12 @@ trees_in::read_enum_def (tree defn, tree maybe_template)
 
   if (installing)
     {
-      TYPE_VALUES (type) = values;
-      TYPE_MIN_VALUE (type) = min;
-      TYPE_MAX_VALUE (type) = max;
+      for (tree t = type; t; t = TYPE_NEXT_VARIANT (t))
+	{
+	  TYPE_VALUES (t) = values;
+	  TYPE_MIN_VALUE (t) = min;
+	  TYPE_MAX_VALUE (t) = max;
+	}
 
       rest_of_type_compilation (type, DECL_NAMESPACE_SCOPE_P (defn));
     }
diff --git a/gcc/testsuite/g++.dg/modules/enum-9_a.H b/gcc/testsuite/g++.dg/modules/enum-9_a.H
new file mode 100644
index 00000000000..fb7d10ad3b6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/enum-9_a.H
@@ -0,0 +1,5 @@
+// PR c++/106848
+// { dg-additional-options -fmodule-header }
+// { dg-module-cmi {} }
+
+typedef enum memory_order { memory_order_seq_cst } memory_order;
diff --git a/gcc/testsuite/g++.dg/modules/enum-9_b.C b/gcc/testsuite/g++.dg/modules/enum-9_b.C
new file mode 100644
index 00000000000..63e81675d0a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/enum-9_b.C
@@ -0,0 +1,6 @@
+// PR c++/106848
+// { dg-additional-options "-fmodules-ts -g" }
+
+import "enum-9_a.H";
+
+memory_order x = memory_order_seq_cst;
-- 
2.38.0.68.ge85701b4af


             reply	other threads:[~2022-10-13 15:39 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-13 15:39 Patrick Palka [this message]
2022-10-14  6:04 ` Richard Biener
2022-10-18 18:26   ` Patrick Palka
2022-10-19  7:33     ` Richard Biener
2022-10-19 13:55       ` Patrick Palka
2022-10-21 12:36         ` Nathan Sidwell
2022-10-21 13:11           ` Patrick Palka
2022-10-24 12:39             ` Nathan Sidwell
2022-10-25 17:46               ` Patrick Palka

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221013153921.3795800-1-ppalka@redhat.com \
    --to=ppalka@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@redhat.com \
    --cc=nathan@acm.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).