------- Comment #1 from fxcoudert at gcc dot gnu dot org 2008-03-25 12:35 ------- Versions <= 4.2.3 fail also for SHAPE:
$ /opt/gcc-4.0.?/bin/gfortran a.f90 -static && ./a.out UBOUND ZDA1= 0 -5 -1 SHAPE = 0 -5 -1 $ /opt/gcc-4.1.?/bin/gfortran a.f90 -static && ./a.out UBOUND ZDA1= 0 -5 -1 SHAPE = 0 -5 -1 $ /opt/gcc-4.2.?/bin/gfortran a.f90 -static && ./a.out UBOUND ZDA1= 0 -5 -1 SHAPE = 0 -5 -1 What's happening is that we simply forget to check for zero-sized sections. The following code: call s(1) contains subroutine s(n) real x(10) print *, ubound(x(5:n)) end subroutine end program is translated into: parm.2.dim[0].lbound = 1; parm.2.dim[0].ubound = *n + -4; parm.2.dim[0].stride = 1; parm.2.data = (void *) &x[4]; parm.2.offset = -5; D.886 = (parm.2.dim[S.1].ubound - parm.2.dim[S.1].lbound) + 1; _gfortran_transfer_integer (&dt_parm.0, &D.886, 4); We're missing something like D.886 = MAX_EXPR (D.886, 0). I remembered taking care of these problems in the past, in trans-intrinsic.c (gfc_conv_intrinsic_bound), but apparently I forgot the block of code in the second arm of the "if (as)" condition. I think the following patch does what is required (but have not time for testing right now): Index: trans-intrinsic.c =================================================================== --- trans-intrinsic.c (revision 132747) +++ trans-intrinsic.c (working copy) @@ -930,6 +930,8 @@ size = fold_build2 (MINUS_EXPR, gfc_array_index_type, ubound, lbound); se->expr = fold_build2 (PLUS_EXPR, gfc_array_index_type, size, gfc_index_one_node); + se->expr = fold_build2 (MAX_EXPR, gfc_array_index_type, se->expr, + gfc_index_zero_node); } else se->expr = gfc_index_one_node; -- fxcoudert at gcc dot gnu dot org changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |fxcoudert at gcc dot gnu dot | |org Known to fail| |4.0.4 4.1.2 4.2.3 4.3.0 | |4.4.0 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35685