File: allocatable_scalar_13.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 (70 lines) | stat: -rw-r--r-- 2,143 bytes parent folder | download | duplicates (3)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
! { dg-do run }
! { dg-options "-fdump-tree-original" }
!
! Test the fix for PR66079. The original problem was with the first
! allocate statement. The rest of this testcase fixes problems found
! whilst working on it!
!
! Reported by Damian Rouson  <damian@sourceryinstitute.org>
!
  type subdata
    integer, allocatable :: b
  endtype
!  block
    call newRealVec
!  end block
contains
  subroutine newRealVec
    type(subdata), allocatable :: d, e, f
    character(:), allocatable :: g, h, i
    character(8), allocatable :: j
    allocate(d,source=subdata(1)) ! memory was lost, now OK
    allocate(e,source=d) ! OK
    allocate(f,source=create (99)) ! memory was lost, now OK
    if (d%b .ne. 1) STOP 1
    if (e%b .ne. 1) STOP 2
    if (f%b .ne. 99) STOP 3
    allocate (g, source = greeting1("good day"))
    if (g .ne. "good day") STOP 4
    allocate (h, source = greeting2("hello"))
    if (h .ne. "hello") STOP 5
    allocate (i, source = greeting3("hiya!"))
    if (i .ne. "hiya!") STOP 6
    call greeting4 (j, "Goodbye ") ! Test that dummy arguments are OK
    if (j .ne. "Goodbye ") STOP 7
  end subroutine

  function create (arg) result(res)
    integer :: arg
    type(subdata), allocatable :: res, res1
    allocate(res, res1, source = subdata(arg))
  end function

  function greeting1 (arg) result(res) ! memory was lost, now OK
    character(*) :: arg
    Character(:), allocatable :: res
    allocate(res, source = arg)
  end function

  function greeting2 (arg) result(res)
    character(5) :: arg
    Character(:), allocatable :: res
    allocate(res, source = arg)
  end function

  function greeting3 (arg) result(res)
    character(5) :: arg
    Character(5), allocatable :: res, res1
    allocate(res, res1, source = arg) ! Caused an ICE
    if (res1 .ne. res) STOP 8
  end function

  subroutine greeting4 (res, arg)
    character(8), intent(in) :: arg
    Character(8), allocatable, intent(out) :: res
    allocate(res, source = arg) ! Caused an ICE
  end subroutine
end
! { dg-final { scan-tree-dump-times "builtin_malloc" 20 "original" } }
! { dg-final { scan-tree-dump-times "builtin_free" 21 "original" } }