From: Rico Tzschichholz Date: Tue, 14 Jan 2020 07:36:26 +0000 (+0100) Subject: codegen: Use result value of assignment rather than its computation X-Git-Tag: 0.47.3~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8dd348ce50260c37fb103f21c5956b7ce63cc2f0;p=thirdparty%2Fvala.git codegen: Use result value of assignment rather than its computation An inline assignment of an array-length, like int j = --i.length; resulted in a faulty tranformation i_length1 = i_length1 - 1; j = i_length1 - 1; Regression of 80d4bf61e0c3100c839f3fdbcb5218996b6afd5f Fixes https://gitlab.gnome.org/GNOME/vala/issues/895 --- diff --git a/codegen/valaccodeassignmentmodule.vala b/codegen/valaccodeassignmentmodule.vala index 617293b0a..fc7e8d6fc 100644 --- a/codegen/valaccodeassignmentmodule.vala +++ b/codegen/valaccodeassignmentmodule.vala @@ -83,7 +83,7 @@ public class Vala.CCodeAssignmentModule : CCodeMemberAccessModule { if (assignment.left.value_type is ArrayType && (((ArrayType) assignment.left.value_type).inline_allocated)) { return load_variable (variable, assignment.left.target_value); } else { - return assignment.right.target_value; + return assignment.left.target_value; } } diff --git a/tests/Makefile.am b/tests/Makefile.am index 0d4968e75..f7c520de8 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -78,6 +78,7 @@ TESTS = \ arrays/fixed-length-concat-invalid.test \ arrays/fixed-length-non-const.test \ arrays/fixed-length-resize-invalid.test \ + arrays/length-inline-assignment.vala \ arrays/struct-field-length-cname.vala \ arrays/incompatible-integer-elements.test \ arrays/slice-invalid-start.test \ diff --git a/tests/arrays/length-inline-assignment.vala b/tests/arrays/length-inline-assignment.vala new file mode 100644 index 000000000..baf33055d --- /dev/null +++ b/tests/arrays/length-inline-assignment.vala @@ -0,0 +1,29 @@ +void main () { + { + int[] i = { 23, 42 }; + int j = --i.length; + assert (i.length == 1); + assert (j == 1); + j = ++i.length; + assert (i.length == 2); + assert (j == 2); + } + { + int[] i = { 23, 42 }; + int j = (i.length = i.length - 1); + assert (i.length == 1); + assert (j == 1); + j = (i.length = i.length + 1); + assert (i.length == 2); + assert (j == 2); + } + { + int[] i = { 23, 42 }; + int j = i.length--; + assert (i.length == 1); + assert (j == 2); + j = i.length++; + assert (i.length == 2); + assert (j == 1); + } +}