From: Harald Anlauf Date: Mon, 17 Jan 2022 21:52:08 +0000 (+0100) Subject: Fortran: handle expansion of zero-sized array constructors X-Git-Tag: upstream/12.2.0~2002 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0d01a2722671bef37b931fd1f121e44b27e68268;p=platform%2Fupstream%2Fgcc.git Fortran: handle expansion of zero-sized array constructors gcc/fortran/ChangeLog: PR fortran/103692 * array.cc (gfc_expand_constructor): Handle zero-sized array constructors. gcc/testsuite/ChangeLog: PR fortran/103692 * gfortran.dg/pr102520.f90: Adjust error messages. * gfortran.dg/pr103692.f90: New test. --- diff --git a/gcc/fortran/array.cc b/gcc/fortran/array.cc index 4723043..f1d92e0 100644 --- a/gcc/fortran/array.cc +++ b/gcc/fortran/array.cc @@ -1883,6 +1883,9 @@ gfc_expand_constructor (gfc_expr *e, bool fatal) gfc_expr *f; bool rc; + if (gfc_is_size_zero_array (e)) + return true; + /* If we can successfully get an array element at the max array size then the array is too big to expand, so we just return. */ f = gfc_get_array_element (e, flag_max_array_constructor); diff --git a/gcc/testsuite/gfortran.dg/pr102520.f90 b/gcc/testsuite/gfortran.dg/pr102520.f90 index 1c98c18..d2ea8f3 100644 --- a/gcc/testsuite/gfortran.dg/pr102520.f90 +++ b/gcc/testsuite/gfortran.dg/pr102520.f90 @@ -5,8 +5,6 @@ program p type t end type type(t), parameter :: a(4) = shape(1) ! { dg-error "Incompatible" } - type(t), parameter :: b(2,2) = reshape(a,[2,2]) ! { dg-error "Incompatible" } - type(t), parameter :: c(2,2) = transpose(b) ! { dg-error "Unclassifiable" } + type(t), parameter :: b(2,2) = reshape(a,[2,2]) ! { dg-error "must be an array" } + type(t), parameter :: c(2,2) = transpose(b) ! { dg-error "must be of rank 2" } end - -! { dg-error "Different shape for array assignment" " " { target *-*-* } 7 } diff --git a/gcc/testsuite/gfortran.dg/pr103692.f90 b/gcc/testsuite/gfortran.dg/pr103692.f90 new file mode 100644 index 0000000..9687a3c --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr103692.f90 @@ -0,0 +1,23 @@ +! { dg-do compile } +! { dg-options "-fdump-tree-original" } +! PR fortran/103692 - ICE in expand_constructor +! Contributed by G.Steinmetz + +program p + character(3), parameter :: a(4) = 'abc' + character(*), parameter :: b(*) = (a(2:1)) + character(*), parameter :: y(*) = [(a(2:1))] + character(*), parameter :: u(*) = a(2:1) + character(*), parameter :: v(*) = [a(2:1)] + character(*), parameter :: w(-1) = (a(2:1)) + character(*), parameter :: x(-1) = a(2:1) + character(5), parameter :: c(3,3) = 'def' + character(*), parameter :: d(*) = [(c(2:1,2:))] + character(*), parameter :: e(*,*) = (c(2:1,2:)) + if (len(b) /= 3 .or. size (b) /= 0) stop 1 + if (len(y) /= 3 .or. size (y) /= 0) stop 2 + if (len(d) /= 5 .or. size (d) /= 0) stop 3 + if (len(e) /= 5 .or. any (shape (e) /= [0,2])) stop 4 +end + +! { dg-final { scan-tree-dump-not "_gfortran_stop_numeric" "original" } }