]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
a68: fix trimmers with implicit lower and upper bounds
authorJose E. Marchesi <jemarch@gnu.org>
Sun, 22 Feb 2026 00:49:32 +0000 (01:49 +0100)
committerJose E. Marchesi <jemarch@gnu.org>
Sun, 22 Feb 2026 00:51:42 +0000 (01:51 +0100)
Signed-off-by: Jose E. Marchesi <jemarch@gnu.org>
gcc/algol68/ChangeLog

* a68-low-units.cc (lower_subscript_for_trimmers): Do not crash
with trimmers with implicit lower and upper bounds.

gcc/testsuite/ChangeLog

* algol68/execute/trimmer-11.a68: New test.

gcc/algol68/a68-low-units.cc
gcc/testsuite/algol68/execute/trimmer-11.a68 [new file with mode: 0644]

index e9660d750dd6f7d1bc60f28aba4fe4868adef56f..cc1fd15fccad81973bdcc0d587bf2b63ad8bcbb5 100644 (file)
@@ -552,22 +552,25 @@ lower_subscript_for_trimmers (NODE_T *p, LOW_CTX_T ctx,
                  {
                    /* Lower bound is implicit.  */
                    FORWARD (q);
-                   if (IS (q, AT_SYMBOL))
-                     {
-                       /* Upper bound is implicit, AT specified.  */
-                       gcc_assert (IS (q, AT_SYMBOL));
-                       at = save_expr (fold_convert (ssizetype, a68_lower_tree (NEXT (q), ctx)));
-                     }
-                   else
+                   if (q != NO_NODE)
                      {
-                       upper_bound
-                         = save_expr (fold_convert (ssizetype, a68_lower_tree (q, ctx)));
-                       FORWARD (q);
-                       if (q != NO_NODE)
+                       if (IS (q, AT_SYMBOL))
                          {
+                           /* Upper bound is implicit, AT specified.  */
                            gcc_assert (IS (q, AT_SYMBOL));
                            at = save_expr (fold_convert (ssizetype, a68_lower_tree (NEXT (q), ctx)));
                          }
+                       else
+                         {
+                           upper_bound
+                             = save_expr (fold_convert (ssizetype, a68_lower_tree (q, ctx)));
+                           FORWARD (q);
+                           if (q != NO_NODE)
+                             {
+                               gcc_assert (IS (q, AT_SYMBOL));
+                               at = save_expr (fold_convert (ssizetype, a68_lower_tree (NEXT (q), ctx)));
+                             }
+                         }
                      }
                  }
                else
diff --git a/gcc/testsuite/algol68/execute/trimmer-11.a68 b/gcc/testsuite/algol68/execute/trimmer-11.a68
new file mode 100644 (file)
index 0000000..0d989d7
--- /dev/null
@@ -0,0 +1,14 @@
+begin [,]int aa = ((1,2,3),
+                   (4,5,6),
+                   (7,8,9));
+      [,]int bb = aa[2:,:];
+
+      assert(1 ELEMS bb = 2);
+      assert(2 ELEMS bb = 3);
+      assert(bb[1,1] = 4);
+      assert(bb[1,2] = 5);
+      assert(bb[1,3] = 6);
+      assert(bb[2,1] = 7);
+      assert(bb[2,2] = 8);
+      assert(bb[2,3] = 9)
+end