[gcc r16-9337] a68: consolidate refs when lowering formulas

"Jose E. Marchesi via Gcc-cvs" <[email protected]>
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:eb29684af9699be404d2917032cc7d48c548ef55

commit r16-9337-geb29684af9699be404d2917032cc7d48c548ef55
Author: Jose E. Marchesi <[email protected]>
Date:   Sat Jun 13 02:24:48 2026 +0200

    a68: consolidate refs when lowering formulas
    
    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.
    
    (cherry picked from commit 0fa86e1efa879ee1330da7c24f907b59422a3dc3)

Diff:
---
 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(+)

diff --git a/gcc/algol68/a68-low-units.cc b/gcc/algol68/a68-low-units.cc
index a0e13c44fcb9..f7bfe6f822fe 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 000000000000..d60588c3a0ad
--- /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 000000000000..37b76110225b
--- /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 000000000000..92de98536d88
--- /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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.