https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61888
Bug ID: 61888 Summary: Wrong results with SIZEOF and assumed-rank arrays Product: gcc Version: 4.10.0 Status: UNCONFIRMED Keywords: rejects-valid, wrong-code Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: burnus at gcc dot gnu.org Per https://gcc.gnu.org/onlinedocs/gfortran/SIZEOF.html, SIZEOF is an inquiry function (and GNU extension); that's in line with C_SIZEOF. However, the code doesn't reflect this. That's fixed by: --- a/gcc/fortran/intrinsic.c +++ b/gcc/fortran/intrinsic.c @@ -2768 +2768 @@ add_functions (void) - add_sym_1 ("sizeof", GFC_ISYM_SIZEOF, CLASS_IMPURE, ACTUAL_NO, BT_INTEGER, ii, + add_sym_1 ("sizeof", GFC_ISYM_SIZEOF, CLASS_INQUIRY, ACTUAL_NO, BT_INTEGER, ii, After doing so, the following test case shows that the size is wrongly calculated for assumed-rank arrays. Additionally, one should check whether c_sizeof() should be permitted in this case. It currently fails with "Error: 'x' argument of 'c_sizeof' intrinsic at (1) must be an interoperable data entity: Only explicit-size and assumed-size arrays are interoperable". One has to decipher TS29113 whether those should be permitted for c_sizeof or not. use iso_c_binding implicit none integer, pointer :: ptr(:) allocate(ptr(10)) call foo(ptr) call bar(ptr) contains subroutine foo(x) integer, dimension(:) :: x print *, sizeof(x) ! Prints EXPECTED: 40 end subroutine bar(x) integer, dimension(..) :: x print *, sizeof(x) ! WRONG: Prints 4 end end