Silverfrost Forums

Welcome to our forums

FTN95 version 8.10 Bug with function argument

9 Mar 2017 8:53 #19018

In the following code a function is passed to subroutine foo, which then passes it to function foo2 (where it is used). When compiled with /checkmate you get a run-time saying that the second argument of the call to foo is not a procedure. This is the bug.

If the call to foo2 is removed, the program runs OK.

This bug has appeared since version 8.10; previously it worked in 8.05 and in earlier versions.

Note: I have only tried using the 32 bit compiler.

module kinds
   integer, parameter :: dp=kind(1.0d0)
end module kinds

module mmm

   use kinds, only: dp

   type p_t
      real(dp) :: a
      real(dp) :: b
   end type
   
contains

   function mult(x)
      real(dp) :: mult
      real(dp), intent(in) :: x
      mult = 2.0_dp*x
   end function mult

   subroutine foo(p, func)
   
      type(p_t), intent(in) :: p
      interface
         function func(x)
            use kinds, only: dp
            real(dp) :: func
            real(dp), intent(in) :: x
         end function func
      end interface
      
      print *, foo2(func, 1.0_dp)
      
      ! If you replace the above line with this one it runs
      !print *, func(1.0_dp)
      
      print *, p%a, p%b
      
   end subroutine foo
   
   function foo2(func, x)
      real(dp) :: foo2
      real(dp), intent(in) :: x
      interface
         function func(x)
            use kinds, only: dp
            real(dp) :: func
            real(dp), intent(in) :: x
         end function func
      end interface
      
      foo2 = func(x)
      
   end function foo2
   
end module mmm

program test

   use mmm
   type(p_t) :: p
   
   p%a = 0.0_dp
   p%b = 1.0_dp
   
   call foo(p, mult)
   
end program test

Regards, David.

9 Mar 2017 11:54 #19022

Curiously, I see the bug even with 8.05-32 bit when I use /check or /checkmate. I wonder if you and I see different behaviour because our Salflibc.dll versions are different -- I did install the updated Salflibc.dll when Paul L. posted them on Dropbox.

9 Mar 2017 9:00 #19027

Quoted from mecej4 Curiously, I see the bug even with 8.05-32 bit when I use /check or /checkmate. I wonder if you and I see different behaviour because our Salflibc.dll versions are different -- I did install the updated Salflibc.dll when Paul L. posted them on Dropbox.

I had been running 8.05 and had included updates to 8.05 supplied by Paul on two separate occasions. First he provided on this forum a link to salflibc.dll (modified 16/07/2016 08:20). Then he provided a further updated salflibc.dll (modified 05/09/2016 09:10). I got the modification times by right clicking, then properties on the dll file.

As far as I recall, my 'real' code with the above features worked correctly with all versions of 8.05 as I successively applied these updates. However, I don't know if my 'test' code above worked because I have only just written it. I will have to revert back to 8.05 until this is fixed, so I can go through the successive updates and check again.

Meanwhile, it would help me if you could confirm the above details about the different versions, if you have saved them somewhere.

10 Mar 2017 2:19 #19030

The version of salflibc.dll that I have in the 8.05 directory has a modification date of 28 Oct. 2016, and a creation date of 13 July 2016.

That version did not allow /check with /64. The bug can be seen with 8.1 and /64 /check.

10 Mar 2017 7:32 #19032

Well it turns out to be a bit more complicated. I successively re-installed version 7.2, then 8.05, then each of the DLL updates I have (I could not find the one you have used mecej4).

I found my 'real' code worked fine with all of these, but my 'test' code posted above failed with the run-time error. Only version 8.10 fails for both my test code and my real code:

Version   salflibc.dll   test code    real code
7.2        16/03/2015    failed        ok
8.05       17/06/2016    failed        ok
8.05       16/07/2016    failed        ok
8.05       05/09/2016    failed        ok
8.05       28/10/2016    failed                           <- mecej4's version
8.10                     failed        failed

This means that, while the code above illustrates a bug in 8.1, the same bug probably has been present since 7.2. It also means my test program isn't good enough. I will see if I can post some code later that is closer to my real code, as this may help Paul to track this bug down.

I was hoping to purchase 8.10 but will I have to hold off until this is fixed.

10 Mar 2017 8:07 #19033

I have made a note of this.

10 Mar 2017 4:29 #19046

When I change the test code so there is an additional argument 'i' after the procedure argument (see below), the code works in versions 7.2, 8.05 [u:7d210975ce]but fails[/u:7d210975ce] in version 8.10.

This is now the same behavior as my 'real' code across all versions:

Version   salflibc.dll   new test code   real code
7.2        16/03/2015    ok              ok
8.05       17/06/2016    ok              ok
8.05       16/07/2016    ok              ok
8.05       05/09/2016    ok              ok
8.05       28/10/2016    ok                           <- mecej4's version
8.10                     failed           failed

Perhaps mecej4's would kindly confirm the result for his row.

The new test code is

module kinds 
    integer, parameter :: dp=kind(1.0d0) 
 end module kinds 

 module mmm 

    use kinds, only: dp 

    type p_t 
       real(dp) :: a 
       real(dp) :: b 
    end type 
     
 contains 

    function mult(x, i) 
       real(dp) :: mult 
       real(dp), intent(in) :: x 
       integer, intent(in) :: i(:)
       mult = 2.0_dp*x 
    end function mult 

    subroutine foo(p, func, i) 
     
       type(p_t), intent(in) :: p 
       integer, intent(in) :: i(:)
       interface 
          function func(x, i) 
             use kinds, only: dp
             real(dp) :: func 
             real(dp), intent(in) :: x 
             integer, intent(in) :: i(:)
          end function func 
       end interface 
       
       print *, foo2(1.0_dp, func, i) 
       
       ! If you replace the above line with this one it runs 
       !print *, func(1.0_dp, i) 
       
       print *, p%a, p%b 
       
    end subroutine foo 

    function foo2(x, func, i) 
       real(dp) :: foo2 
       real(dp), intent(in) :: x 
       integer, intent(in) :: i(:)
       interface 
          function func(x, i) 
             use kinds, only: dp 
             real(dp) :: func 
             real(dp), intent(in) :: x 
             integer, intent(in) :: i(:)
          end function func 
       end interface 
       
       foo2 = func(x, i) 
       
    end function foo2

 end module mmm 

 program test 

    use mmm 
    type(p_t) :: p 
    integer :: i(1)
     
    p%a = 0.0_dp 
    p%b = 1.0_dp 
     
    call foo(p, mult, i) 
     
 end program test 

Paul, when debugging this is it important to check both test programs work with 8.10 because there may be two bugs here.

10 Mar 2017 6:15 #19048

DavidB,

I can confirm that your new test code works with /check on 8.05 with my DLL version, and fails with 8.10.

By the way, the strange modification date may be the result of an event that I vaguely remember. My antivirus program deleted salflibc.dll for some reason, but placed a copy in quarantine. I had to rescue the file from that location. The file is 2,273,280 bytes long.

21 Mar 2017 2:17 #19198

This has now been fixed in FTN95 for the next release.

21 Mar 2017 5:59 #19199

Thanks very much Paul. Did you check both test codes?

22 Mar 2017 6:42 #19201

Both programs now run OK.

Please login to reply.