diff options
author | Iain Buclaw <ibuclaw@gdcproject.org> | 2020-07-18 17:14:54 +0200 |
---|---|---|
committer | Iain Buclaw <ibuclaw@gdcproject.org> | 2020-07-30 23:44:31 +0200 |
commit | 7508a7e958ea06eb311a4a106312634eaf6d40c3 (patch) | |
tree | c3d3f96bb65452d64418a4f759a902275f7141f1 /gcc/d/expr.cc | |
parent | 873b45d39c14fee6b68032b83ea6bfbc023e3379 (diff) | |
download | gcc-7508a7e958ea06eb311a4a106312634eaf6d40c3.zip gcc-7508a7e958ea06eb311a4a106312634eaf6d40c3.tar.gz gcc-7508a7e958ea06eb311a4a106312634eaf6d40c3.tar.bz2 |
d: Fix associative array literals that don't have alignment holes filled
Associative array literal keys with alignment holes are now filled using
memset() prior to usage, with LTR evaluation of side-effects enforced.
gcc/d/ChangeLog:
PR d/96152
* d-codegen.cc (build_array_from_exprs): New function.
* d-tree.h (build_array_from_exprs): Declare.
* expr.cc (ExprVisitor::visit (AssocArrayLiteralExp *)): Use
build_array_from_exprs to generate key and value arrays.
gcc/testsuite/ChangeLog:
PR d/96152
* gdc.dg/pr96152.d: New test.
Diffstat (limited to 'gcc/d/expr.cc')
-rw-r--r-- | gcc/d/expr.cc | 33 |
1 files changed, 9 insertions, 24 deletions
diff --git a/gcc/d/expr.cc b/gcc/d/expr.cc index 355561a..20ab49d 100644 --- a/gcc/d/expr.cc +++ b/gcc/d/expr.cc @@ -2799,30 +2799,14 @@ public: /* Build an expression that assigns all expressions in KEYS to a constructor. */ - vec <constructor_elt, va_gc> *kelts = NULL; - vec_safe_reserve (kelts, e->keys->length); - for (size_t i = 0; i < e->keys->length; i++) - { - Expression *key = (*e->keys)[i]; - tree t = build_expr (key); - CONSTRUCTOR_APPEND_ELT (kelts, size_int (i), - convert_expr (t, key->type, ta->index)); - } - tree tkeys = make_array_type (ta->index, e->keys->length); - tree akeys = build_constructor (tkeys, kelts); + tree akeys = build_array_from_exprs (ta->index->sarrayOf (e->keys->length), + e->keys, this->constp_); + tree init = stabilize_expr (&akeys); /* Do the same with all expressions in VALUES. */ - vec <constructor_elt, va_gc> *velts = NULL; - vec_safe_reserve (velts, e->values->length); - for (size_t i = 0; i < e->values->length; i++) - { - Expression *value = (*e->values)[i]; - tree t = build_expr (value); - CONSTRUCTOR_APPEND_ELT (velts, size_int (i), - convert_expr (t, value->type, ta->next)); - } - tree tvals = make_array_type (ta->next, e->values->length); - tree avals = build_constructor (tvals, velts); + tree avals = build_array_from_exprs (ta->next->sarrayOf (e->values->length), + e->values, this->constp_); + init = compound_expr (init, stabilize_expr (&avals)); /* Generate: _d_assocarrayliteralTX (ti, keys, vals); */ tree keys = d_array_value (build_ctype (ta->index->arrayOf ()), @@ -2840,8 +2824,9 @@ public: vec <constructor_elt, va_gc> *ce = NULL; CONSTRUCTOR_APPEND_ELT (ce, TYPE_FIELDS (aatype), mem); - this->result_ = build_nop (build_ctype (e->type), - build_constructor (aatype, ce)); + tree result = build_nop (build_ctype (e->type), + build_constructor (aatype, ce)); + this->result_ = compound_expr (init, result); } /* Build a struct literal. */ |