Dear all, the attached patch fixes a missing initialization found by an UBSAN instrumented compiler. It also plugs several frontend memleaks I found running f951 under valgrind on the testcase in the PR.
Regtested on x86_64-pc-linux-gnu. No new testcase needed. OK for mainline? Thanks, Harald
From 03210ffb6aaa0e2169cfeaa244fa1a28b1360f60 Mon Sep 17 00:00:00 2001 From: Harald Anlauf <[email protected]> Date: Thu, 26 Mar 2026 21:35:11 +0100 Subject: [PATCH] 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. --- 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 c6291d7ea1d..3340a20e227 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); -- 2.51.0
