[Bug fortran/115150] [12/13/14/15 Regression] SHAPE of zero-sized array yields a negative value

2024-05-19 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115150

--- Comment #2 from GCC Commits  ---
The master branch has been updated by Tobias Burnus :

https://gcc.gnu.org/g:b701306a9b38bd74cdc26c7ece5add22f2203b56

commit r15-658-gb701306a9b38bd74cdc26c7ece5add22f2203b56
Author: Tobias Burnus 
Date:   Mon May 20 08:34:48 2024 +0200

Fortran: Fix SHAPE for zero-size arrays

PR fortran/115150

gcc/fortran/ChangeLog:

* trans-intrinsic.cc (gfc_conv_intrinsic_bound): Fix SHAPE
for zero-size arrays

gcc/testsuite/ChangeLog:

* gfortran.dg/shape_12.f90: New test.

[Bug fortran/115150] [12/13/14/15 Regression] SHAPE of zero-sized array yields a negative value

2024-05-18 Thread burnus at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115150

Tobias Burnus  changed:

   What|Removed |Added

   Target Milestone|--- |12.5
 CC||sandra at gcc dot gnu.org

--- Comment #1 from Tobias Burnus  ---
Looking at the dump, GCC 11 has:
  _gfortran_shape_4 (&parm.3, D.3966);
while GCC 12 has:
  x[S.3] = (integer(kind=4)) (((unsigned int) a.dim[S.3].ubound - (unsigned
int) a.dim[S.3].lbound) + 1);

* * * *

Probably caused by:

r12-4591-g1af78e731feb93
Author: Sandra Loosemore 
Date:   Tue Oct 19 21:11:15 2021 -0700

Fortran: Fixes and additional tests for shape/ubound/size [PR94070]

This patch reimplements the SHAPE intrinsic to be inlined similarly to
LBOUND and UBOUND, instead of as a library call, to avoid an
unnecessary array copy.  Various bugs are also fixed.

gcc/fortran/
PR fortran/94070

* * *

SHAPE has:
"Result Value. The result has a value whose i-th element is equal to the extent
of dimension i of SOURCE, except that if SOURCE is assumed-rank, and associated
with an assumed-size array, the last element is equal to −1."

Thus, an example for the latter:

GCC 11.4 - good:
   0   2  -1
GCC 12 (to trunk) - wrong:
  -3   2  -1

integer :: x(10)
call f(x, -3)
contains
subroutine f(y,n)
  integer :: y(1:n,2,*)
  call g(y)
end
subroutine g(z)
  integer :: z(..)
  print *, shape(z)
end
end