From fba53b18ab956e028e1a710f0029404408888c43 Mon Sep 17 00:00:00 2001 From: Paul Thomas Date: Tue, 31 May 2005 17:39:03 +0000 Subject: [PATCH] char_initialiser_actual.f90: Test character initialisers as actual arguments. 2005-05-30 Paul Thomas * gfortran.dg/char_initialiser_actual.f90: Test character initialisers as actual arguments. * gfortran.dg/char_pointer_comp_assign.f90: Test character pointer structure component assignments. * gfortran.dg/char_array_structure_constructor.f90: Test character components in structure constructors. From-SVN: r100401 --- gcc/testsuite/ChangeLog | 9 ++++++ .../char_array_structure_constructor.f90 | 28 +++++++++++++++++ .../gfortran.dg/char_initialiser_actual.f90 | 27 ++++++++++++++++ .../gfortran.dg/char_pointer_comp_assign.f90 | 31 +++++++++++++++++++ 4 files changed, 95 insertions(+) create mode 100755 gcc/testsuite/gfortran.dg/char_array_structure_constructor.f90 create mode 100755 gcc/testsuite/gfortran.dg/char_initialiser_actual.f90 create mode 100755 gcc/testsuite/gfortran.dg/char_pointer_comp_assign.f90 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 2b499e94dd72..57f8f913c02b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,12 @@ +2005-05-31 Paul Thomas + + * gfortran.dg/char_initialiser_actual.f90: + Test character initialisers as actual arguments. + * gfortran.dg/char_pointer_comp_assign.f90: + Test character pointer structure component assignments. + * gfortran.dg/char_array_structure_constructor.f90: + Test character components in structure constructors. + 2005-05-31 Andrew pinski PR middle-end/20931 diff --git a/gcc/testsuite/gfortran.dg/char_array_structure_constructor.f90 b/gcc/testsuite/gfortran.dg/char_array_structure_constructor.f90 new file mode 100755 index 000000000000..0b6c05c33213 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/char_array_structure_constructor.f90 @@ -0,0 +1,28 @@ +! { dg-do run } +! This test the fix of PR19107, where character array actual +! arguments in derived type constructors caused an ICE. +! It also checks that the scalar counterparts are OK. +! Contributed by Paul Thomas pault@gcc.gnu.org +! +MODULE global + TYPE :: dt + CHARACTER(4) a + CHARACTER(4) b(2) + END TYPE + TYPE (dt), DIMENSION(:), ALLOCATABLE, SAVE :: c +END MODULE global +program char_array_structure_constructor + USE global + call alloc (2) + if ((any (c%a /= "wxyz")) .OR. & + (any (c%b(1) /= "abcd")) .OR. & + (any (c%b(2) /= "efgh"))) call abort () +contains + SUBROUTINE alloc (n) + USE global + ALLOCATE (c(n), STAT=IALLOC_FLAG) + DO i = 1,n + c (i) = dt ("wxyz",(/"abcd","efgh"/)) + ENDDO + end subroutine alloc +END program char_array_structure_constructor diff --git a/gcc/testsuite/gfortran.dg/char_initialiser_actual.f90 b/gcc/testsuite/gfortran.dg/char_initialiser_actual.f90 new file mode 100755 index 000000000000..3796f7ee21c3 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/char_initialiser_actual.f90 @@ -0,0 +1,27 @@ +! { dg do-run } +! Tests passing of character array initialiser as actual argument. +! Fixes PR18109. +! Contributed by Paul Thomas pault@gcc.gnu.org +program char_initialiser + character*5, dimension(3) :: x + character*5, dimension(:), pointer :: y + x=(/"is Ja","ne Fo","nda"/) + call sfoo ("is Ja", x(1)) + call afoo ((/"is Ja","ne Fo","nda"/), x) + y => pfoo ((/"is Ja","ne Fo","nda"/)) + call afoo (y, x) +contains + subroutine sfoo(ch1, ch2) + character*(*) :: ch1, ch2 + if (ch1 /= ch2) call abort () + end subroutine sfoo + subroutine afoo(ch1, ch2) + character*(*), dimension(:) :: ch1, ch2 + if (any(ch1 /= ch2)) call abort () + end subroutine afoo + function pfoo(ch2) + character*5, dimension(:), target :: ch2 + character*5, dimension(:), pointer :: pfoo + pfoo => ch2 + end function pfoo +end program diff --git a/gcc/testsuite/gfortran.dg/char_pointer_comp_assign.f90 b/gcc/testsuite/gfortran.dg/char_pointer_comp_assign.f90 new file mode 100755 index 000000000000..4e2d853b185c --- /dev/null +++ b/gcc/testsuite/gfortran.dg/char_pointer_comp_assign.f90 @@ -0,0 +1,31 @@ +! { dg-do run } +! This test the fix of PR18283, where assignments of scalar, +! character pointer components of derived types caused an ICE. +! It also checks that the array counterparts remain operational. +! Contributed by Paul Thomas pault@gcc.gnu.org +! +program char_pointer_comp_assign + implicit none + type :: dt + character (len=4), pointer :: scalar + character (len=4), pointer :: array(:) + end type dt + type (dt) :: a + character (len=4), target :: scalar_t ="abcd" + character (len=4), target :: array_t(2) = (/"abcd","efgh"/) + +! Do assignments first + allocate (a%scalar, a%array(2)) + a%scalar = scalar_t + if (a%scalar /= "abcd") call abort () + a%array = array_t + if (any(a%array /= (/"abcd","efgh"/))) call abort () + deallocate (a%scalar, a%array) + +! Now do pointer assignments. + a%scalar => scalar_t + if (a%scalar /= "abcd") call abort () + a%array => array_t + if (any(a%array /= (/"abcd","efgh"/))) call abort () + +end program char_pointer_comp_assign