From af2d2d135a3374fb8cbd04f027683b0cbb868d88 Mon Sep 17 00:00:00 2001 From: Tobias Burnus Date: Tue, 9 Oct 2018 20:03:31 +0200 Subject: [PATCH] re PR fortran/83522 (ICE on allocatable string reference, string(:)(:)) 2018-10-09 Tobias Burnus PR fortran/83522 * resolve.c (resolve_ref): Reject nonscalar substring references. PR fortran/83522 * gfortran.dg/actual_array_substr_1.f90: Add dg-error, change to dg-do compile. * gfortran.dg/actual_array_substr_2.f90: Ditto. * gfortran.dg/array_initializer_1.f90: Use array element not size-one section. * gfortran.dg/array_substring.f90: New. From-SVN: r264990 --- gcc/fortran/ChangeLog | 6 ++++++ gcc/fortran/resolve.c | 7 +++++++ gcc/testsuite/ChangeLog | 10 ++++++++++ .../gfortran.dg/actual_array_substr_1.f90 | 8 +++++--- .../gfortran.dg/actual_array_substr_2.f90 | 11 ++++++----- gcc/testsuite/gfortran.dg/array_substring.f90 | 17 +++++++++++++++++ 6 files changed, 51 insertions(+), 8 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/array_substring.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index d945e206d50..ab6b09b1cdd 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2018-10-09 Tobias Burnus + + PR fortran/83522 + * resolve.c (resolve_ref): Reject nonscalar + substring references. + 2018-10-09 Paul Thomas PR fortran/87151 diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index 87e65df5f4e..4ec881e5d78 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -5129,6 +5129,13 @@ resolve_ref (gfc_expr *expr) break; case REF_SUBSTRING: + /* F2008, R610 alias F2018, R908. */ + if (current_part_dimension || seen_part_dimension) + { + gfc_error ("Substring reference of nonscalar not permitted at %L", + &expr->where); + return false; + } break; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 985635296ea..3389faa17e5 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,13 @@ +2018-10-09 Tobias Burnus + + PR fortran/83522 + * gfortran.dg/actual_array_substr_1.f90: Add dg-error, + change to dg-do compile. + * gfortran.dg/actual_array_substr_2.f90: Ditto. + * gfortran.dg/array_initializer_1.f90: Use array + element not size-one section. + * gfortran.dg/array_substring.f90: New. + 2018-10-09 Eric Botcazou * gnat.dg/derived_type5.adb, gnat.dg/derived_type5_pkg.ads: New diff --git a/gcc/testsuite/gfortran.dg/actual_array_substr_1.f90 b/gcc/testsuite/gfortran.dg/actual_array_substr_1.f90 index 7c10c7020eb..d992f45f465 100644 --- a/gcc/testsuite/gfortran.dg/actual_array_substr_1.f90 +++ b/gcc/testsuite/gfortran.dg/actual_array_substr_1.f90 @@ -1,15 +1,17 @@ -! { dg-do run } +! { dg-do compile } ! Test fix of PR28118, in which a substring reference to an ! actual argument with an array reference would cause a segfault. ! +! Revised for PR fortran/83522 +! ! Contributed by Paul Thomas ! program gfcbug33 character(12) :: a(2) a(1) = "abcdefghijkl" a(2) = "mnopqrstuvwx" - call foo ((a(2:1:-1)(6:))) - call bar ((a(:)(7:11))) + call foo ((a(2:1:-1)(6:))) ! { dg-error "Substring reference of nonscalar not permitted" } + call bar ((a(:)(7:11))) ! { dg-error "Substring reference of nonscalar not permitted" } contains subroutine foo (chr) character(7) :: chr(:) diff --git a/gcc/testsuite/gfortran.dg/actual_array_substr_2.f90 b/gcc/testsuite/gfortran.dg/actual_array_substr_2.f90 index fed51342ee0..958ab418a43 100644 --- a/gcc/testsuite/gfortran.dg/actual_array_substr_2.f90 +++ b/gcc/testsuite/gfortran.dg/actual_array_substr_2.f90 @@ -1,10 +1,12 @@ -! { dg-do run } +! { dg-do compile } ! Tests the fix for pr28174, in which the fix for pr28118 was ! corrupting the character lengths of arrays that shared a ! character length structure. In addition, in developing the ! fix, it was noted that intent(out/inout) arguments were not ! getting written back to the calling scope. ! +! Revised for PR fortran/83522 +! ! Based on the testscase by Harald Anlauf ! program pr28174 @@ -20,7 +22,7 @@ program pr28174 n = m - 4 ! Make sure that variable substring references work. - call foo (a(:)(m:m+5), c(:)(n:m+2), d(:)(5:9)) + call foo (a(:)(m:m+5), c(:)(n:m+2), d(:)(5:9)) ! { dg-error "Substring reference of nonscalar not permitted" } if (any (a .ne. teststring)) STOP 1 if (any (b .ne. teststring)) STOP 2 if (any (c .ne. (/"ab456789#hij", & @@ -37,8 +39,7 @@ contains ! This next is not required by the standard but tests the ! functioning of the gfortran implementation. ! if (all (x(:)(3:7) .eq. y)) STOP 5 - x = foostring (:)(5 : 4 + len (x)) - y = foostring (:)(3 : 2 + len (y)) + x = foostring (:)(5 : 4 + len (x)) ! { dg-error "Substring reference of nonscalar not permitted" } + y = foostring (:)(3 : 2 + len (y)) ! { dg-error "Substring reference of nonscalar not permitted" } end subroutine foo end program pr28174 - diff --git a/gcc/testsuite/gfortran.dg/array_substring.f90 b/gcc/testsuite/gfortran.dg/array_substring.f90 new file mode 100644 index 00000000000..ea80556cfc1 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/array_substring.f90 @@ -0,0 +1,17 @@ +! { dg-do compile } +! +! PR fortran/83522 +! +! Contributed by urbanjost and Jerry DeLisle +! +program testit + character(len=:),allocatable :: strings(:) + integer :: i + strings=[character(len=2) :: 'AA','BB'] + write(*,*)strings(:)(:) ! { dg-error "Substring reference of nonscalar not permitted" } + !strings(:)(:) ! Parse error: "Invalid character in name" + strings(:)(:) = 'x' ! { dg-error "Substring reference of nonscalar not permitted" } + do i=1, size(strings) + write(*,*)strings(i)(:) ! This is valid and works + end do +end program testit -- 2.30.2