This code with negative dimension(s) in shape sh : $ cat z1.f90 program p integer, parameter :: sh(2) = [2, -2] integer, parameter :: a(2,2) = reshape([1, 2, 3, 4], sh) print *, a end $ gfortran -g -O0 -Wall -fcheck=all z1.f90 f951: internal compiler error: in gfc_simplify_reshape, at fortran/simplify.c:5091 --- $ cat z4.f90 program p integer, parameter :: sh(2) = -2 integer, parameter :: a(2,2) = reshape([1, 2, 3, 4], sh) print *, a end $ gfortran -g -O0 -Wall -fcheck=all z4.f90 f951: internal compiler error: in gfc_simplify_reshape, at fortran/simplify.c:5091
Detected, but pointing to the line before : $ cat z3.f90 program p integer, parameter :: sh(2) = [2, 2] integer, parameter :: a(2,2) = reshape([1, 2, 3, 4], -sh) print *, a end $ gfortran -g -O0 -Wall -fcheck=all z3.f90 z3.f90:2:34: integer, parameter :: sh(2) = [2, 2] 1 Error: 'shape' argument of 'reshape' intrinsic at (1) has negative element (-2)
Confirmed from 4.8 up to trunk (6.0). Note that the error emitted for the code in comment 1 is quite misleading.
This one is interesting. gfc_check_reshape isn't checking 'sh' because it thinks 'sh' is a variable instead of a named constant. So, when gfc_simplify_reshape is called, it runs into an gcc_assert that the element is greater than zero because gfc_check_reshape should have emitted an error. If the gcc_assert is removed, an error message is generated.
I have a patch.
Author: kargl Date: Sat Nov 7 20:18:17 2015 New Revision: 229939 URL: https://gcc.gnu.org/viewcvs?rev=229939&root=gcc&view=rev Log: 2015-11-07 Steven G. Kargl <kargl@gcc.gnu.org> PR fortran/68153 * check.c (gfc_check_reshape): Improve check for valid SHAPE argument. 2015-11-07 Steven G. Kargl <kargl@gcc.gnu.org> PR fortran/68153 * gfortran.dg/pr68153.f90: New test. Added: trunk/gcc/testsuite/gfortran.dg/pr68153.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/check.c trunk/gcc/testsuite/ChangeLog
Author: kargl Date: Sun Nov 8 17:53:36 2015 New Revision: 229958 URL: https://gcc.gnu.org/viewcvs?rev=229958&root=gcc&view=rev Log: 2015-11-08 Steven G. Kargl <kargl@gcc.gnu.org> PR fortran/68153 * check.c (gfc_check_reshape): Improve check for valid SHAPE argument. 2015-11-08 Steven G. Kargl <kargl@gcc.gnu.org> PR fortran/68153 * gfortran.dg/pr68153.f90: New test. Added: branches/gcc-5-branch/gcc/testsuite/gfortran.dg/pr68153.f90 Modified: branches/gcc-5-branch/gcc/fortran/ChangeLog branches/gcc-5-branch/gcc/fortran/check.c branches/gcc-5-branch/gcc/testsuite/ChangeLog
Fixed on trunk and 5-branch. Thanks for the bug report.