d: Fix OutOfMemoryError thrown when appending to an array with a side effect
authorIain Buclaw <ibuclaw@gdcproject.org>
Sun, 22 Nov 2020 13:29:54 +0000 (14:29 +0100)
committerIain Buclaw <ibuclaw@gdcproject.org>
Sun, 22 Nov 2020 18:39:26 +0000 (19:39 +0100)
commit23045f8b062e20672f5170fc66532de7a5d9a1d6
tree1e2a2b9df94c72efa445409d083af872edc578df
parentc1fb592f2c3c6b5a6616cf882ce24d30e167a646
d: Fix OutOfMemoryError thrown when appending to an array with a side effect

When appending a character to an array, the result of that concat
assignment was not the new value of the array, similarly, when appending
an array to another array, side effects were evaluated in reverse to the
expected order of evaluation.

As of this change, the address of the left-hand side expression is
saved and re-used as the result.  Its evaluation is now also forced to
occur before the concat operation itself is called.

gcc/d/ChangeLog:

PR d/97889
* expr.cc (ExprVisitor::visit (CatAssignExp *)): Enforce LTR order of
evaluation on left and right hand side expressions.

gcc/testsuite/ChangeLog:

PR d/97889
* gdc.dg/torture/pr97889.d: New test.
gcc/d/expr.cc
gcc/testsuite/gdc.dg/torture/pr97889.d [new file with mode: 0644]