Fortran: ICE with elemental and dummy argument with VALUE attribute [PR107819]

gcc/fortran/ChangeLog:

	PR fortran/107819
	* trans-stmt.cc (gfc_conv_elemental_dependencies): In checking for
	elemental dependencies, treat dummy argument with VALUE attribute
	as implicitly having intent(in).

gcc/testsuite/ChangeLog:

	PR fortran/107819
	* gfortran.dg/elemental_dependency_7.f90: New test.
This commit is contained in:
Harald Anlauf 2022-11-27 21:10:18 +01:00
parent 2200b70546
commit 07b9bcc1d1
2 changed files with 29 additions and 0 deletions

View file

@ -264,6 +264,7 @@ gfc_conv_elemental_dependencies (gfc_se * se, gfc_se * loopse,
if (e->expr_type == EXPR_VARIABLE
&& e->rank && fsym
&& fsym->attr.intent != INTENT_IN
&& !fsym->attr.value
&& gfc_check_fncall_dependency (e, fsym->attr.intent,
sym, arg0, check_variable))
{

View file

@ -0,0 +1,28 @@
! { dg-do run }
! PR fortran/107819 - ICE in gfc_check_argument_var_dependency
! Contributed by G.Steinmetz
!
! Note: the testcase is considered non-conforming for m>1 due to aliasing
program p
implicit none
integer, parameter :: m = 1
integer :: i
integer :: a(m) = [(-i,i=1,m)]
integer :: n(m) = [(i,i=m,1,-1)]
integer :: b(m)
b = a
call s (a(n), a) ! { dg-warning "might interfere with actual argument" }
! Compare to separate application of subroutine in element order
do i = 1, size (b)
call s (b(n(i)), b(i))
end do
if (any (a /= b)) stop 1
contains
elemental subroutine s (x, y)
integer, value :: x
integer, intent(out) :: y
y = x
end
end