File: elemental_subroutine_3.f90

package info (click to toggle)
gcc-arm-none-eabi 15%3A12.2.rel1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 959,712 kB
  • sloc: cpp: 3,275,382; ansic: 2,061,766; ada: 840,956; f90: 208,513; makefile: 76,132; asm: 73,433; xml: 50,448; exp: 34,146; sh: 32,436; objc: 15,637; fortran: 14,012; python: 11,991; pascal: 6,787; awk: 4,779; perl: 3,054; yacc: 338; ml: 285; lex: 201; haskell: 122
file content (50 lines) | stat: -rw-r--r-- 1,858 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
! { dg-do run }
! Test the fix for PR25746, in which dependency checking was not being
! done for elemental subroutines and therefore for interface assignments.
!
! This test is based on
! http://home.comcast.net/~kmbtib/Fortran_stuff/elem_assign.f90
! as reported by Harald Anlauf <anlauf@gmx.de> in the PR.
! 
module elem_assign
   implicit none
   type mytype
      integer x
   end type mytype
   interface assignment(=)
      module procedure myassign
   end interface assignment(=)
   contains
      elemental subroutine myassign(x,y)
         type(mytype), intent(out) :: x
         type(mytype), intent(in) :: y
! Multiply the components by 2 to verify that this is being called.
         x%x = y%x*2
      end subroutine myassign
end module elem_assign

program test
   use elem_assign
   implicit none
   type(mytype) :: y(6), x(6) = (/mytype(1),mytype(20),mytype(300),&
                                  mytype(4000),mytype(50000),&
                                  mytype(1000000)/)
   type(mytype) :: z(2, 3)
! The original case - dependency between lhs and rhs. 
   x = x((/2,3,1,4,5,6/))
   if (any(x%x .ne. (/40, 600, 2, 8000, 100000, 2000000/))) STOP 1
! Slightly more elborate case with non-trivial array ref on lhs.
   x(4:1:-1) = x((/1,3,2,4/))
   if (any(x%x .ne. (/16000, 1200, 4, 80, 100000, 2000000/))) STOP 2
! Check that no-dependence case works....
   y = x
   if (any(y%x .ne. (/32000, 2400, 8, 160, 200000, 4000000/))) STOP 3
! ...and now a case that caused headaches during the preparation of the patch
   x(2:5) = x(1:4)
   if (any(x%x .ne. (/16000, 32000, 2400, 8, 160, 2000000/))) STOP 4
! Check offsets are done correctly in multi-dimensional cases
   z = reshape (x, (/2,3/))
   z(:, 3:2:-1) = z(:, 1:2)
   y = reshape (z, (/6/))
   if (any(y%x .ne. (/ 64000, 128000, 19200, 64, 128000, 256000/))) STOP 5
end program test