Hi Paul,
The patch looks fine to me but I have two questions:
(i) Why is this not done in resolve.c?
Of course it doesn't matter where the function resides :-) I put it
into frontend-passes.c because it makes heavy use of gfc_code_walker,
and out of habit. If you prefer, I can of course move the code to
resolve.c.
If your question is more like "why is that not done during
normal resolution" - while fixing this bug, I began to understand
why the standard has an explicit PURE attribute. If the compiler
is chasing after a procedure which may or may not be implicit_pure, then
everything else needs to have been resolved beforehand. And in normal
resolution, something needs to be the last.
(ii) Is Martin's reduced reproducer not the basis for a testcase?
There, git got the better of me. I thought it was included in the
patch, but, as I reread it and found that this wasn't the case.
I have attache the test case now.
OK for trunk and backport once gcc 10 is open again?
Regards
Thomas
#include <stdio.h>
extern int num_calls;
int side_effect_c()
{
num_calls ++;
}
! { dg-do run }
! { dg-additional-sources implicit_pure_5.c }
! PR fortran/96018 - a wrongly marked implicit_pure
! function caused wrong code.
module wrapper
use, intrinsic :: iso_c_binding, only : c_int
implicit none
integer(kind=c_int), bind(C) :: num_calls
contains
integer function call_side_effect() result(ierr)
call side_effect(ierr)
end function call_side_effect
integer function inner_3d(array) result(ierr)
real, intent(in) :: array(:,:,:)
integer dimensions(3)
dimensions = shape(array)
ierr = call_side_effect()
end function inner_3d
integer function inner_4d(array) result(ierr)
real, intent(in) :: array(:,:,:,:)
integer dimensions(4)
dimensions = shape(array)
ierr = call_side_effect()
end function inner_4d
subroutine write_3d()
real :: array(1,1,1)
integer ierr
ierr = inner_3d(array)
ierr = call_side_effect()
end subroutine write_3d
subroutine write_4d()
real array(1,1,1,1)
integer ierr
ierr = inner_4d(array)
ierr = call_side_effect()
end subroutine write_4d
subroutine side_effect(ierr)
integer, intent(out) :: ierr ! Error code
interface
integer(c_int) function side_effect_c() bind(C,name='side_effect_c')
use, intrinsic :: iso_c_binding, only: c_int
end function side_effect_c
end interface
ierr = side_effect_c()
end subroutine side_effect
end module wrapper
program self_contained
use wrapper
implicit none
call write_3d()
if (num_calls /= 2) stop 1
call write_4d()
if (num_calls /= 4) stop 2
end program self_contained