summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gfortran.dg
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/testsuite/gfortran.dg')
-rw-r--r--gcc/testsuite/gfortran.dg/dec_init_1.f9062
-rw-r--r--gcc/testsuite/gfortran.dg/dec_init_2.f9046
-rw-r--r--gcc/testsuite/gfortran.dg/init_flag_13.f9051
-rw-r--r--gcc/testsuite/gfortran.dg/init_flag_14.f9051
-rw-r--r--gcc/testsuite/gfortran.dg/init_flag_15.f0364
5 files changed, 274 insertions, 0 deletions
diff --git a/gcc/testsuite/gfortran.dg/dec_init_1.f90 b/gcc/testsuite/gfortran.dg/dec_init_1.f90
new file mode 100644
index 00000000000..91f16f85294
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/dec_init_1.f90
@@ -0,0 +1,62 @@
+! { dg-do run }
+! { dg-options "-fdec-structure -finit-derived -finit-local-zero -fdump-tree-original" }
+!
+! Test -finit-derived with DEC structure and union.
+!
+
+subroutine dummy(i1,r1,c1,l1,i2,r2,c2,l2)
+ implicit none
+ integer, intent(in) :: i1
+ real, intent(in) :: r1
+ character, intent(in) :: c1
+ logical, intent(in) :: l1
+ integer, intent(inout) :: i2
+ real, intent(inout) :: r2
+ character, intent(inout) :: c2
+ logical, intent(inout) :: l2
+ print *, i1, i2, l1, l2, c1, c2, r1, r2
+ if ( i1 .ne. 0 .or. i2 .ne. 0 ) call abort()
+ if ( l1 .or. l2 ) call abort()
+ if ( c1 .ne. achar(0) .or. c2 .ne. achar(0) ) call abort()
+ if ( r1 .ne. 0.0 .or. r2 .ne. 0.0 ) call abort()
+end subroutine
+
+structure /s3/
+ union
+ map
+ integer m11
+ real m12
+ character m13
+ logical m14
+ end map
+ map
+ logical m21
+ character m22
+ real m23
+ integer m24
+ end map
+ end union
+end structure
+
+structure /s2/
+ integer i2
+ real r2
+ character c2
+ logical l2
+end structure
+
+structure /s1/
+ logical l1
+ real r1
+ character c1
+ integer i1
+ record /s2/ y
+end structure
+
+record /s1/ x
+record /s3/ y
+
+call dummy (x.i1, x.r1, x.c1, x.l1, x.y.i2, x.y.r2, x.y.c2, x.y.l2)
+call dummy (y.m11, y.m12, y.m13, y.m14, y.m24, y.m23, y.m22, y.m21)
+
+end
diff --git a/gcc/testsuite/gfortran.dg/dec_init_2.f90 b/gcc/testsuite/gfortran.dg/dec_init_2.f90
new file mode 100644
index 00000000000..0efcdf96ad1
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/dec_init_2.f90
@@ -0,0 +1,46 @@
+! { dg-do run }
+! { dg-options "-fdec-structure -finit-derived -finit-integer=42 -finit-real=nan -finit-logical=true -finit-character=32 -fdump-tree-original" }
+!
+! Test -finit-derived with DEC structure and union.
+!
+
+subroutine dummy(i1,r1,c1,l1,i2,r2,c2,l2)
+ implicit none
+ integer, intent(in) :: i1
+ real, intent(in) :: r1
+ character, intent(in) :: c1
+ logical, intent(in) :: l1
+ integer, intent(inout) :: i2
+ real, intent(inout) :: r2
+ character, intent(inout) :: c2
+ logical, intent(inout) :: l2
+ print *, i1, i2, l1, l2, c1, c2, r1, r2
+ if ( i1 .ne. 42 .or. i2 .ne. 42 ) call abort()
+ if ( (.not. l1) .or. (.not. l2) ) call abort()
+ if ( c1 .ne. achar(32) .or. c2 .ne. achar(32) ) call abort()
+ if ( (.not. isnan(r1)) .or. (.not. isnan(r2)) ) call abort()
+end subroutine
+
+! Nb. the current implementation decides the -finit-* flags are meaningless
+! with components of a union, so we omit the union test here.
+
+structure /s2/
+ integer i2
+ real r2
+ character c2
+ logical l2
+end structure
+
+structure /s1/
+ logical l1
+ real r1
+ character c1
+ integer i1
+ record /s2/ y
+end structure
+
+record /s1/ x
+
+call dummy (x.i1, x.r1, x.c1, x.l1, x.y.i2, x.y.r2, x.y.c2, x.y.l2)
+
+end
diff --git a/gcc/testsuite/gfortran.dg/init_flag_13.f90 b/gcc/testsuite/gfortran.dg/init_flag_13.f90
new file mode 100644
index 00000000000..cdd039af78c
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/init_flag_13.f90
@@ -0,0 +1,51 @@
+! { dg-do compile }
+! { dg-options "-finit-local-zero -finit-derived -fdump-tree-original" }
+!
+! Make sure -finit-derived initializes components of local derived type
+! variables to zero with -finit-local-zero.
+!
+
+subroutine dummy(i1,r1,c1,l1,i2,r2,c2,l2)
+ implicit none
+ integer, intent(in) :: i1
+ real, intent(in) :: r1
+ character, intent(in) :: c1
+ logical, intent(in) :: l1
+ integer, intent(out) :: i2
+ real, intent(out) :: r2
+ character, intent(out) :: c2
+ logical, intent(out) :: l2
+end subroutine
+
+type t2
+ integer i2
+ real r2
+ character c2
+ logical l2
+end type
+
+type t1
+ logical l1
+ real r1
+ character c1
+ integer i1
+ type (t2) y
+end type
+
+type (t1) :: x
+
+call dummy (x%i1, x%r1, x%c1, x%l1, x%y%i2, x%y%r2, x%y%c2, x%y%l2)
+
+end
+
+! We expect to see each component initialized exactly once in MAIN.
+! NB. the "once" qualifier also tests that the dummy variables aren't
+! given an extraneous initializer.
+! { dg-final { scan-tree-dump-times "i1= *0" 1 "original" } }
+! { dg-final { scan-tree-dump-times "r1= *0" 1 "original" } }
+! { dg-final { scan-tree-dump-times "c1= *\"\"" 1 "original" } }
+! { dg-final { scan-tree-dump-times "l1= *0" 1 "original" } }
+! { dg-final { scan-tree-dump-times "i2= *0" 1 "original" } }
+! { dg-final { scan-tree-dump-times "r2= *0" 1 "original" } }
+! { dg-final { scan-tree-dump-times "c2= *\"\"" 1 "original" } }
+! { dg-final { scan-tree-dump-times "l2= *0" 1 "original" } }
diff --git a/gcc/testsuite/gfortran.dg/init_flag_14.f90 b/gcc/testsuite/gfortran.dg/init_flag_14.f90
new file mode 100644
index 00000000000..13991f826d7
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/init_flag_14.f90
@@ -0,0 +1,51 @@
+! { dg-do compile }
+! { dg-options "-finit-derived -finit-integer=42 -finit-real=inf -finit-logical=true -finit-character=32 -fdump-tree-original" }
+!
+! Make sure -finit-derived initializes components of local derived type
+! variables according to other -finit-* flags.
+!
+
+subroutine dummy(i1,r1,c1,l1,i2,r2,c2,l2)
+ implicit none
+ integer, intent(in) :: i1
+ real, intent(in) :: r1
+ character, intent(in) :: c1
+ logical, intent(in) :: l1
+ integer, intent(out) :: i2
+ real, intent(out) :: r2
+ character, intent(out) :: c2
+ logical, intent(out) :: l2
+end subroutine
+
+type t2
+ integer i2
+ real r2
+ character c2
+ logical l2
+end type
+
+type t1
+ logical l1
+ real r1
+ character c1
+ integer i1
+ type (t2) y
+end type
+
+type (t1) :: x
+
+call dummy (x%i1, x%r1, x%c1, x%l1, x%y%i2, x%y%r2, x%y%c2, x%y%l2)
+
+end
+
+! We expect to see each component initialized exactly once in MAIN.
+! NB. the "once" qualifier also tests that the dummy variables aren't
+! given an extraneous initializer.
+! { dg-final { scan-tree-dump-times "i1= *42" 1 "original" } }
+! { dg-final { scan-tree-dump-times "r1= *\[iI]nf" 1 "original" } }
+! { dg-final { scan-tree-dump-times "c1= *\" \"" 1 "original" } }
+! { dg-final { scan-tree-dump-times "l1= *1" 1 "original" } }
+! { dg-final { scan-tree-dump-times "i2= *42" 1 "original" } }
+! { dg-final { scan-tree-dump-times "r2= *\[iI]nf" 1 "original" } }
+! { dg-final { scan-tree-dump-times "c2= *\" \"" 1 "original" } }
+! { dg-final { scan-tree-dump-times "l2= *1" 1 "original" } }
diff --git a/gcc/testsuite/gfortran.dg/init_flag_15.f03 b/gcc/testsuite/gfortran.dg/init_flag_15.f03
new file mode 100644
index 00000000000..fef9442dd50
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/init_flag_15.f03
@@ -0,0 +1,64 @@
+! { dg-do run }
+! { dg-options "-finit-derived -finit-integer=1" }
+!
+! Make sure -finit-derived works on class variables.
+! Based on class_result_1.f03
+!
+
+module points_2i
+
+ implicit none
+
+ type point2i
+ integer :: x, y
+ end type
+
+contains
+
+ subroutine print( point )
+ class(point2i) :: point
+ write(*,'(2i4)') point%x, point%y
+ end subroutine
+
+ subroutine set_vector( point, rx, ry )
+ class(point2i) :: point
+ integer :: rx, ry
+ point%x = rx
+ point%y = ry
+ end subroutine
+
+ function add_vector( point, vector )
+ class(point2i), intent(in) :: point, vector
+ class(point2i), allocatable :: add_vector
+ allocate( add_vector )
+ add_vector%x = point%x + vector%x
+ add_vector%y = point%y + vector%y
+ end function
+
+end module
+
+
+program init_flag_15
+
+ use points_2i
+ implicit none
+
+ type(point2i), target :: point_2i, vector_2i
+ class(point2i), pointer :: point, vector
+ type(point2i) :: vsum
+ integer :: i
+
+ point => point_2i ! = (1, 1) due to -finit-integer
+ vector => vector_2i
+ call set_vector(vector, 2, 2)
+ vsum = add_vector(point, vector)
+
+ call print(point)
+ call print(vector)
+ call print(vsum)
+
+ if (vsum%x .ne. 3 .or. vsum%y .ne. 3) then
+ call abort()
+ endif
+
+end program