Hi,

This patch fixes an ICE in the D front-end when handling the var
expression generated for `__traits(initSymbol)'.

The original assert expected the type of `__traits(initSymbol)' to be
exactly `const(void[])', but because D strips const from arrays to allow
passing slices as mutable ranges to template functions, so it got turned
into `const(void)[]'.

Regstrapped on x86_64-linux-gnu, committed to mainline, and backported
to releases/gcc-13, gcc-14, and gcc-15.

Regards,
Iain.

---
        PR d/123419

gcc/d/ChangeLog:

        * expr.cc (ExprVisitor::visit (VarExp *)): Adjust assertion.

gcc/testsuite/ChangeLog:

        * gdc.dg/pr123419.d: New test.
---
 gcc/d/expr.cc                   | 2 +-
 gcc/testsuite/gdc.dg/pr123419.d | 9 +++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gdc.dg/pr123419.d

diff --git a/gcc/d/expr.cc b/gcc/d/expr.cc
index 79d1839f0d6..77c9412fd94 100644
--- a/gcc/d/expr.cc
+++ b/gcc/d/expr.cc
@@ -2156,7 +2156,7 @@ public:
              {
                /* Generate a slice for non-zero initialized aggregates,
                   otherwise create an empty array.  */
-               gcc_assert (e->type->isConst ()
+               gcc_assert (e->type->nextOf ()->isConst ()
                            && e->type->nextOf ()->ty == TY::Tvoid);
 
                tree type = build_ctype (e->type);
diff --git a/gcc/testsuite/gdc.dg/pr123419.d b/gcc/testsuite/gdc.dg/pr123419.d
new file mode 100644
index 00000000000..84c0f866789
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr123419.d
@@ -0,0 +1,9 @@
+// { dg-do compile }
+struct S123419 {}
+
+void f123419(T)(T _) {}
+
+void test()
+{
+    f123419(__traits(initSymbol, S123419));
+}
-- 
2.43.0

Reply via email to