File: alloc_comp_assign_2.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 (51 lines) | stat: -rw-r--r-- 1,590 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
! { dg-do run }
! Test FORALL and WHERE with derived types with allocatable components (PR 20541).
!
! Contributed by Erik Edelmann  <eedelmann@gcc.gnu.org>
!            and Paul Thomas  <pault@gcc.gnu.org>
!
  type :: a
    integer, allocatable :: i(:)
  end type a

  type :: b
    type (a), allocatable :: at(:)
  end type b

  type(a) :: x(2)
  type(b) :: y(2), z(2)
  integer i, m(4)

! Start with scalar and array element assignments in FORALL.

  x(1) = a ((/1, 2, 3, 4/))
  x(2) = a ((/1, 2, 3, 4/) + 10)
  forall (j = 1:2, i = 1:4, x(j)%i(i) > 2 + (j-1)*10)  x(j)%i(i) =  j*4-i
  if (any ((/((x(i)%i(j), j = 1,4), i = 1,2)/) .ne. &
          (/1, 2, 1, 0, 11, 12, 5, 4/))) STOP 1

  y(1) = b ((/x(1),x(2)/))
  y(2) = b ((/x(2),x(1)/))
  forall (k = 1:2, j=1:2, i = 1:4, y(k)%at(j)%i(i) <= 10)
    y(k)%at(j)%i(i) =  j*4-i+k
  end forall
  if (any ((/(((y(k)%at(i)%i(j), j = 1,4), i = 1,2), k = 1,2)/) .ne. &
         (/4,3,2,1,11,12,6,5,11,12,3,2,9,8,7,6/))) STOP 2 

! Now simple assignments in WHERE.

  where (y(1)%at(1)%i > 2) y(1)%at(1)%i = 0
  if (any( (/(((y(k)%at(i)%i(j), j = 1,4), i = 1,2), k = 1,2)/) .ne. &
         (/0,0,2,1,11,12,6,5,11,12,3,2,9,8,7,6/))) STOP 3 

! Check that temporaries and full array  alloctable component assignments
! are correctly handled in FORALL.

  x = (/a ((/1,2,3,4/)),a ((/5,6,7,8/))/)
  forall (i=1:2) y(i) = b ((/x(i)/))
  forall (i=1:2) y(i) = y(3-i)      ! This needs a temporary.
  forall (i=1:2) z(i) = y(i)
  if (any ((/(((z(k)%at(i)%i(j), j = 1,4), i = 1,1), k = 1,2)/) .ne. &
         (/(/5,6,7,8/),(/1,2,3,4/)/))) STOP 4

end