Fortran: avoid NULL pointer dereference checking elemental procedure args

gcc/fortran/ChangeLog:

	PR fortran/104571
	* resolve.cc (resolve_elemental_actual): Avoid NULL pointer
	dereference.

gcc/testsuite/ChangeLog:

	PR fortran/104571
	* gfortran.dg/pr104571.f90: New test.

Co-authored-by: Steven G. Kargl <kargl@gcc.gnu.org>
This commit is contained in:
Harald Anlauf 2022-03-29 22:12:15 +02:00
parent eb59ddf57f
commit 69db6e7f4e
2 changed files with 15 additions and 2 deletions

View file

@ -2397,8 +2397,9 @@ resolve_elemental_actual (gfc_expr *expr, gfc_code *c)
if (rank > 0 && esym && expr == NULL)
for (eformal = esym->formal, arg = arg0; arg && eformal;
arg = arg->next, eformal = eformal->next)
if ((eformal->sym->attr.intent == INTENT_OUT
|| eformal->sym->attr.intent == INTENT_INOUT)
if (eformal->sym
&& (eformal->sym->attr.intent == INTENT_OUT
|| eformal->sym->attr.intent == INTENT_INOUT)
&& arg->expr && arg->expr->rank == 0)
{
gfc_error ("Actual argument at %L for INTENT(%s) dummy %qs of "

View file

@ -0,0 +1,12 @@
! { dg-do compile }
! { dg-options "-std=legacy" }
! PR fortran/104571 - ICE in resolve_elemental_actual
! Contributed by G.Steinmetz
program p
real :: x(3)
call g(x) ! { dg-error "Missing alternate return" }
contains
elemental subroutine g(*) ! { dg-error "Alternate return specifier" }
end
end