[Bug fortran/49479] [4.6/4.7 Regression] reshape / optionals / zero sized arrays
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49479 --- Comment #1 from Joost VandeVondele 2011-06-20 20:04:47 UTC --- the difference (I think) seems to be in the present check that has become if (data != 0B && (integer(kind=4)[0:] * restrict) data->data != 0B) instead of the original if (data != 0B)
[Bug fortran/49479] [4.6/4.7 Regression] reshape / optionals / zero sized arrays
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49479 Dominique d'Humieres changed: What|Removed |Added Status|UNCONFIRMED |NEW Last reconfirmed||2011.06.20 20:16:50 Ever Confirmed|0 |1 --- Comment #2 from Dominique d'Humieres 2011-06-20 20:16:50 UTC --- Revision 162456 is OK, 163718 is not.
[Bug fortran/49479] [4.6/4.7 Regression] reshape / optionals / zero sized arrays
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49479 Tobias Burnus changed: What|Removed |Added Keywords||wrong-code CC||burnus at gcc dot gnu.org Target Milestone|--- |4.6.2 --- Comment #3 from Tobias Burnus 2011-06-20 21:39:28 UTC --- There seems to be a bug in the implementation of Fortran 2008's new feature: "A null pointer or unallocated allocatable can be used to denote an absent nonallocatable nonpointer optional argument." That check has been added in Rev 163263 on 2010-08-15. However, I am not sure that the bug is in the new code - it could also be a RESHAPE bug (cf. PR 49324 for another reshape bug). I think gfortran's convention is - and also TR 29113 require that the addr_expr is not NULL if the variable is allocated - even if it is zero sized. However, I need to recheck and maybe also other library functions have this issue. Workaround: -std=f2003.
[Bug fortran/49479] [4.6/4.7 Regression] reshape / optionals / zero sized arrays
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49479 --- Comment #4 from Tobias Burnus 2011-06-21 08:58:31 UTC --- (In reply to comment #3) > I think gfortran's convention is - and also TR 29113 requires - that the > addr_expr is not NULL if the variable is allocated - even if it is zero sized. The TR 29113 draft (Interop ML version) has (5.2.3 CFI_cdesc_t) ftp://ftp.nag.co.uk/sc22wg5/N1851-N1900/N1854.pdf "void * base addr; If the object is an unallocated allocatable or a pointer that is disassociated, the value is NULL. If the object has zero size, the value is not NULL but is otherwise processor-dependent. Otherwise [...]" And trans.c has for gfc_call_malloc: /* Call malloc to allocate size bytes of memory, with special conditions: + if size == 0, return a malloced area of size 1, If one looks at RESHAPE in the library: http://gcc.gnu.org/git/?p=gcc.git;a=blob;f=libgfortran/intrinsics/reshape_generic.c;hb=HEAD one sees: 86 if (ret->data == NULL) 87 { 88 rs = 1; 89 for (n = 0; n < rdim; n++) 90 { 91 rex = shape_data[n]; 93 GFC_DIMENSION_SET(ret->dim[n],0,rex - 1,rs); 95 rs *= rex; 96 } 98 ret->data = internal_malloc_size ( rs * size ); Thus, if shape_data[n] == 0 -- which is here the case --, "rs" == 0 and thus one calls malloc with zero size. POSIX states: "If size is 0, either a null pointer or a unique pointer that can be successfully passed to free() shall be returned." Hence, the "rs*size" should be replaced by "MAX(1, rs*size)". I think other intrinsics will have the same problem.
[Bug fortran/49479] [4.6/4.7 Regression] reshape / optionals / zero sized arrays
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49479 --- Comment #5 from Tobias Burnus 2011-06-21 09:30:32 UTC --- Actually, thinking about it: "RESHAPE(allocatable_array, shape)" is *not* allocatable. trans-expr.c has: 147 if (!sym->attr.pointer && !sym->attr.allocatable 148 && sym->as && sym->as->type == AS_ASSUMED_SHAPE 149 && (gfc_option.allow_std & GFC_STD_F2008) != 0) One probably needs to check the actual argument, i.e. gfc_expr_attr(actual) with allocatable or pointer attribute - or type being C_PTR (including C_NULL_PTR). For the latter: expr->ts.type == BT_DERIVED && expr->ts.u.derived && expr->ts.u.derived->attr.is_iso_c && ??? (some check for ISOCBINDING_PTR)
[Bug fortran/49479] [4.6/4.7 Regression] reshape / optionals / zero sized arrays
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49479 --- Comment #6 from Thomas Koenig 2011-06-27 19:02:12 UTC --- A patch suggested by comment #4 fixes the failure. Regression-testing.
[Bug fortran/49479] [4.6/4.7 Regression] reshape / optionals / zero sized arrays
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49479 --- Comment #7 from Thomas Koenig 2011-06-28 18:59:06 UTC --- Author: tkoenig Date: Tue Jun 28 18:59:04 2011 New Revision: 175594 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=175594 Log: 2011-06-28 Thomas Koenig PR fortran/49479 * m4/reshape.m4: If source allocation is smaller than one, set it to one. * intrinsics/reshape_generic.c: Likewise. * generated/reshape_r16.c: Regenerated. * generated/reshape_c4.c: Regenerated. * generated/reshape_c16.c: Regenerated. * generated/reshape_c8.c: Regenerated. * generated/reshape_r4.c: Regenerated. * generated/reshape_i4.c: Regenerated. * generated/reshape_r10.c: Regenerated. * generated/reshape_r8.c: Regenerated. * generated/reshape_c10.c: Regenerated. * generated/reshape_i8.c: Regenerated. * generated/reshape_i16.c: Regenerated. 2011-06-28 Thomas Koenig PR fortran/49479 * gfortran.dg/reshape_zerosize_3.f90: New test. Added: trunk/gcc/testsuite/gfortran.dg/reshape_zerosize_3.f90 Modified: trunk/gcc/testsuite/ChangeLog trunk/libgfortran/ChangeLog trunk/libgfortran/generated/reshape_c10.c trunk/libgfortran/generated/reshape_c16.c trunk/libgfortran/generated/reshape_c4.c trunk/libgfortran/generated/reshape_c8.c trunk/libgfortran/generated/reshape_i16.c trunk/libgfortran/generated/reshape_i4.c trunk/libgfortran/generated/reshape_i8.c trunk/libgfortran/generated/reshape_r10.c trunk/libgfortran/generated/reshape_r16.c trunk/libgfortran/generated/reshape_r4.c trunk/libgfortran/generated/reshape_r8.c trunk/libgfortran/intrinsics/reshape_generic.c trunk/libgfortran/m4/reshape.m4
[Bug fortran/49479] [4.6/4.7 Regression] reshape / optionals / zero sized arrays
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49479 --- Comment #8 from Thomas Koenig 2011-07-06 18:50:50 UTC --- Author: tkoenig Date: Wed Jul 6 18:50:46 2011 New Revision: 175929 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=175929 Log: 2011-07-06 Thomas Koenig Partial backport from trunk: PR fortran/49479 * runtime/memory.c: If size is zero, allocate a single byte. * m4/eoshift1.m4: Remove double allocation. * m4/eoshift3.m4: Likewise. * generated/eoshift1_4.c: Regenerated. * generated/eoshift1_8.c: Regenerated. * generated/eoshift1_16.c: Regenerated. * generated/eoshift3_4.c: Regenerated. * generated/eoshift3_8.c: Regenerated. * generated/eoshift3_16.c: Regenerated. 2011-07-06 Thomas Koenig PR fortran/49479 * gfortran.dg/reshape_zerosize_3.f90: New test case. Added: branches/gcc-4_6-branch/gcc/testsuite/gfortran.dg/reshape_zerosize_3.f90 Modified: branches/gcc-4_6-branch/gcc/testsuite/ChangeLog branches/gcc-4_6-branch/libgfortran/ChangeLog branches/gcc-4_6-branch/libgfortran/generated/eoshift1_16.c branches/gcc-4_6-branch/libgfortran/generated/eoshift1_4.c branches/gcc-4_6-branch/libgfortran/generated/eoshift1_8.c branches/gcc-4_6-branch/libgfortran/generated/eoshift3_16.c branches/gcc-4_6-branch/libgfortran/generated/eoshift3_4.c branches/gcc-4_6-branch/libgfortran/generated/eoshift3_8.c branches/gcc-4_6-branch/libgfortran/m4/eoshift1.m4 branches/gcc-4_6-branch/libgfortran/m4/eoshift3.m4 branches/gcc-4_6-branch/libgfortran/runtime/memory.c
[Bug fortran/49479] [4.6/4.7 Regression] reshape / optionals / zero sized arrays
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49479 Thomas Koenig changed: What|Removed |Added Status|NEW |RESOLVED Resolution||FIXED --- Comment #9 from Thomas Koenig 2011-07-06 18:51:43 UTC --- Fixed on trunk and 4.6, closing.
[Bug fortran/49479] [4.6/4.7 Regression] reshape / optionals / zero sized arrays
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49479 --- Comment #10 from Thomas Koenig 2011-09-10 14:07:01 UTC --- Author: tkoenig Date: Sat Sep 10 14:06:57 2011 New Revision: 178748 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=178748 Log: 2011-09-10 Thomas Koenig PR fortran/49479 * generated/m4/ifunction.m4: Always call internal_malloc_size even when there is a zero-sized return array. * generated/generated/maxloc1_16_i16.c: Regenerated. * generated/generated/maxloc1_16_i1.c: Regenerated. * generated/generated/maxloc1_16_i2.c: Regenerated. * generated/generated/maxloc1_16_i4.c: Regenerated. * generated/generated/maxloc1_16_i8.c: Regenerated. * generated/generated/maxloc1_16_r10.c: Regenerated. * generated/generated/maxloc1_16_r16.c: Regenerated. * generated/generated/maxloc1_16_r4.c: Regenerated. * generated/generated/maxloc1_16_r8.c: Regenerated. * generated/generated/maxloc1_4_i16.c: Regenerated. * generated/generated/maxloc1_4_i1.c: Regenerated. * generated/generated/maxloc1_4_i2.c: Regenerated. * generated/generated/maxloc1_4_i4.c: Regenerated. * generated/generated/maxloc1_4_i8.c: Regenerated. * generated/generated/maxloc1_4_r10.c: Regenerated. * generated/generated/maxloc1_4_r16.c: Regenerated. * generated/generated/maxloc1_4_r4.c: Regenerated. * generated/generated/maxloc1_4_r8.c: Regenerated. * generated/generated/maxloc1_8_i16.c: Regenerated. * generated/generated/maxloc1_8_i1.c: Regenerated. * generated/generated/maxloc1_8_i2.c: Regenerated. * generated/generated/maxloc1_8_i4.c: Regenerated. * generated/generated/maxloc1_8_i8.c: Regenerated. * generated/generated/maxloc1_8_r10.c: Regenerated. * generated/generated/maxloc1_8_r16.c: Regenerated. * generated/generated/maxloc1_8_r4.c: Regenerated. * generated/generated/maxloc1_8_r8.c: Regenerated. * generated/generated/maxval_i16.c: Regenerated. * generated/generated/maxval_i1.c: Regenerated. * generated/generated/maxval_i2.c: Regenerated. * generated/generated/maxval_i4.c: Regenerated. * generated/generated/maxval_i8.c: Regenerated. * generated/generated/maxval_r10.c: Regenerated. * generated/generated/maxval_r16.c: Regenerated. * generated/generated/maxval_r4.c: Regenerated. * generated/generated/maxval_r8.c: Regenerated. * generated/generated/minloc1_16_i16.c: Regenerated. * generated/generated/minloc1_16_i1.c: Regenerated. * generated/generated/minloc1_16_i2.c: Regenerated. * generated/generated/minloc1_16_i4.c: Regenerated. * generated/generated/minloc1_16_i8.c: Regenerated. * generated/generated/minloc1_16_r10.c: Regenerated. * generated/generated/minloc1_16_r16.c: Regenerated. * generated/generated/minloc1_16_r4.c: Regenerated. * generated/generated/minloc1_16_r8.c: Regenerated. * generated/generated/minloc1_4_i16.c: Regenerated. * generated/generated/minloc1_4_i1.c: Regenerated. * generated/generated/minloc1_4_i2.c: Regenerated. * generated/generated/minloc1_4_i4.c: Regenerated. * generated/generated/minloc1_4_i8.c: Regenerated. * generated/generated/minloc1_4_r10.c: Regenerated. * generated/generated/minloc1_4_r16.c: Regenerated. * generated/generated/minloc1_4_r4.c: Regenerated. * generated/generated/minloc1_4_r8.c: Regenerated. * generated/generated/minloc1_8_i16.c: Regenerated. * generated/generated/minloc1_8_i1.c: Regenerated. * generated/generated/minloc1_8_i2.c: Regenerated. * generated/generated/minloc1_8_i4.c: Regenerated. * generated/generated/minloc1_8_i8.c: Regenerated. * generated/generated/minloc1_8_r10.c: Regenerated. * generated/generated/minloc1_8_r16.c: Regenerated. * generated/generated/minloc1_8_r4.c: Regenerated. * generated/generated/minloc1_8_r8.c: Regenerated. * generated/generated/minval_i16.c: Regenerated. * generated/generated/minval_i1.c: Regenerated. * generated/generated/minval_i2.c: Regenerated. * generated/generated/minval_i4.c: Regenerated. * generated/generated/minval_i8.c: Regenerated. * generated/generated/minval_r10.c: Regenerated. * generated/generated/minval_r16.c: Regenerated. * generated/generated/minval_r4.c: Regenerated. * generated/generated/minval_r8.c: Regenerated. * generated/generated/product_c10.c: Regenerated. * generated/generated/product_c16.c: Regenerated. * generated/generated/product_c4.c: Regenerated. * generated/generated/product_c8.c: Regenerated. * generated/generated/product_i16.c: Regenerated. * generated/generated/product_i1.c: Regenerated. * generated/generated/product_i2.c: Regenerated. * generated/generated/product_i4.c: Regenerated. * generated/generated/product_i8.c: Regenerated. * generated/generated/product_r10.c: Regenerated. * generated/generated/product_r16.c: Regenerated. * generated/generated/product_r4.c: Regen
[Bug fortran/49479] [4.6/4.7 Regression] reshape / optionals / zero sized arrays
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49479 --- Comment #11 from Thomas Koenig 2011-09-11 09:16:08 UTC --- Author: tkoenig Date: Sun Sep 11 09:16:03 2011 New Revision: 178757 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=178757 Log: 2011-09-11 Thomas Koenig Backport fron trunk PR fortran/49479 * generated/m4/ifunction.m4: Always call internal_malloc_size even when there is a zero-sized return array. * generated/generated/maxloc1_16_i16.c: Regenerated. * generated/generated/maxloc1_16_i1.c: Regenerated. * generated/generated/maxloc1_16_i2.c: Regenerated. * generated/generated/maxloc1_16_i4.c: Regenerated. * generated/generated/maxloc1_16_i8.c: Regenerated. * generated/generated/maxloc1_16_r10.c: Regenerated. * generated/generated/maxloc1_16_r16.c: Regenerated. * generated/generated/maxloc1_16_r4.c: Regenerated. * generated/generated/maxloc1_16_r8.c: Regenerated. * generated/generated/maxloc1_4_i16.c: Regenerated. * generated/generated/maxloc1_4_i1.c: Regenerated. * generated/generated/maxloc1_4_i2.c: Regenerated. * generated/generated/maxloc1_4_i4.c: Regenerated. * generated/generated/maxloc1_4_i8.c: Regenerated. * generated/generated/maxloc1_4_r10.c: Regenerated. * generated/generated/maxloc1_4_r16.c: Regenerated. * generated/generated/maxloc1_4_r4.c: Regenerated. * generated/generated/maxloc1_4_r8.c: Regenerated. * generated/generated/maxloc1_8_i16.c: Regenerated. * generated/generated/maxloc1_8_i1.c: Regenerated. * generated/generated/maxloc1_8_i2.c: Regenerated. * generated/generated/maxloc1_8_i4.c: Regenerated. * generated/generated/maxloc1_8_i8.c: Regenerated. * generated/generated/maxloc1_8_r10.c: Regenerated. * generated/generated/maxloc1_8_r16.c: Regenerated. * generated/generated/maxloc1_8_r4.c: Regenerated. * generated/generated/maxloc1_8_r8.c: Regenerated. * generated/generated/maxval_i16.c: Regenerated. * generated/generated/maxval_i1.c: Regenerated. * generated/generated/maxval_i2.c: Regenerated. * generated/generated/maxval_i4.c: Regenerated. * generated/generated/maxval_i8.c: Regenerated. * generated/generated/maxval_r10.c: Regenerated. * generated/generated/maxval_r16.c: Regenerated. * generated/generated/maxval_r4.c: Regenerated. * generated/generated/maxval_r8.c: Regenerated. * generated/generated/minloc1_16_i16.c: Regenerated. * generated/generated/minloc1_16_i1.c: Regenerated. * generated/generated/minloc1_16_i2.c: Regenerated. * generated/generated/minloc1_16_i4.c: Regenerated. * generated/generated/minloc1_16_i8.c: Regenerated. * generated/generated/minloc1_16_r10.c: Regenerated. * generated/generated/minloc1_16_r16.c: Regenerated. * generated/generated/minloc1_16_r4.c: Regenerated. * generated/generated/minloc1_16_r8.c: Regenerated. * generated/generated/minloc1_4_i16.c: Regenerated. * generated/generated/minloc1_4_i1.c: Regenerated. * generated/generated/minloc1_4_i2.c: Regenerated. * generated/generated/minloc1_4_i4.c: Regenerated. * generated/generated/minloc1_4_i8.c: Regenerated. * generated/generated/minloc1_4_r10.c: Regenerated. * generated/generated/minloc1_4_r16.c: Regenerated. * generated/generated/minloc1_4_r4.c: Regenerated. * generated/generated/minloc1_4_r8.c: Regenerated. * generated/generated/minloc1_8_i16.c: Regenerated. * generated/generated/minloc1_8_i1.c: Regenerated. * generated/generated/minloc1_8_i2.c: Regenerated. * generated/generated/minloc1_8_i4.c: Regenerated. * generated/generated/minloc1_8_i8.c: Regenerated. * generated/generated/minloc1_8_r10.c: Regenerated. * generated/generated/minloc1_8_r16.c: Regenerated. * generated/generated/minloc1_8_r4.c: Regenerated. * generated/generated/minloc1_8_r8.c: Regenerated. * generated/generated/minval_i16.c: Regenerated. * generated/generated/minval_i1.c: Regenerated. * generated/generated/minval_i2.c: Regenerated. * generated/generated/minval_i4.c: Regenerated. * generated/generated/minval_i8.c: Regenerated. * generated/generated/minval_r10.c: Regenerated. * generated/generated/minval_r16.c: Regenerated. * generated/generated/minval_r4.c: Regenerated. * generated/generated/minval_r8.c: Regenerated. * generated/generated/product_c10.c: Regenerated. * generated/generated/product_c16.c: Regenerated. * generated/generated/product_c4.c: Regenerated. * generated/generated/product_c8.c: Regenerated. * generated/generated/product_i16.c: Regenerated. * generated/generated/product_i1.c: Regenerated. * generated/generated/product_i2.c: Regenerated. * generated/generated/product_i4.c: Regenerated. * generated/generated/product_i8.c: Regenerated. * generated/generated/product_r10.c: Regenerated. * generated/generated/product_r16.c: Regenerated. * generated/gener