Index: gcc/fortran/trans-expr.c =================================================================== *** gcc/fortran/trans-expr.c (revision 117052) --- gcc/fortran/trans-expr.c (working copy) *************** gfc_conv_function_call (gfc_se * se, gfc *** 2029,2035 **** gfc_add_expr_to_block (&se->pre, tmp); } ! if (fsym && fsym->ts.type == BT_CHARACTER && parmse.string_length == NULL_TREE && e->ts.type == BT_PROCEDURE && e->symtree->n.sym->ts.type == BT_CHARACTER --- 2029,2035 ---- gfc_add_expr_to_block (&se->pre, tmp); } ! if (e && fsym && fsym->ts.type == BT_CHARACTER && parmse.string_length == NULL_TREE && e->ts.type == BT_PROCEDURE && e->symtree->n.sym->ts.type == BT_CHARACTER Index: gcc/testsuite/gfortran.dg/optional_assumed_charlen_1.f90 =================================================================== *** gcc/testsuite/gfortran.dg/optional_assumed_charlen_1.f90 (revision 0) --- gcc/testsuite/gfortran.dg/optional_assumed_charlen_1.f90 (revision 0) *************** *** 0 **** --- 1,20 ---- + ! { dg-do compile } + ! Tests the fix for PR29284 in which an ICE would occur in converting + ! the call to a suboutine with an assumed character length, optional + ! dummy that is not present. + ! + ! Contributed by Rakuen Himawari + ! + MODULE foo + CONTAINS + SUBROUTINE sub1(a) + CHARACTER (LEN=*), OPTIONAL :: a + WRITE(*,*) 'foo bar' + END SUBROUTINE sub1 + + SUBROUTINE sub2 + CALL sub1() + END SUBROUTINE sub2 + + END MODULE foo + ! { dg-final { cleanup-modules "foo" } }