It is necessary to consolidate operands of both monadic and dyadic
formulas so that paremeters expecting references will get an address.

Signed-off-by: Jose E. Marchesi <[email protected]>

gcc/algol68/ChangeLog

        * a68-low-units.cc (a68_lower_formula): Consolidate operands of
        formula before call.
        (a68_lower_monadic_formula): Likewise.

gcc/testsuite/ChangeLog

        * algol68/execute/formula-3.a68: New test.
        * algol68/execute/formula-4.a68: Likewise.
        * algol68/execute/formula-5.a68: Likewise.
---
 gcc/algol68/a68-low-units.cc                |  4 ++++
 gcc/testsuite/algol68/execute/formula-3.a68 | 11 +++++++++++
 gcc/testsuite/algol68/execute/formula-4.a68 | 11 +++++++++++
 gcc/testsuite/algol68/execute/formula-5.a68 | 11 +++++++++++
 4 files changed, 37 insertions(+)
 create mode 100644 gcc/testsuite/algol68/execute/formula-3.a68
 create mode 100644 gcc/testsuite/algol68/execute/formula-4.a68
 create mode 100644 gcc/testsuite/algol68/execute/formula-5.a68

diff --git a/gcc/algol68/a68-low-units.cc b/gcc/algol68/a68-low-units.cc
index a0e13c44fcb..f7bfe6f822f 100644
--- a/gcc/algol68/a68-low-units.cc
+++ b/gcc/algol68/a68-low-units.cc
@@ -1017,6 +1017,9 @@ a68_lower_formula (NODE_T *p, LOW_CTX_T ctx)
          tree op = a68_lower_tree (NEXT (SUB (p)), ctx);
          tree arg2 = a68_lower_tree (NEXT (NEXT (SUB (p))), ctx);
 
+         arg1 = a68_consolidate_ref (MOID (SUB (p)), arg1);
+         arg2 = a68_consolidate_ref (MOID (NEXT (NEXT (SUB (p)))), arg2);
+
          if (POINTER_TYPE_P (TREE_TYPE (op)))
            op = fold_build1 (INDIRECT_REF,
                              TREE_TYPE (TREE_TYPE (op)),
@@ -1049,6 +1052,7 @@ a68_lower_monadic_formula (NODE_T *p, LOW_CTX_T ctx)
       tree op = a68_lower_tree (SUB (p), ctx);
       tree secondary = a68_lower_tree (NEXT (SUB (p)), ctx);
 
+      secondary = a68_consolidate_ref (MOID (NEXT (SUB (p))), secondary);
       if (POINTER_TYPE_P (TREE_TYPE (op)))
        op = fold_build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (op)), op);
       return build_call_expr_loc (a68_get_node_location (p), op, 1, secondary);
diff --git a/gcc/testsuite/algol68/execute/formula-3.a68 
b/gcc/testsuite/algol68/execute/formula-3.a68
new file mode 100644
index 00000000000..d60588c3a0a
--- /dev/null
+++ b/gcc/testsuite/algol68/execute/formula-3.a68
@@ -0,0 +1,11 @@
+{ This tests that names are passed properly to dyadic operators. }
+
+begin mode Foo = struct (int i,j);
+      Foo f;
+      i'f := 10;
+      j'f := 20;
+      op +:= = (ref Foo f, int i) int: (i'f +:= i; j'f +:= i; i + 1);
+      assert ((f +:= 1) = 2);
+      assert (i'f = 11);
+      assert (j'f = 21)
+end
diff --git a/gcc/testsuite/algol68/execute/formula-4.a68 
b/gcc/testsuite/algol68/execute/formula-4.a68
new file mode 100644
index 00000000000..37b76110225
--- /dev/null
+++ b/gcc/testsuite/algol68/execute/formula-4.a68
@@ -0,0 +1,11 @@
+{ This tests that names are passed properly to dyadic operators. }
+
+begin mode Foo = struct (int i,j);
+      Foo f;
+      i'f := 10;
+      j'f := 20;
+      op +=: = (int i, ref Foo f) int: (i'f +:= i; j'f +:= i; i + 1);
+      assert ((1 +=: f) = 2);
+      assert (i'f = 11);
+      assert (j'f = 21)
+end
diff --git a/gcc/testsuite/algol68/execute/formula-5.a68 
b/gcc/testsuite/algol68/execute/formula-5.a68
new file mode 100644
index 00000000000..92de98536d8
--- /dev/null
+++ b/gcc/testsuite/algol68/execute/formula-5.a68
@@ -0,0 +1,11 @@
+{ This tests that names are passed properly to monadic operators. }
+
+begin mode Foo = struct (int i,j);
+      Foo f;
+      i'f := 10;
+      j'f := 20;
+      op + = (ref Foo f) int: (i'f +:= 2; j'f +:= 2; i'f + j'f);
+      assert (+f = 34);
+      assert (i'f = 12);
+      assert (j'f = 22)
+end
-- 
2.39.5

Reply via email to