This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: PR fortran/21104: Failure to allocate returned arrays
- From: Richard Sandiford <richard at codesourcery dot com>
- To: Paul Brook <paul at codesourcery dot com>
- Cc: fortran at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Fri, 09 Sep 2005 07:23:47 +0100
- Subject: Re: PR fortran/21104: Failure to allocate returned arrays
- References: <873bojpj3j.fsf@talisman.home><200509082054.03727.paul@codesourcery.com>
Paul Brook <paul@codesourcery.com> writes:
>> gcc/fortran/
>> [...]
>> gcc/testsuite/
>> * gfortran.fortran-torture/execute/pr21104-1.c,
>> * gfortran.fortran-torture/execute/pr21104-2.c,
>> * gfortran.fortran-torture/execute/pr21104-3.c: New tests.
>
> Ok.
Thanks. For the record, here's the updated testsuite patch (now committed).
Richard
gcc/testsuite/
PR fortran/21104
* gfortran.dg/array_alloc_1.f90,
* gfortran.dg/array_alloc_2.f90,
* gfortran.dg/array_alloc_3.f90: New tests.
diff -c /dev/null gcc/testsuite/gfortran.dg/array_alloc_1.f90
*** /dev/null 2005-06-16 22:49:09.000000000 +0100
--- gcc/testsuite/gfortran.dg/array_alloc_1.f90 2005-09-09 07:16:41.000000000 +0100
***************
*** 0 ****
--- 1,21 ----
+ ! PR 21104. Make sure that either f() or its caller will allocate
+ ! the array data. We've decided to make the caller allocate it.
+ ! { dg-do run }
+ program main
+ implicit none
+ call test (f ())
+ contains
+ subroutine test (x)
+ integer, dimension (10) :: x
+ integer :: i
+ do i = 1, 10
+ if (x (i) .ne. i * 100) call abort
+ end do
+ end subroutine test
+
+ function f
+ integer, dimension (10) :: f
+ integer :: i
+ forall (i = 1:10) f (i) = i * 100
+ end function f
+ end program main
diff -c /dev/null gcc/testsuite/gfortran.dg/array_alloc_2.f90
*** /dev/null 2005-06-16 22:49:09.000000000 +0100
--- gcc/testsuite/gfortran.dg/array_alloc_2.f90 2005-09-09 07:11:42.000000000 +0100
***************
*** 0 ****
--- 1,38 ----
+ ! Like array_alloc_1.f90, but check cases in which the array length is
+ ! not a literal constant.
+ ! { dg-do run }
+ program main
+ implicit none
+ integer, parameter :: n = 100
+ call test (n, f1 ())
+ call test (47, f2 (50))
+ call test (n, f3 (f1 ()))
+ contains
+ subroutine test (expected, x)
+ integer, dimension (:) :: x
+ integer :: i, expected
+ if (size (x, 1) .ne. expected) call abort
+ do i = 1, expected
+ if (x (i) .ne. i * 100) call abort
+ end do
+ end subroutine test
+
+ function f1
+ integer, dimension (n) :: f1
+ integer :: i
+ forall (i = 1:n) f1 (i) = i * 100
+ end function f1
+
+ function f2 (howmuch)
+ integer :: i, howmuch
+ integer, dimension (4:howmuch) :: f2
+ forall (i = 4:howmuch) f2 (i) = i * 100 - 300
+ end function f2
+
+ function f3 (x)
+ integer, dimension (:) :: x
+ integer, dimension (size (x, 1)) :: f3
+ integer :: i
+ forall (i = 1:size(x)) f3 (i) = i * 100
+ end function f3
+ end program main
diff -c /dev/null gcc/testsuite/gfortran.dg/array_alloc_3.f90
*** /dev/null 2005-06-16 22:49:09.000000000 +0100
--- gcc/testsuite/gfortran.dg/array_alloc_3.f90 2005-09-09 07:11:45.000000000 +0100
***************
*** 0 ****
--- 1,35 ----
+ ! Like array_alloc_1.f90, but check multi-dimensional arrays.
+ ! { dg-do run }
+ program main
+ implicit none
+ call test ((/ 3, 4, 5 /), f ((/ 3, 4, 5 /)))
+ contains
+ subroutine test (expected, x)
+ integer, dimension (:,:,:) :: x
+ integer, dimension (3) :: expected
+ integer :: i, i1, i2, i3
+ do i = 1, 3
+ if (size (x, i) .ne. expected (i)) call abort
+ end do
+ do i1 = 1, expected (1)
+ do i2 = 1, expected (2)
+ do i3 = 1, expected (3)
+ if (x (i1, i2, i3) .ne. i1 + i2 * 10 + i3 * 100) call abort
+ end do
+ end do
+ end do
+ end subroutine test
+
+ function f (x)
+ integer, dimension (3) :: x
+ integer, dimension (x(1), x(2), x(3)) :: f
+ integer :: i1, i2, i3
+ do i1 = 1, x(1)
+ do i2 = 1, x(2)
+ do i3 = 1, x(3)
+ f (i1, i2, i3) = i1 + i2 * 10 + i3 * 100
+ end do
+ end do
+ end do
+ end function f
+ end program main