diff options
author | Iain Buclaw <ibuclaw@gdcproject.org> | 2020-11-17 13:11:33 +0100 |
---|---|---|
committer | Iain Buclaw <ibuclaw@gdcproject.org> | 2020-11-18 10:22:18 +0100 |
commit | 798bdfa0ebcf2bd012ffce75a594f783a8cb2dd0 (patch) | |
tree | 46cce232509d2f6ff158cb16d730c099e92cb874 /gcc/d/d-codegen.cc | |
parent | 27d8c3516b67c0f5a8fe8970d0558ee3b97e8281 (diff) | |
download | gcc-798bdfa0ebcf2bd012ffce75a594f783a8cb2dd0.zip gcc-798bdfa0ebcf2bd012ffce75a594f783a8cb2dd0.tar.gz gcc-798bdfa0ebcf2bd012ffce75a594f783a8cb2dd0.tar.bz2 |
d: Fix LHS of array concatentation evaluated before the RHS.
In an array append expression:
array ~= fun(array);
The array in the left hand side of the expression was extended before
evaluating the result of the right hand side, which resulted in the
newly uninitialized array index being used before set.
This fixes that so that the result of the right hand side is always
saved in a reusable temporary before assigning to the destination.
gcc/d/ChangeLog:
PR d/97843
* d-codegen.cc (build_assign): Evaluate TARGET_EXPR before use in
the right hand side of an assignment.
* expr.cc (ExprVisitor::visit (CatAssignExp *)): Force a TARGET_EXPR
on the element to append if it is a CALL_EXPR.
gcc/testsuite/ChangeLog:
PR d/97843
* gdc.dg/torture/pr97843.d: New test.
Diffstat (limited to 'gcc/d/d-codegen.cc')
-rw-r--r-- | gcc/d/d-codegen.cc | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc index 1f2d65c..4c16f6a 100644 --- a/gcc/d/d-codegen.cc +++ b/gcc/d/d-codegen.cc @@ -1343,7 +1343,10 @@ build_assign (tree_code code, tree lhs, tree rhs) since that would cause the LHS to be constructed twice. So we force the TARGET_EXPR to be expanded without a target. */ if (code != INIT_EXPR) - rhs = compound_expr (rhs, TARGET_EXPR_SLOT (rhs)); + { + init = compound_expr (init, rhs); + rhs = TARGET_EXPR_SLOT (rhs); + } else { d_mark_addressable (lhs); |