aboutsummaryrefslogtreecommitdiff
path: root/gcc/fortran/trans-expr.cc
diff options
context:
space:
mode:
authorHarald Anlauf <anlauf@gmx.de>2025-04-08 22:30:15 +0200
committerHarald Anlauf <anlauf@gmx.de>2025-04-09 17:18:44 +0200
commit334545194d9023fb9b2f72ee0dcde8af94930f25 (patch)
tree82364273fdaa750198a9d29e42c264937909f7de /gcc/fortran/trans-expr.cc
parent4645d092969face6aa1da4c919924697185f9cf9 (diff)
downloadgcc-334545194d9023fb9b2f72ee0dcde8af94930f25.zip
gcc-334545194d9023fb9b2f72ee0dcde8af94930f25.tar.gz
gcc-334545194d9023fb9b2f72ee0dcde8af94930f25.tar.bz2
Fortran: fix issue with impure elemental subroutine and interface [PR119656]
PR fortran/119656 gcc/fortran/ChangeLog: * interface.cc (gfc_compare_actual_formal): Fix front-end memleak when searching for matching interfaces. * trans-expr.cc (gfc_conv_procedure_call): If there is a formal dummy corresponding to an absent argument, use its type, and only fall back to inferred type otherwise. gcc/testsuite/ChangeLog: * gfortran.dg/optional_absent_13.f90: New test.
Diffstat (limited to 'gcc/fortran/trans-expr.cc')
-rw-r--r--gcc/fortran/trans-expr.cc18
1 files changed, 12 insertions, 6 deletions
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 6ece39b..62dd38d 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -6925,10 +6925,18 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym,
{
/* Pass a NULL pointer for an absent arg. */
parmse.expr = null_pointer_node;
+
+ /* Is it an absent character dummy? */
+ bool absent_char = false;
gfc_dummy_arg * const dummy_arg = arg->associated_dummy;
- if (dummy_arg
- && gfc_dummy_arg_get_typespec (*dummy_arg).type
- == BT_CHARACTER)
+
+ /* Fall back to inferred type only if no formal. */
+ if (fsym)
+ absent_char = (fsym->ts.type == BT_CHARACTER);
+ else if (dummy_arg)
+ absent_char = (gfc_dummy_arg_get_typespec (*dummy_arg).type
+ == BT_CHARACTER);
+ if (absent_char)
parmse.string_length = build_int_cst (gfc_charlen_type_node,
0);
}
@@ -6954,9 +6962,7 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym,
|| !CLASS_DATA (fsym)->attr.allocatable));
gfc_init_se (&parmse, NULL);
parmse.expr = null_pointer_node;
- if (arg->associated_dummy
- && gfc_dummy_arg_get_typespec (*arg->associated_dummy).type
- == BT_CHARACTER)
+ if (fsym->ts.type == BT_CHARACTER)
parmse.string_length = build_int_cst (gfc_charlen_type_node, 0);
}
else if (fsym && fsym->ts.type == BT_CLASS