https://gcc.gnu.org/g:0b00cedee96ec5c9e1542249c77122219fcdacad

commit 0b00cedee96ec5c9e1542249c77122219fcdacad
Author: Mikael Morin <[email protected]>
Date:   Thu Oct 9 13:02:40 2025 +0200

    gimple-simulate: Correction terminaison chaînes de caractères

Diff:
---
 gcc/gimple-simulate.cc | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/gcc/gimple-simulate.cc b/gcc/gimple-simulate.cc
index d980d62ee402..d713009b53ae 100644
--- a/gcc/gimple-simulate.cc
+++ b/gcc/gimple-simulate.cc
@@ -2179,7 +2179,11 @@ simul_scope::evaluate (tree expr) const
        const char *str = TREE_STRING_POINTER (expr);
        for (int i = 0; i < len; ++i)
          set_cst_array_elem_at (result, elt_type, i, str[i]);
-       set_cst_array_elem_at (result, elt_type, len, 0);
+       /* Fortran strings are not 0-terminated.
+          Decide on the 0-termination here depending on the type size.  */
+       if (tree_fits_shwi_p (TYPE_SIZE_UNIT (expr_type))
+           && tree_to_shwi (TYPE_SIZE_UNIT (expr_type)) > len)
+         set_cst_array_elem_at (result, elt_type, len, 0);
        return result;
       }

Reply via email to