This simplified code snippet with a zero sized array parameter z ... program p integer, parameter :: z(0) = 0 print *, any(z > 0) print *, all(z > 0) end or this variation ... program p integer, parameter :: z(1:0) = 0 print *, any(z > 0) print *, all(z > 0) end prints (with gfortran 5.1.1 on SUSE Linux 13.2, 64 bit) internal compiler error: in gfc_conv_intrinsic_anyall, at fortran/trans-intrinsic.c:3149 Whereas, without declaring z as a parameter it works, e.g. program p integer :: z(0) = 0 print *, any(z > 0) print *, all(z > 0) end Kind regards.

Some more examples with other error messages. This one ... program p integer, parameter :: z(0) = 0 print *, count(z > 0) end yields : internal compiler error: in gfc_conv_intrinsic_count, at fortran/trans-intrinsic.c:3233 This one ... program p integer, parameter :: z(0) = 0 print *, iall(z, z > 0) print *, iany(z, z > 0) print *, iparity(z, z > 0) print *, parity(z > 0) print *, product(z, z > 0) print *, sum(z, z > 0) end yields : internal compiler error: in gfc_conv_intrinsic_arith, at fortran/trans-intrinsic.c:3357 This one ... program p integer, parameter :: z(0) = 0 print *, minval(z, z > 0) print *, maxval(z, z > 0) end yields : internal compiler error: in gfc_conv_intrinsic_minmaxval, at fortran/trans-intrinsic.c:4253

Confirmed. I glance at the simplification code suggests that gfortran is not considering the possibility of zero-sized constant arrays. Not sure how to fix this one.

Maybe some kind of "shortcut" (similar to Steve's fix for pr83998) can solve this. Not sure where this would fit in.

(In reply to Harald Anlauf from comment #3) > Maybe some kind of "shortcut" (similar to Steve's fix for pr83998) can > solve this. Not sure where this would fit in. I have a patch for at least the ANY and ALL problem. :-)

On Thu, Mar 01, 2018 at 10:31:42PM +0000, kargl at gcc dot gnu.org wrote: > (In reply to Harald Anlauf from comment #3) > > Maybe some kind of "shortcut" (similar to Steve's fix for pr83998) can > > solve this. Not sure where this would fit in. > > I have a patch for at least the ANY and ALL problem. :-) > Well, the simply obvious patch gfc_expr * gfc_simplify_any (gfc_expr *mask, gfc_expr *dim) { + /* Check for zero sized array. sgk */ + if (mask->rank > 0 && mask->shape == NULL) + return gfc_get_logical_expr (mask->ts.kind, &mask->where, false); + return simplify_transformation (mask, dim, NULL, false, gfc_or); } cause a bunch of regressions. One is given by ! { dg-do run } ! PR 71795 - wrong result when putting an array constructor ! instide an iterator. program test implicit none integer :: i,n logical, dimension(1) :: ra logical :: rs integer, allocatable :: a(:) allocate ( a(1) ) n = 1 a = 2 rs = any ( (/ (any(a(i).eq.(/1,2,3/)) ,i=1,n) /) ) if (.not. rs) call abort end program test which is odd. The code never goes through the if () statement as mask->shape is always non-null. So, the code should compile as-if I never made a change to gfc_simplify_any. :(

I've worked out the issues with regression in the testsuite. (Well, I think I have.)

Patch submitted. https://gcc.gnu.org/ml/fortran/2018-03/msg00010.html This fixes additional failures not included in Gerhard's testcases.

Author: kargl Date: Sat Mar 3 19:49:20 2018 New Revision: 258223 URL: https://gcc.gnu.org/viewcvs?rev=258223&root=gcc&view=rev Log: 2018-03-03 Steven G. Kargl <kargl@gcc.gnu.org> PR fortran/66128 * simplify.c (is_size_zero_array): New function to check for size zero array. (gfc_simplify_all, gfc_simplify_any, gfc_simplify_count, gfc_simplify_iall, gfc_simplify_iany, gfc_simplify_iparity, gfc_simplify_minval, gfc_simplify_maxval, gfc_simplify_norm2, gfc_simplify_product, gfc_simplify_sum): Use it, and implement requirements from F2018. 2018-03-03 Steven G. Kargl <kargl@gcc.gnu.org> PR fortran/66128 * gfortran.dg/zero_sized_8.f90: New test. Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/simplify.c trunk/gcc/testsuite/ChangeLog

Author: kargl Date: Sat Mar 3 19:59:54 2018 New Revision: 258224 URL: https://gcc.gnu.org/viewcvs?rev=258224&root=gcc&view=rev Log: 2018-03-03 Steven G. Kargl <kargl@gcc.gnu.org> PR fortran/66128 * gfortran.dg/zero_sized_8.f90: Really commit new test. Added: trunk/gcc/testsuite/gfortran.dg/zero_sized_8.f90 Modified: trunk/gcc/testsuite/ChangeLog

Fixed on trunk. The patch does not apply cleaning to branch-7 due to changes in minval max maxval simplification changes. Closing as fixed. Thanks for the bug report.

According to your mail at (In reply to kargl from comment #10) > Closing as fixed. https://gcc.gnu.org/ml/fortran/2018-03/msg00010.html still shows a few tests that fail. Let's keep this PR open to track these.

(In reply to Thomas Koenig from comment #11) > According to your mail at (In reply to kargl from comment #10) > > > Closing as fixed. > > https://gcc.gnu.org/ml/fortran/2018-03/msg00010.html still shows a few > tests that fail. > > Let's keep this PR open to track these. I was going to submit individual PR's for the remaining issues after writing code to actually test for the ICE.

unassign myself

(In reply to Thomas Koenig from comment #11) > According to your mail at (In reply to kargl from comment #10) > > > Closing as fixed. > > https://gcc.gnu.org/ml/fortran/2018-03/msg00010.html still shows a few > tests that fail. > > Let's keep this PR open to track these. First, I should note that the URL does not lead to a list of tests that fail. It points to a list of intrinsic subrprogram where the Fortran standard specifically calls out behavior for dummy arguments associated with a size zero actual argument. No tests were written or performed. Item 1) is covered by PR 54613 Item 2) is now PR 84697. Items 3)-5) do not exhibit any unexpected behavior. Item 6) concerns old g77 compatibility routines I won't check those as no one should be using these routines. This PR should be closed, but I'll leave that up to others.

Author: tkoenig Date: Tue Mar 6 23:50:01 2018 New Revision: 258305 URL: https://gcc.gnu.org/viewcvs?rev=258305&root=gcc&view=rev Log: 2017-03-06 Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/84697 PR fortran/66128 * expr.c (simplify_parameter_variable): If p is a size zero array and not an ARRAY_EXPR insert an empty array constructor and return. * gfortran.h: Add prototype for gfc_is_size_zero_array. * simplify.c (is_size_zero_array): Make non-static and rename into (gfc_is_size_zero_array): Check for parameter arrays of zero size by comparing shape and absence of constructor. (gfc_simplify_all): Use gfc_is_size_zero_array instead of is_size_zero_array. (gfc_simplify_count): Likewise. (gfc_simplify_iall): Likewise. (gfc_simplify_iany): Likewise. (gfc_simplify_iparity): Likewise. (gfc_simplify_minval): Likewise. (gfc_simplify_maxval): Likewise. (gfc_simplify_product): Likewise. (gfc_simplify_sum): Likewise. 2017-03-06 Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/84697 PR fortran/66128 * gfortran.dg/minmaxloc_zerosize_1.f90: New test. Added: trunk/gcc/testsuite/gfortran.dg/minmaxloc_zerosize_1.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/expr.c trunk/gcc/fortran/gfortran.h trunk/gcc/fortran/simplify.c trunk/gcc/testsuite/ChangeLog

I'll take a look at what's left (maxval for strings, at least) and fix what is necessary to fix.

Here's a problem with maxval: $ cat maxval_parameter_2.f90 ! { dg-do run } program main integer, dimension(0,3), parameter :: i = 0 integer, dimension(0,3) :: j = 0 print *,maxval(i,dim=1) print *,maxval(j,dim=1) end program main $ gfortran maxval_parameter_2.f90 $ ./a.out -2147483648 -2147483648 -2147483648 -2147483648 The run-time result is correct, the simplified version isn't.

Author: tkoenig Date: Sun Mar 11 20:28:00 2018 New Revision: 258435 URL: https://gcc.gnu.org/viewcvs?rev=258435&root=gcc&view=rev Log: 2018-03-11 Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/66128 * simplify.c (simplify_transformation): Return default result for empty array argument. (gfc_simplify_all): Remove special-case handling for zerosize. (gfc_simplify_any): Likewise. (gfc_simplify_count): Likewise. (gfc_simplify_iall): Likewise. (gfc_simplify_iany): Likewise. (gfc_simplify_iparity): Likewise. (gfc_simplify_minval): Likewise. (gfc_simplify_maxval): Likewise. (gfc_simplify_norm2): Likewise. (gfc_simplify_product): Likewise. (gfc_simplify_sum): Likewise. 2018-03-11 Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/66128 * gfortran.dg/zero_sized_9.f90: New test. Added: trunk/gcc/testsuite/gfortran.dg/zero_sized_9.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/simplify.c trunk/gcc/testsuite/ChangeLog

Fixed, closing.