While playing with modifications of PR4581, I tried module m implicit none type t integer :: i end type t type(t), dimension(2), parameter :: a1 = (/ t(1), t(2) /) type(t), dimension(2), parameter :: d = cshift ( a1, 1 ) end module m and got pr45081_red.f90:7.43: type(t), dimension(2), parameter :: d = cshift ( a1, 1 ) 1 Error: transformational intrinsic 'cshift' at (1) is not permitted in an initialization expression The F2003 standard says: (5) A reference to a transformational standard intrinsic function other than NULL, where each argument is an initialization expression, and the F2008 version adds: (6) a reference to a transformational standard intrinsic function other than COMMAND ARGUMENT -COUNT, NULL, NUM IMAGES, THIS IMAGE, where each argument is a constant expression, This is fixed by the following patch: --- ../_clean/gcc/fortran/expr.c 2010-09-09 21:06:18.000000000 +0200 +++ gcc/fortran/expr.c 2010-09-16 12:24:49.000000000 +0200 @@ -2329,7 +2329,7 @@ check_transformational (gfc_expr *e) }; static const char * const trans_func_f2003[] = { - "all", "any", "count", "dot_product", "matmul", "null", "pack", + "all", "any", "count", "cshift", "dot_product", "eoshift", "matmul", "null", "pack", "product", "repeat", "reshape", "selected_char_kind", "selected_int_kind", "selected_real_kind", "spread", "sum", "transfer", "transpose", "trim", "unpack", NULL but then I am back to PR45081!-(even with the Paul's patch).
pasto!-(
They are not, as there, afaik, are no simplifiers yet. Hence, with your patch they will be accepted, but you'd end up with wrong code at the end, as the functions are not properly simplified and thus not constant.
MAXLOC and MINLOC are also missing (see pr25104). > They are not, as there, afaik, are no simplifiers yet. > > Hence, with your patch they will be accepted, but you'd end up with wrong code > at the end, as the functions are not properly simplified and thus not constant. I have seen that, and also in gcc/fortran/simplify.c /* FIXME: Returning here avoids a regression in array_simplify_1.f90. Replace NULL with gcc_unreachable() after implementing gfc_simplify_cshift(). */ Am I correct to understand that the current situation (i.e. the error message) is a temporary fix for some missing gfc_simplify_*?
(In reply to comment #3) > Am I correct to understand that the current situation (i.e. the error message) > is a temporary fix for some missing gfc_simplify_*? If the error message you refer to is > Error: transformational intrinsic 'cshift' at (1) is not permitted in an > initialization expression then yes.
Related or duplicate of PR52473.
From http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29962#c20 Transformational intrinsics, done are: * all, any, count * product, sum * dot_product, matmul, transpose * pack, unpack, spread Left: * maxloc, minloc * maxval, minval (generic case) * cshift, eoshift While at it, see also PR29600 (kind arguments) and PR36313 (character type). Earlier this year, I was working on the cshift/eoshift, but I strongly believe that the linear list that builds the constructor must be replaced with splay trees before this can be implemented somewhat efficiently. I think what is left in pr29962 is a duplicate of this one.
*** Bug 29962 has been marked as a duplicate of this bug. ***
*** Bug 25104 has been marked as a duplicate of this bug. ***
Partial fix done at revision r230709.
Still to be done: Simplification for maxloc/minloc/maxval/minval for character arguments. Apart from that, I think we are done (but I will check before closing :-)
> Still to be done: Simplification for maxloc/minloc/maxval/minval > for character arguments. > > Apart from that, I think we are done (but I will check before > closing :-) From https://gcc.gnu.org/ml/fortran/2015-11/msg00120.html I see > The attached patch provides a partial implementation for > the simplification for CSHIFT. It is partial in that it > only applies to rank 1 arrays. For arrays with rank > 1, > gfc_simplify_cshift will issue an error. Here, the intent > is that hopefully someone that knows what they are doing > with supply a patch for rank > 1. Is it still true?
Still a lot of cases missing. None of the following are simplified: program main integer, dimension(4), parameter :: b = [1,2,3,4] integer, dimension(4), parameter :: beo = eoshift(b,1) integer, dimension(2,2), parameter :: a = reshape([1,2,3,4],shape(a)) integer, dimension(2,2), parameter :: eo2 = eoshift(a,shift=1,dim=1) integer, dimension(2,2), parameter :: cs2 = cshift(a,shift=1,dim=1) integer, dimension(2), parameter :: miv = minval(a,dim=1) integer, dimension(2), parameter :: mav = maxval(a,dim=1) integer, dimension(2), parameter :: mil = minloc(a,dim=1) integer, dimension(2), parameter :: mal = maxloc(a,dim=1) end program main
Created attachment 42822 [details] Patch which extends minval/maxval This looks promising - it just removes the special handling of maxval (which is incomplete), replacing it with the general implementation.
Author: tkoenig Date: Mon Dec 11 17:39:07 2017 New Revision: 255542 URL: https://gcc.gnu.org/viewcvs?rev=255542&root=gcc&view=rev Log: 2017-12-11 Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/45689 * simplify.c (min_max_choose): Add prototype. (gfc_count): Format correctly. (simplify_transformation): Pass array argument to init_result_expr. (gfc_simplify_minval_maxval): Remove. (gfc_min): New function. (gfc_simplify_minval): Call simplify_transformation. (gfc_max): New function. (gfc_simplify_maxval): Call simplify_transformation. 2017-12-11 Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/45689 * gfortran.dg/minval_parameter_1.f90: New test. * gfortran.dg/maxval_parameter_1.f90: New test. Added: trunk/gcc/testsuite/gfortran.dg/maxval_parameter_1.f90 trunk/gcc/testsuite/gfortran.dg/minval_parameter_1.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/simplify.c trunk/gcc/testsuite/ChangeLog
Created attachment 42976 [details] Patch which works for minloc(...,dim=1) for rank-one arrays This is a proof-of-concept patch for minloc which works for one of the three cases that need to be looked at, i.e. minloc(rank_one_array,dim=1) Still missing are minloc(arbitray_array) and minloc(arbitrary_array,dim=xx)
Author: tkoenig Date: Tue Jan 2 17:51:26 2018 New Revision: 256084 URL: https://gcc.gnu.org/viewcvs?rev=256084&root=gcc&view=rev Log: 2018-01-02 Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/45689 PR fortran/83650 * simplify.c (gfc_simplify_cshift): Re-implement to allow full range of arguments. 2018-01-02 Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/45689 PR fortran/83650 * gfortran.dg/simplify_cshift_1.f90: Correct erroneous case. * gfortran.dg/simplify_cshift_4.f90: New test. Added: trunk/gcc/testsuite/gfortran.dg/simplify_cshift_4.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/simplify.c trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/gfortran.dg/simplify_cshift_1.f90
Author: tkoenig Date: Tue Jan 2 18:14:04 2018 New Revision: 256088 URL: https://gcc.gnu.org/viewcvs?rev=256088&root=gcc&view=rev Log: 2017-01-02 Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/45689 * intrinsic.c (add_function): Add gfc_simplify_maxloc and gfc_simplify_minloc to maxloc and minloc, respectively. * intrinsic.h: Add prototypes for gfc_simplify_minloc and gfc_simplify_maxloc. * simplify.c (min_max_chose): Adjust prototype. Modify function to have a return value which indicates if the extremum was found. (is_constant_array_expr): Fix typo in comment. (simplify_minmaxloc_to_scalar): New function. (simplify_minmaxloc_nodim): New function. (new_array): New function. (simplify_minmaxloc_to_array): New function. (gfc_simplify_minmaxloc): New function. (simplify_minloc): New function. (simplify_maxloc): New function. 2017-01-02 Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/45689 * gfortran.dg/minloc_4.f90: New test case. * gfortran.dg/maxloc_4.f90: New test case. Added: trunk/gcc/testsuite/gfortran.dg/maxloc_4.f90 trunk/gcc/testsuite/gfortran.dg/minloc_4.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/intrinsic.c trunk/gcc/fortran/intrinsic.h trunk/gcc/fortran/simplify.c
Author: tkoenig Date: Thu Jan 4 21:04:23 2018 New Revision: 256265 URL: https://gcc.gnu.org/viewcvs?rev=256265&root=gcc&view=rev Log: 2018-01-04 Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/83683 PR fortran/45689 * check.c (gfc_check_eoshift): Check for string length and for conformance of boundary. * intrinsic.c (add_functions): Add gfc_simplify_eoshift. * intrinsic.h: Add prototype for gfc_simplify_eoshift. * simplify.c (gfc_simplify_eoshift): New function. 2018-01-04 Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/83683 PR fortran/45689 * gfortran.dg/eoshift_8.f90: New test. * gfortran.dg/simplify_eoshift_1.f90: New test. Added: trunk/gcc/testsuite/gfortran.dg/eoshift_8.f90 trunk/gcc/testsuite/gfortran.dg/simplify_eoshift_1.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/check.c trunk/gcc/fortran/intrinsic.c trunk/gcc/fortran/intrinsic.h trunk/gcc/fortran/simplify.c trunk/gcc/testsuite/ChangeLog
Fixed on trunk, closing.