[committed] d: Fix ICE: type variant differs by TYPE_MAX_VALUE with -g [PR119826]

Message ID 20250415234520.1174460-1-ibuclaw@gdcproject.org
State New
Headers
Series [committed] d: Fix ICE: type variant differs by TYPE_MAX_VALUE with -g [PR119826] |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm fail Patch failed to apply

Commit Message

Iain Buclaw April 15, 2025, 11:45 p.m. UTC
  Hi,

This patch fixes the ICE in PR119826.

Forward referenced enum types were never fixed up after the main
ENUMERAL_TYPE was finished.  All flags set are now propagated to all
variants after its mode, size, and alignment has been calculated.

Bootstrapped and regression tested on x86_64-linux-gnu/-m32, and
committed to mainline.  Will backport as necessary once gcc-14/13/12
release branches have been regtested too.

Regards,
Iain.

---
	PR d/119826

gcc/d/ChangeLog:

	* types.cc (TypeVisitor::visit (TypeEnum *)): Propagate flags of main
	enum types to all forward-referenced variants.

gcc/testsuite/ChangeLog:

	* gdc.dg/debug/imports/pr119826b.d: New test.
	* gdc.dg/debug/pr119826.d: New test.
---
 gcc/d/types.cc                                | 20 +++++++++++++++++++
 .../gdc.dg/debug/imports/pr119826b.d          | 14 +++++++++++++
 gcc/testsuite/gdc.dg/debug/pr119826.d         |  8 ++++++++
 3 files changed, 42 insertions(+)
 create mode 100644 gcc/testsuite/gdc.dg/debug/imports/pr119826b.d
 create mode 100644 gcc/testsuite/gdc.dg/debug/pr119826.d
  

Patch

diff --git a/gcc/d/types.cc b/gcc/d/types.cc
index e43fa88a5d4..1c74840605b 100644
--- a/gcc/d/types.cc
+++ b/gcc/d/types.cc
@@ -1179,6 +1179,26 @@  public:
 
 	layout_type (t->ctype);
 
+	/* Fix up all forward-referenced variants of this enum type.  */
+	for (tree v = TYPE_MAIN_VARIANT (t->ctype); v;
+	     v = TYPE_NEXT_VARIANT (v))
+	  {
+	    if (v == t->ctype)
+	      continue;
+
+	    TYPE_VALUES (v) = TYPE_VALUES (t->ctype);
+	    TYPE_LANG_SPECIFIC (v) = TYPE_LANG_SPECIFIC (t->ctype);
+	    TYPE_MIN_VALUE (v) = TYPE_MIN_VALUE (t->ctype);
+	    TYPE_MAX_VALUE (v) = TYPE_MAX_VALUE (t->ctype);
+	    TYPE_UNSIGNED (v) = TYPE_UNSIGNED (t->ctype);
+	    TYPE_SIZE (v) = TYPE_SIZE (t->ctype);
+	    TYPE_SIZE_UNIT (v) = TYPE_SIZE_UNIT (t->ctype);
+	    SET_TYPE_MODE (v, TYPE_MODE (t->ctype));
+	    TYPE_PRECISION (v) = TYPE_PRECISION (t->ctype);
+	    SET_TYPE_ALIGN (v, TYPE_ALIGN (t->ctype));
+	    TYPE_USER_ALIGN (v) = TYPE_USER_ALIGN (t->ctype);
+	  }
+
 	/* Complete forward-referenced fields of this enum type.  */
 	finish_incomplete_fields (t->ctype);
       }
diff --git a/gcc/testsuite/gdc.dg/debug/imports/pr119826b.d b/gcc/testsuite/gdc.dg/debug/imports/pr119826b.d
new file mode 100644
index 00000000000..3c5a6acbb87
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/debug/imports/pr119826b.d
@@ -0,0 +1,14 @@ 
+module imports.pr119826b;
+
+import pr119826 : t119826;
+
+class C119826
+{
+    enum E119826 { Evalue }
+    const E119826 em = void;
+}
+
+void f119826(C119826 c)
+{
+    t119826(c.em);
+}
diff --git a/gcc/testsuite/gdc.dg/debug/pr119826.d b/gcc/testsuite/gdc.dg/debug/pr119826.d
new file mode 100644
index 00000000000..2fb98c7ba9d
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/debug/pr119826.d
@@ -0,0 +1,8 @@ 
+// { dg-do compile }
+// { dg-additional-sources "imports/pr119826b.d" }
+module pr119826;
+
+int t119826(A)(A args)
+{
+    assert(false);
+}