]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: several small fixes in gfc_simplify_eoshift [PR124631]
authorHarald Anlauf <anlauf@gmx.de>
Thu, 26 Mar 2026 20:35:11 +0000 (21:35 +0100)
committerHarald Anlauf <anlauf@gmx.de>
Fri, 27 Mar 2026 19:17:41 +0000 (20:17 +0100)
PR fortran/124631

gcc/fortran/ChangeLog:

* simplify.cc (gfc_simplify_eoshift): Initialize sstride[0] to
prevent pointer arithmetic with undefined offset.  Fix several
frontend memleaks.

gcc/fortran/simplify.cc

index c6291d7ea1d47f90d87dea5d1a9f9fadafdb9001..3340a20e227cb6bb54d3052c410be5220878a6c4 100644 (file)
@@ -3004,6 +3004,7 @@ gfc_simplify_eoshift (gfc_expr *array, gfc_expr *shift, gfc_expr *boundary,
   /* Shut up compiler */
   len = 1;
   rsoffset = 1;
+  sstride[0] = 0;
 
   n = 0;
   for (d=0; d < array->rank; d++)
@@ -3073,7 +3074,7 @@ gfc_simplify_eoshift (gfc_expr *array, gfc_expr *shift, gfc_expr *boundary,
        {
          while (n--)
            {
-             *dest = gfc_copy_expr (bnd_ctor->expr);
+             *dest = bnd_ctor->expr;
              dest += rsoffset;
            }
        }
@@ -3081,7 +3082,7 @@ gfc_simplify_eoshift (gfc_expr *array, gfc_expr *shift, gfc_expr *boundary,
        {
          while (n--)
            {
-             *dest = gfc_copy_expr (bnd);
+             *dest = bnd;
              dest += rsoffset;
            }
        }
@@ -3122,6 +3123,9 @@ gfc_simplify_eoshift (gfc_expr *array, gfc_expr *shift, gfc_expr *boundary,
                                   NULL);
     }
 
+  free (arrayvec);
+  free (resultvec);
+
  final:
   if (temp_boundary)
     gfc_free_expr (bnd);