Debian Codegraph @

gcc/testsuite/gfortran.dg/ISO_Fortran_binding_12.f90

raw
1 ! { dg-do run { target c99_runtime } }
2 ! { dg-additional-sources ISO_Fortran_binding_12.c }
3 !
4 ! Test the fix for PR90093. The additional source is the main program.
5 !
6 ! Contributed by Reinhold Bader <[email protected]>
7 !
8 module mod_optional
9 use, intrinsic :: iso_c_binding
10 implicit none
11 integer :: status = 0
12
13 contains
14
15 subroutine foo_opt(this, that, sz, flag) bind(c)
16 real(c_float), optional :: this(:)
17 real(c_float), optional :: that(*)
18 integer(c_int), optional :: sz
19 integer(c_int), value :: flag
20 if (flag == 0) then
21 if (.not. present(this) .or. present(that) .or. present(sz)) then
22 write(*,*) 'FAIL 1', present(this), present(that), present(sz)
23 status = status + 1
24 end if
25 else if (flag == 1) then
26 if (present(this) .or. .not. present(that) .or. .not. present(sz)) then
27 write(*,*) 'FAIL 2', present(this), present(that), present(sz)
28 status = status + 1
29 end if
30 if (sz /= 12) then
31 write(*,*) 'FAIL 3'
32 status = status + 1
33 end if
34 else if (flag == 2) then
35 if (present(this) .or. present(that) .or. present(sz)) then
36 write(*,*) 'FAIL 4', present(this), present(that), present(sz)
37 status = status + 1
38 end if
39 end if
40 end subroutine foo_opt
41
42 subroutine write_res() BIND(C)
43 ! Add a check that the fortran missing optional is accepted by the
44 ! bind(C) procedure.
45 call foo_opt (flag = 2)
46 if (status == 0) then
47 write(*,*) 'OK'
48 else
49 stop 1
50 end if
51 end subroutine
52
53 end module mod_optional