File: bind-c-intent-out.f90

package info (click to toggle)
gcc-arm-none-eabi 15%3A14.2.rel1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,099,328 kB
  • sloc: cpp: 3,627,108; ansic: 2,571,498; ada: 834,230; f90: 235,082; makefile: 79,231; asm: 74,984; xml: 51,692; exp: 39,736; sh: 33,298; objc: 15,629; python: 15,069; fortran: 14,429; pascal: 7,003; awk: 5,070; perl: 3,106; ml: 285; lisp: 253; lex: 204; haskell: 135
file content (47 lines) | stat: -rw-r--r-- 1,647 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
! { dg-do run }
! { dg-options "-fdump-tree-original" }
!
! PR fortran/91863
!
! Contributed by G. Steinmetz
!

subroutine sub(x) bind(c)
  implicit none (type, external)
  integer, allocatable, intent(out) :: x(:)

  allocate(x(3:5))
  x(:) = [1, 2, 3]
end subroutine sub


program p
  implicit none (type, external)
  interface
    subroutine sub(x) bind(c)
      integer, allocatable, intent(out) :: x(:)
    end
  end interface
  integer, allocatable :: a(:)

  call sub(a)
  if (.not.allocated(a)) stop 1
  if (any(shape(a) /= [3])) stop 2
  if (lbound(a,1) /= 3 .or. ubound(a,1) /= 5) stop 3
  print *, a(0), a(1), a(2), a(3), a(4)
  print *, a
  if (any(a /= [1, 2, 3])) stop 4
end program p

! "cfi" only appears in context of "a" -> bind-C descriptor
! the intent(out) implies freeing in the callee (!) (when implemented in Fortran), hence the "free"
! and also in the caller (when implemented in Fortran)
! It is the only 'free' as 'a' is part of the main program and, hence, implicitly has the SAVE attribute.
! The  'cfi = 0' appears before the call due to the deallocate and when preparing the C descriptor
! As cfi (i.e. the descriptor itself) is allocated in libgomp, it has to be freed after the call.

! { dg-final { scan-tree-dump-times "__builtin_free" 2 "original" } }
! { dg-final { scan-tree-dump-times "__builtin_free \\(_x->base_addr\\);" 1 "original" } }
! { dg-final { scan-tree-dump-times "_x->base_addr = 0B;" 1 "original" } }
! { dg-final { scan-tree-dump-times "__builtin_free \\(cfi\\.\[0-9\]+\\.base_addr\\);" 1 "original" } }
! { dg-final { scan-tree-dump-times "cfi\\.\[0-9\]+\\.base_addr = 0B;" 1 "original" } }