aboutsummaryrefslogtreecommitdiff
path: root/gcc/d/expr.cc
diff options
context:
space:
mode:
authorIain Buclaw <ibuclaw@gdcproject.org>2022-06-29 21:52:39 +0200
committerIain Buclaw <ibuclaw@gdcproject.org>2022-06-29 21:56:28 +0200
commit329bef49da30158d30fed1106002bb71674776bd (patch)
treecc2447cb58fa019894a7af0dfc678cd1333b068e /gcc/d/expr.cc
parent49d508065bdd36fb1a9b6aad9666b1edb5e06474 (diff)
downloadgcc-329bef49da30158d30fed1106002bb71674776bd.zip
gcc-329bef49da30158d30fed1106002bb71674776bd.tar.gz
gcc-329bef49da30158d30fed1106002bb71674776bd.tar.bz2
d: Fix error: aggregate value used where floating point was expected
Casting from vector to static array is permitted, and the frontend generates a reinterpret cast, but casting back the other way resulted in an error. This has been fixed to be properly handled in the code generation pass of VectorExp, and the conversion for lvalue and rvalue handling done in convert_expr and convert_for_rvalue respectively. PR d/106139 gcc/d/ChangeLog: * d-convert.cc (convert_expr): Handle casting from array to vector. (convert_for_rvalue): Rewrite vector to array casts of the same element type into a constructor. (convert_for_assignment): Return calling convert_for_rvalue. * expr.cc (ExprVisitor::visit (VectorExp *)): Handle generating a vector expression from a static array. * toir.cc (IRVisitor::visit (ReturnStatement *)): Call convert_for_rvalue on return value. gcc/testsuite/ChangeLog: * gdc.dg/pr106139a.d: New test. * gdc.dg/pr106139b.d: New test. * gdc.dg/pr106139c.d: New test. * gdc.dg/pr106139d.d: New test.
Diffstat (limited to 'gcc/d/expr.cc')
-rw-r--r--gcc/d/expr.cc10
1 files changed, 8 insertions, 2 deletions
diff --git a/gcc/d/expr.cc b/gcc/d/expr.cc
index 34b3ddd..1bb10a8 100644
--- a/gcc/d/expr.cc
+++ b/gcc/d/expr.cc
@@ -2917,14 +2917,13 @@ public:
void visit (VectorExp *e) final override
{
- tree type = build_ctype (e->type);
-
/* First handle array literal expressions. */
if (e->e1->op == EXP::arrayLiteral)
{
ArrayLiteralExp *ale = e->e1->isArrayLiteralExp ();
vec <constructor_elt, va_gc> *elms = NULL;
bool constant_p = true;
+ tree type = build_ctype (e->type);
vec_safe_reserve (elms, ale->elements->length);
for (size_t i = 0; i < ale->elements->length; i++)
@@ -2944,9 +2943,16 @@ public:
else
this->result_ = build_constructor (type, elms);
}
+ else if (e->e1->type->toBasetype ()->ty == TY::Tsarray)
+ {
+ /* Build a vector representation from a static array. */
+ this->result_ = convert_expr (build_expr (e->e1, this->constp_),
+ e->e1->type, e->type);
+ }
else
{
/* Build constructor from single value. */
+ tree type = build_ctype (e->type);
tree value = d_convert (TREE_TYPE (type),
build_expr (e->e1, this->constp_, true));
this->result_ = build_vector_from_val (type, value);