d: Fix internal compiler error: in build_complex, at tree.c:2358
authorIain Buclaw <ibuclaw@gdcproject.org>
Mon, 21 Mar 2022 18:47:50 +0000 (19:47 +0100)
committerIain Buclaw <ibuclaw@gdcproject.org>
Mon, 21 Mar 2022 18:51:51 +0000 (19:51 +0100)
The conversion from the special _Complex enum to native complex used
build_complex, however the input value isn't necessarily a literal.

PR d/105004

gcc/d/ChangeLog:

* d-codegen.cc (build_struct_literal): Use complex_expr to build
complex expressions from __c_complex types.

gcc/testsuite/ChangeLog:

* gdc.dg/pr105004.d: New test.

gcc/d/d-codegen.cc
gcc/testsuite/gdc.dg/pr105004.d [new file with mode: 0644]

index 3e54d3b..3206edd 100644 (file)
@@ -1161,7 +1161,7 @@ build_struct_literal (tree type, vec <constructor_elt, va_gc> *init)
   if (COMPLEX_FLOAT_TYPE_P (type))
     {
       gcc_assert (vec_safe_length (init) == 2);
-      return build_complex (type, (*init)[0].value, (*init)[1].value);
+      return complex_expr (type, (*init)[0].value, (*init)[1].value);
     }
 
   vec <constructor_elt, va_gc> *ve = NULL;
diff --git a/gcc/testsuite/gdc.dg/pr105004.d b/gcc/testsuite/gdc.dg/pr105004.d
new file mode 100644 (file)
index 0000000..60b3c3f
--- /dev/null
@@ -0,0 +1,14 @@
+// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105004
+// { dg-do compile }
+
+private struct _Complex(T)
+{
+    T re;
+    T im;
+}
+enum __c_complex_float  : _Complex!float;
+
+__c_complex_float pr105004(float re, float im)
+{
+    return typeof(return)(re, im);
+}