Fortran: fix memleak for character,value dummy of bind(c) procedure [PR110360]

Testcase gfortran.dg/bind_c_usage_13.f03 exhibited a memleak in the frontend
occuring when passing a character literal to a character,value dummy of a
bind(c) procedure, due to a missing cleanup in the conversion of the actual
argument expression.  Reduced testcase:

  program p
    interface
       subroutine val_c (c) bind(c)
         use iso_c_binding, only: c_char
         character(len=1,kind=c_char), value :: c
       end subroutine val_c
    end interface
    call val_c ("A")
  end

gcc/fortran/ChangeLog:

	PR fortran/110360
	* trans-expr.cc (conv_scalar_char_value): Use gfc_replace_expr to
	avoid leaking replaced gfc_expr.
This commit is contained in:
Harald Anlauf 2023-08-16 22:00:49 +02:00
parent 4a2b262597
commit 9ade70bb86

View file

@ -4044,8 +4044,9 @@ conv_scalar_char_value (gfc_symbol *sym, gfc_se *se, gfc_expr **expr)
gfc_typespec ts;
gfc_clear_ts (&ts);
*expr = gfc_get_int_expr (gfc_default_character_kind, NULL,
(*expr)->value.character.string[0]);
gfc_expr *tmp = gfc_get_int_expr (gfc_default_character_kind, NULL,
(*expr)->value.character.string[0]);
gfc_replace_expr (*expr, tmp);
}
else if (se != NULL && (*expr)->expr_type == EXPR_VARIABLE)
{