------- Comment #2 from fxcoudert at gcc dot gnu dot org 2006-10-10 07:31 ------- For the TRANSPOSE case, the generated code shows that the {u,l}bounds simply aren't set right:
$ cat pr29391.f90 integer :: i(-1:1,-1:1)=0, j(2) j = lbound(transpose(i)) end $ cat pr29391.f90.003t.original MAIN__ () { int4 j[2]; static int4 i[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0}; _gfortran_set_std (70, 127, 0); { int8 S.0; S.0 = 1; while (1) { if (S.0 > 2) goto L.1; else (void) 0; { struct array2_int4 atmp.2; struct array2_int4 parm.1; parm.1.dtype = 266; parm.1.dim[0].lbound = -1; parm.1.dim[0].ubound = 1; parm.1.dim[0].stride = 1; parm.1.dim[1].lbound = -1; parm.1.dim[1].ubound = 1; parm.1.dim[1].stride = 3; parm.1.data = (void *) &i[0]; parm.1.offset = 0; atmp.2.dtype = parm.1.dtype; atmp.2.dim[0].stride = parm.1.dim[1].stride; atmp.2.dim[0].lbound = parm.1.dim[1].lbound; atmp.2.dim[0].ubound = parm.1.dim[1].ubound; atmp.2.dim[1].stride = parm.1.dim[0].stride; atmp.2.dim[1].lbound = parm.1.dim[0].lbound; atmp.2.dim[1].ubound = parm.1.dim[0].ubound; atmp.2.data = parm.1.data; atmp.2.offset = parm.1.offset; j[NON_LVALUE_EXPR <S.0> + -1] = (int4) atmp.2.dim[S.0 - 1].lbound; } S.0 = S.0 + 1; } L.1:; } } The following patch ought to fix it: Index: gcc/fortran/trans-array.c =================================================================== --- gcc/fortran/trans-array.c (revision 117560) +++ gcc/fortran/trans-array.c (working copy) @@ -787,11 +787,17 @@ gfc_add_modify_expr (&se->pre, gfc_conv_descriptor_lbound (dest, dest_index), - gfc_conv_descriptor_lbound (src, src_index)); + gfc_index_one_node); gfc_add_modify_expr (&se->pre, gfc_conv_descriptor_ubound (dest, dest_index), - gfc_conv_descriptor_ubound (src, src_index)); + build2 (PLUS_EXPR, gfc_array_index_type, + gfc_index_one_node, + build2 (MINUS_EXPR, gfc_array_index_type, + gfc_conv_descriptor_ubound + (src, src_index), + gfc_conv_descriptor_lbound + (src, src_index)))); if (!loop->to[n]) { One last comment: I'm not sure the stride shouldn't be set to one. The patch above regtests fine, and can compile correctly everything I threw at it, but maybe I have not been clever enough to think of something that would trigger a check on the stride. Paul, could I have your opinion on the patch and the stride question? After you comment, I'll go on designing patches for the other functions. -- fxcoudert at gcc dot gnu dot org changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |paulthomas2 at wanadoo dot | |fr Known to fail| |4.2.0 4.1.2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29391