[gcc r16-8308] Fortran: several small fixes in gfc_simplify_eoshift [PR124631]

Harald Anlauf anlauf@gcc.gnu.org
Fri Mar 27 19:49:04 GMT 2026


https://gcc.gnu.org/g:73933cdc44dea4b1bd5e1a2ef04d1df6edeb27c6

commit r16-8308-g73933cdc44dea4b1bd5e1a2ef04d1df6edeb27c6
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Thu Mar 26 21:35:11 2026 +0100

    Fortran: several small fixes in gfc_simplify_eoshift [PR124631]
    
            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.

Diff:
---
 gcc/fortran/simplify.cc | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/gcc/fortran/simplify.cc b/gcc/fortran/simplify.cc
index c6291d7ea1d4..3340a20e227c 100644
--- a/gcc/fortran/simplify.cc
+++ b/gcc/fortran/simplify.cc
@@ -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);


More information about the Gcc-cvs mailing list