using GNU Fortran 95 (GCC) 4.1.0 20051126 (prerelease) with '-g -pedantic -std=f95', I get a bad / no diagnostic for the following invalid code: INTEGER, PARAMETER :: K(2)=1 SELECT CASE(I) CASE(MAXLOC(K,1)) END SELECT END
What broken here? Where are the details?
(In reply to comment #1) > What broken here? Where are the details? I wondered that as well for a while. The problem, IIUC is that the case-selector must be an initialization expression. I'm no language lawyer, but if I understand the F2003 (draft) standard, MAXLOC(k,1), where 'k' is a PARAMETER, ought to be a perfectly valid initialization expression. The standard, section 7.1.7, says on initialization expressions: "It is an expression in which each operation is intrinsic, and each primary is [...] (5) A reference to a transformational standard intrinsic function other than NULL, where each argument is an initialization expression," MAXLOC, is, AFAIK, a transformational standard intrinsic, and 'k' and 1 are, AFAIK, initialization expressions. It turns out, however, that the F95 standard has a slightly different definition of initialization expressions (in section 7.1.6.1); it seems that MAXLOC is not allowed here. So it seems the code is still invalid F95, and we should give a warning/error message if strict F95 standard checking is requested. I must, however, say, that I find it a bit wierd that MAXLOC isn't allowed in this context, so I'm not sure what to think here ... I leave this as unconfirmed for now.
(In reply to comment #2) > context, so I'm not sure what to think here ... I leave this as unconfirmed > for now. Ifort 8.1 reports the following error: In a CASE statement, the case-value must be a constant expression. [MAXLOC] CASE(MAXLOC(K,1)) -----^ Which agrees with my interpretation of the F95 standard. And now when I actually try it in gfortran (:-)), I get an ICE: erik:~$ gfortran huj.f90 huj.f90: In function 'MAIN__': huj.f90:1: internal compiler error: in gfc_conv_constant_to_tree, at fortran/trans-const.c:276 Confirmed as 'ice-on-invalid'.
Yes, we are not rejecting this early enough so we get the ICE in the trans* functions.
Well, the testcase is valid F2003 but not valid F95. We have to get it working (for F2003 mode), which probably means adding a simplification function for MAXLOC. And the same is true for all the intrinsics allowed by F2003 in an initialization expression. But we also have to get it rejected in F95 mode, which means keeping an explicit list of the intrinsics that are allowed in initialization expressions in F95, under the rules of 7.1.6.1 (all subcases a to e of case #7). I see two options here: either we add a property for all intrinsics, define it in the list and use that (lots of changes and thinking) or we add a new function valid_intrinsic_in_init_expr(). I'd prefer the second option, and will be thinking of something along these lines.
Paul Thomas proposed a patch that fixes the F95 problem. We still need to write simplification routines to enable such code (which is valid F2003) to compile with gfortran. I don't have time for that right now.
If someone acts on FX's suggestion, Bug 32035 might also be tackeled at the same time... Philippe
change the keyword, as the error is now generated for std=f95 but the code is rejected for std=f2003
Subject: Bug 25104 Author: dfranke Date: Mon Jul 23 20:35:03 2007 New Revision: 126858 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=126858 Log: gcc/fortran: 2007-07-23 Daniel Franke <franke.daniel@gmail.com> PR fortran/25104 PR fortran/31639 * expr.c (check_transformational): Reject valid transformational intrinsics to avoid ICE. (check_inquiry): Report error for assumed character lengths for all supported standards. (check_init_expr): Whitespace fix. gcc/testsuite: 2007-07-23 Daniel Franke <franke.daniel@gmail.com> PR fortran/31639 * gfortran.dg/initialization_9.f90: New test. Added: trunk/gcc/testsuite/gfortran.dg/initialization_9.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/expr.c trunk/gcc/testsuite/ChangeLog
Commit shown in comment #9 restores the situation as described in comment #8, no further development yet.
Subject: Bug 25104 Author: dfranke Date: Tue Mar 31 20:01:51 2009 New Revision: 145369 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=145369 Log: gcc/fortran/: 2009-03-31 Daniel Franke <franke.daniel@gmail.com> PR fortran/25104 PR fortran/29962 * intrinsic.h (gfc_simplify_dot_product): New prototype. (gfc_simplify_matmul): Likewise. (gfc_simplify_transpose): Likewise. * intrinsic.c (add_functions): Added new simplifier callbacks. * simplify.c (init_result_expr): New. (compute_dot_product): New. (gfc_simplify_dot_product): New. (gfc_simplify_matmul): New. (gfc_simplify_transpose): New. * expr.c (check_transformational): Allow transformational intrinsics with simplifier in initialization expression. gcc/testsuite/: 2009-03-31 Daniel Franke <franke.daniel@gmail.com> PR fortran/25104 PR fortran/29962 * gfortran.dg/dot_product_1.f03: New. * gfortran.dg/matmul_8.f03: New. * gfortran.dg/transpose_3.f03: New. Added: branches/fortran-dev/gcc/testsuite/gfortran.dg/dot_product_1.f03 branches/fortran-dev/gcc/testsuite/gfortran.dg/matmul_8.f03 branches/fortran-dev/gcc/testsuite/gfortran.dg/transpose_3.f03 Modified: branches/fortran-dev/gcc/fortran/ChangeLog.dev branches/fortran-dev/gcc/fortran/expr.c branches/fortran-dev/gcc/fortran/intrinsic.c branches/fortran-dev/gcc/fortran/intrinsic.h branches/fortran-dev/gcc/fortran/simplify.c branches/fortran-dev/gcc/testsuite/ChangeLog.fortran-dev
Subject: Bug 25104 Author: dfranke Date: Sun Apr 5 20:40:13 2009 New Revision: 145573 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=145573 Log: gcc/fortran/: 2009-04-05 Daniel Franke <franke.daniel@gmail.com> PR fortran/25104 PR fortran/29962 * check.c (gfc_check_all_any): Check rank of DIM. (gfc_check_count): Likewise. * intrinsic.h (gfc_simplify_all): New prototype. (gfc_simplify_any): Likewise. (gfc_simplify_count): Likewise. (gfc_simplify_sum): Likewise. (gfc_simplify_product): Likewise. * intrinsic.c (add_functions): Added new simplifier callbacks. * simplify.c (transformational_result): New. (simplify_transformation_to_scalar): New. (simplify_transformation_to_array): New. (gfc_count): New. (gfc_simplify_all): New. (gfc_simplify_any): New. (gfc_simplify_count): New. (gfc_simplify_sum): New. (gfc_simplify_product): New. * expr.c (check_transformational): Allow additional transformational intrinsics in initialization expression. gcc/testsuite/: 2009-04-05 Daniel Franke <franke.daniel@gmail.com> PR fortran/25104 PR fortran/29962 * gfortran.dg/count_init_expr.f03 * gfortran.dg/product_init_expr.f03 * gfortran.dg/sum_init_expr.f03 Added: branches/fortran-dev/gcc/testsuite/gfortran.dg/count_init_expr.f03 branches/fortran-dev/gcc/testsuite/gfortran.dg/product_init_expr.f03 branches/fortran-dev/gcc/testsuite/gfortran.dg/sum_init_expr.f03 Modified: branches/fortran-dev/gcc/fortran/ChangeLog.dev branches/fortran-dev/gcc/fortran/check.c branches/fortran-dev/gcc/fortran/expr.c branches/fortran-dev/gcc/fortran/intrinsic.c branches/fortran-dev/gcc/fortran/intrinsic.h branches/fortran-dev/gcc/fortran/simplify.c branches/fortran-dev/gcc/testsuite/ChangeLog.fortran-dev
Subject: Bug 25104 Author: dfranke Date: Fri Apr 10 14:04:16 2009 New Revision: 145907 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=145907 Log: gcc/fortran/: 2009-04-10 Daniel Franke <franke.daniel@gmail.com> PR fortran/25104 PR fortran/29962 * array.c (gfc_append_constructor): Added NULL-check. * check.c (gfc_check_spread): Check DIM. (gfc_check_unpack): Check that the ARRAY arguments provides enough values for MASK. * intrinsic.h (gfc_simplify_spread): New prototype. (gfc_simplify_unpack): Likewise. * intrinsic.c (add_functions): Added new simplifier callbacks. * simplify.c (gfc_simplify_spread): New. (gfc_simplify_unpack): New. * expr.c (check_transformational): Allow additional transformational intrinsics in initialization expression. gcc/testsuite/: 2009-04-10 Daniel Franke <franke.daniel@gmail.com> PR fortran/25104 PR fortran/29962 * gfortran.dg/spread_init_expr.f03: New. * gfortran.dg/unpack_init_expr.f03: New. * gfortran.dg/intrinsic_argument_conformance_2.f90: Adjusted error message. Added: branches/fortran-dev/gcc/testsuite/gfortran.dg/spread_init_expr.f03 branches/fortran-dev/gcc/testsuite/gfortran.dg/unpack_init_expr.f03 Modified: branches/fortran-dev/gcc/fortran/ChangeLog.dev branches/fortran-dev/gcc/fortran/array.c branches/fortran-dev/gcc/fortran/check.c branches/fortran-dev/gcc/fortran/expr.c branches/fortran-dev/gcc/fortran/intrinsic.c branches/fortran-dev/gcc/fortran/intrinsic.h branches/fortran-dev/gcc/fortran/simplify.c branches/fortran-dev/gcc/testsuite/ChangeLog.fortran-dev branches/fortran-dev/gcc/testsuite/gfortran.dg/intrinsic_argument_conformance_2.f90
Could the patches in comments #11 to #13 be applied to trunk too?
> Could the patches in comments #11 to #13 be applied to trunk too? They can and will, but there are at least two more coming and I want to have and test them together before moving them over to trunk.
Subject: Bug 25104 Author: burnus Date: Sun Jun 7 11:53:21 2009 New Revision: 148243 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=148243 Log: 2009-06-07 Daniel Franke <franke.daniel@gmail.com> PR fortran/25104 PR fortran/29962 * intrinsic.h (gfc_simplify_dot_product): New prototype. (gfc_simplify_matmul): Likewise. (gfc_simplify_transpose): Likewise. * intrinsic.c (add_functions): Added new simplifier callbacks. * simplify.c (init_result_expr): New. (compute_dot_product): New. (gfc_simplify_dot_product): New. (gfc_simplify_matmul): New. (gfc_simplify_transpose): New. * expr.c (check_transformational): Allow transformational * intrinsics with simplifier in initialization expression. 2009-06-07 Daniel Franke <franke.daniel@gmail.com> PR fortran/25104 PR fortran/29962 * gfortran.dg/dot_product_1.f03: New. * gfortran.dg/matmul_8.f03: New. * gfortran.dg/transpose_3.f03: New. Added: trunk/gcc/testsuite/gfortran.dg/dot_product_1.f03 trunk/gcc/testsuite/gfortran.dg/matmul_8.f03 trunk/gcc/testsuite/gfortran.dg/transpose_3.f03 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/expr.c trunk/gcc/fortran/intrinsic.c trunk/gcc/fortran/intrinsic.h trunk/gcc/fortran/simplify.c trunk/gcc/testsuite/ChangeLog
Subject: Bug 25104 Author: burnus Date: Sun Jun 7 16:35:06 2009 New Revision: 148249 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=148249 Log: 2009-06-07 Daniel Franke <franke.daniel@gmail.com> PR fortran/25104 PR fortran/29962 * check.c (gfc_check_all_any): Check rank of DIM. (gfc_check_count): Likewise. * intrinsic.h (gfc_simplify_all): New prototype. (gfc_simplify_any): Likewise. (gfc_simplify_count): Likewise. (gfc_simplify_sum): Likewise. (gfc_simplify_product): Likewise. * intrinsic.c (add_functions): Added new simplifier callbacks. * simplify.c (transformational_result): New. (simplify_transformation_to_scalar): New. (simplify_transformation_to_array): New. (gfc_count): New. (gfc_simplify_all): New. (gfc_simplify_any): New. (gfc_simplify_count): New. (gfc_simplify_sum): New. (gfc_simplify_product): New. * expr.c (check_transformational): Allow additional * transformational intrinsics in initialization expression. 2009-06-07 Daniel Franke <franke.daniel@gmail.com> PR fortran/25104 PR fortran/29962 * gfortran.dg/count_init_expr.f03 * gfortran.dg/product_init_expr.f03 * gfortran.dg/sum_init_expr.f03 Added: trunk/gcc/testsuite/gfortran.dg/count_init_expr.f03 trunk/gcc/testsuite/gfortran.dg/product_init_expr.f03 trunk/gcc/testsuite/gfortran.dg/sum_init_expr.f03 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/check.c trunk/gcc/fortran/expr.c trunk/gcc/fortran/intrinsic.c trunk/gcc/fortran/intrinsic.h trunk/gcc/fortran/simplify.c trunk/gcc/testsuite/ChangeLog
Subject: Bug 25104 Author: burnus Date: Sun Jun 7 17:33:34 2009 New Revision: 148250 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=148250 Log: 2009-06-07 Daniel Franke <franke.daniel@gmail.com> PR fortran/25104 PR fortran/29962 * array.c (gfc_append_constructor): Added NULL-check. * check.c (gfc_check_spread): Check DIM. (gfc_check_unpack): Check that the ARRAY arguments provides enough values for MASK. * intrinsic.h (gfc_simplify_spread): New prototype. (gfc_simplify_unpack): Likewise. * intrinsic.c (add_functions): Added new simplifier callbacks. * simplify.c (gfc_simplify_spread): New. (gfc_simplify_unpack): New. * expr.c (check_transformational): Allow additional * transformational intrinsics in initialization expression. 2009-06-07 Daniel Franke <franke.daniel@gmail.com> PR fortran/25104 PR fortran/29962 * gfortran.dg/spread_init_expr.f03: New. * gfortran.dg/unpack_init_expr.f03: New. * gfortran.dg/intrinsic_argument_conformance_2.f90: Adjusted error message. Added: trunk/gcc/testsuite/gfortran.dg/spread_init_expr.f03 trunk/gcc/testsuite/gfortran.dg/unpack_init_expr.f03 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/array.c trunk/gcc/fortran/check.c trunk/gcc/fortran/expr.c trunk/gcc/fortran/intrinsic.c trunk/gcc/fortran/intrinsic.h trunk/gcc/fortran/simplify.c trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/gfortran.dg/intrinsic_argument_conformance_2.f90
Unassigning myself.
The test in comment #0 now gives (with/without -std=g95) pr25104.f90:3.5: CASE(MAXLOC(K,1)) 1 Error: transformational intrinsic 'maxloc' at (1) is not permitted in an initialization expression for 4.4.4, 4.5.0, and trunk. I think this wrong without -std=f95 (see pr45689).
Duplicate of pr45689. *** This bug has been marked as a duplicate of bug 45689 ***