d: Fix ICE: type variant differs by TYPE_MAX_VALUE with -g [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.

	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.
This commit is contained in:
Iain Buclaw 2025-04-16 01:28:53 +02:00
parent a6f4178d0d
commit c5ffab99a5
3 changed files with 42 additions and 0 deletions

View file

@ -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);
}

View file

@ -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);
}

View file

@ -0,0 +1,8 @@
// { dg-do compile }
// { dg-additional-sources "imports/pr119826b.d" }
module pr119826;
int t119826(A)(A args)
{
assert(false);
}