public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-8688] d: Fix internal compiler error: Segmentation fault at gimple-expr.cc:88
@ 2022-08-15 20:34 Iain Buclaw
0 siblings, 0 replies; only message in thread
From: Iain Buclaw @ 2022-08-15 20:34 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:dc230a0c690794cd45cc4065fa13303fd6cdfc40
commit r12-8688-gdc230a0c690794cd45cc4065fa13303fd6cdfc40
Author: Iain Buclaw <ibuclaw@gdcproject.org>
Date: Mon Aug 15 17:51:03 2022 +0200
d: Fix internal compiler error: Segmentation fault at gimple-expr.cc:88
Because complex types are deprecated in the language, the new way to
expose native complex types is by defining an enum with a basetype of a
library-defined struct that is implicitly treated as-if it is native.
As casts are not implicitly added by the front-end when downcasting from
enum to its underlying type, we must insert an explicit cast during the
code generation pass.
PR d/106623
gcc/d/ChangeLog:
* d-codegen.cc (underlying_complex_expr): New function.
(d_build_call): Handle passing native complex objects as the
library-defined equivalent.
* d-tree.h (underlying_complex_expr): Declare.
* expr.cc (ExprVisitor::visit (DotVarExp *)): Call
underlying_complex_expr instead of build_vconvert.
gcc/testsuite/ChangeLog:
* gdc.dg/torture/pr106623.d: New test.
(cherry picked from commit e206fecaac29f559f4990312b875604eb1ce3ef3)
Diff:
---
gcc/d/d-codegen.cc | 34 +++++++++++++++++++++++++++++++++
gcc/d/d-tree.h | 1 +
gcc/d/expr.cc | 2 +-
gcc/testsuite/gdc.dg/torture/pr106623.d | 28 +++++++++++++++++++++++++++
4 files changed, 64 insertions(+), 1 deletion(-)
diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc
index 22090a8c755..0f2110ec7c1 100644
--- a/gcc/d/d-codegen.cc
+++ b/gcc/d/d-codegen.cc
@@ -1578,6 +1578,32 @@ complex_expr (tree type, tree re, tree im)
type, re, im);
}
+/* Build a two-field record TYPE representing the complex expression EXPR. */
+
+tree
+underlying_complex_expr (tree type, tree expr)
+{
+ gcc_assert (list_length (TYPE_FIELDS (type)) == 2);
+
+ expr = d_save_expr (expr);
+
+ /* Build a constructor from the real and imaginary parts. */
+ if (COMPLEX_FLOAT_TYPE_P (TREE_TYPE (expr)) &&
+ (!INDIRECT_REF_P (expr)
+ || !CONVERT_EXPR_CODE_P (TREE_CODE (TREE_OPERAND (expr, 0)))))
+ {
+ vec <constructor_elt, va_gc> *ve = NULL;
+ CONSTRUCTOR_APPEND_ELT (ve, TYPE_FIELDS (type),
+ real_part (expr));
+ CONSTRUCTOR_APPEND_ELT (ve, TREE_CHAIN (TYPE_FIELDS (type)),
+ imaginary_part (expr));
+ return build_constructor (type, ve);
+ }
+
+ /* Replace type in the reinterpret cast with a cast to the record type. */
+ return build_vconvert (type, expr);
+}
+
/* Cast EXP (which should be a pointer) to TYPE* and then indirect.
The back-end requires this cast in many cases. */
@@ -2204,6 +2230,14 @@ d_build_call (TypeFunction *tf, tree callable, tree object,
build_address (targ));
}
+ /* Complex types are exposed as special types with an underlying
+ struct representation, if we are passing the native type to a
+ function that accepts the library-defined version, then ensure
+ it is properly reinterpreted as the underlying struct type. */
+ if (COMPLEX_FLOAT_TYPE_P (TREE_TYPE (targ))
+ && arg->type->isTypeStruct ())
+ targ = underlying_complex_expr (build_ctype (arg->type), targ);
+
/* Type `noreturn` is a terminator, as no other arguments can possibly
be evaluated after it. */
if (TREE_TYPE (targ) == noreturn_type_node)
diff --git a/gcc/d/d-tree.h b/gcc/d/d-tree.h
index 5f6b9d61001..ec2b1b65729 100644
--- a/gcc/d/d-tree.h
+++ b/gcc/d/d-tree.h
@@ -564,6 +564,7 @@ extern tree size_mult_expr (tree, tree);
extern tree real_part (tree);
extern tree imaginary_part (tree);
extern tree complex_expr (tree, tree, tree);
+extern tree underlying_complex_expr (tree, tree);
extern tree indirect_ref (tree, tree);
extern tree build_deref (tree);
extern tree build_array_index (tree, tree);
diff --git a/gcc/d/expr.cc b/gcc/d/expr.cc
index 6fba382f0ed..6654244292e 100644
--- a/gcc/d/expr.cc
+++ b/gcc/d/expr.cc
@@ -1911,7 +1911,7 @@ public:
underlying is really a complex type. */
if (e->e1->type->ty == TY::Tenum
&& e->e1->type->isTypeEnum ()->sym->isSpecial ())
- object = build_vconvert (build_ctype (tb), object);
+ object = underlying_complex_expr (build_ctype (tb), object);
this->result_ = component_ref (object, get_symbol_decl (vd));
}
diff --git a/gcc/testsuite/gdc.dg/torture/pr106623.d b/gcc/testsuite/gdc.dg/torture/pr106623.d
new file mode 100644
index 00000000000..d782b236861
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/torture/pr106623.d
@@ -0,0 +1,28 @@
+// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106623
+// { dg-do compile }
+private struct _Complex(T) { T re; T im; }
+enum __c_complex_double : _Complex!double;
+
+pragma(inline, true)
+ulong hashOf()(scope const double val)
+{
+ return *cast(ulong*)&val;
+}
+
+pragma(inline, true)
+ulong hashOf()(scope const _Complex!double val, ulong seed = 0)
+{
+ return hashOf(val.re) + hashOf(val.im);
+}
+
+pragma(inline, true)
+ulong hashOf()(__c_complex_double val, ulong seed = 0)
+{
+ return hashOf(cast(_Complex!double) val, seed);
+}
+
+ulong test106623()
+{
+ __c_complex_double val;
+ return hashOf(val);
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-08-15 20:34 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-15 20:34 [gcc r12-8688] d: Fix internal compiler error: Segmentation fault at gimple-expr.cc:88 Iain Buclaw
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).