https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94070
Bug ID: 94070 Summary: Assumed-rank arrays – bounds mishandled, SIZE/SHAPE/UBOUND/LBOUND Product: gcc Version: 10.0 Status: UNCONFIRMED Keywords: wrong-code Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: burnus at gcc dot gnu.org CC: jrfsousa at gmail dot com Target Milestone: --- Created attachment 47987 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=47987&action=edit assumed_rank_19_aux.c – to be used with … As found by José and reported at https://gcc.gnu.org/ml/fortran/2020-03/msg00016.html Testing shows that assumed-rank arrays are mishandled in several ways * When required by the standard, the lower bound is not always shifted to "1" – this causes misreported bounds. * Likewise, for BIND(C), the bounds are not always the expected 0. * When allocatable/pointer, the argument cannot be assumed-rank; hence, "-1" is a perfectly valid upper and lower bound and size()/shape() shall report >= 0 and not a negative value! Likewise for dim[rank-1].extent with bind(C): the value shall not be negative. See attached test case. All code which works uses STOP and assert(). All code which doesn't uses (__builtin_)print(f) diagnostic. Caveat: I hope I haven't made any mistake when writing the test code. * * * Compile with: gfortran assumed_rank_19.f90 assumed_rank_19_aux.c When using DejaGNU/before committing: use the commented ISO_Fortran_binding.h #include as otherwise the testsuite may fail to find that file.