We should only allow a) elemental functions b) we currently check gfc_init_expr_extensions(): /* FIXME: This should be moved into the intrinsic definitions. */ static const char * const init_expr_extensions[] = { "digits", "epsilon", "huge", "kind", "maxexponent", "minexponent", "precision", "present", "radix", "range", "selected_real_kind", "tiny", NULL }; I'm neither sure whether this is correct nor whether this is complete. See: "7.1.7 Initialization expression" in Fortran 2003 and "7.1.6.1 Constant expression" in Fortran 95. There is at least the following difference between the standards: F2003: [Allowed is] "A reference to an elemental standard intrinsic function, where each argument is an initialization expression" F95: "An initialization expression is a constant expression in which the exponentiation operation is permitted only with an integer power, and each primary is [...] (4) An elemental intrinsic function reference of type integer or character where each argument is an initialization expression of type integer or character"
I just realized I was too brief: There are three types of initialization expressions (IE): - Valid in F95 - Added as valid F2003 - Only valid as GNU extensions We need to check: - Is there a non-elemental function in the IE - Is the list in gfc_init_expr_extensions() correct: /* FIXME: This should be moved into the intrinsic definitions. */ static const char * const init_expr_extensions[] = { "digits", "epsilon", "huge", "kind", "maxexponent", "minexponent", "precision", "present", "radix", "range", "selected_real_kind", "tiny", NULL It is currently used in gfc_intrinsic_func_interface as: if (gfc_init_expr && flag && gfc_init_expr_extensions (specific)) - Do we miss some other restriction? - Do we miss another change between F95 and F2003 except that noninteger/noncharacter arguments to elemental intrinsics are allowed? - Is it possible to reach the "gfc_notify_std (GFC_STD_GNU," block, if one checks for "if (expr->ts.type != BT_INTEGER && expr->ts.type != BT_CHARACTER)" and does one allows things in F2003 which should not be allowed?
One other thing we need to change: real, parameter :: d = 2.0**0.5 1 Error: Exponent at (1) must be INTEGER for an initialization expression This is now also allowed in F2003.
Non-elemental intrinsic functions in Section 13.7 of Fortran 2003: ALL(T), ALLOCATED(I), ANY(T), ASSOCIATED(I), BIT_SIZE(I), COMMAND_ARGUMENT_COUNT(I), COUNT(T), CSHIFT(T), DIGITS(I), DOT_PRODUCT(T), EOSHIFT(T), EPSILON(I), EXTENDS_TYPE_OF(I), HUGE(I), KIND(I), LBOUND(I), LEN(I), MATMUL(T), MAXLOC(T), MAXVAL(T), MINLOC(T), MINVAL(T), NEW_LINE(I), NULL(T), PACK(T), PRECISION(I), PRESENT(I), PRODUCT(T), RADIX(I), RANGE(I), REPEAT(T), RESHAPE(T), SAME_TYPE_AS(I), SELECTED_CHAR_KIND(T), SELECTED_INT_KIND(T), SELECTED_REAL_KIND(T), SHAPE(I), SIZE(I), SPREAD(T), SUM(T), TINY(I), TRANSFER(T), TRANPOSE(T), TRIM(T), UBOUND(I), UNPACK(T), (I) = Inquiry functiony (T) = Transformational function Allowed in Fortran 2003: - elemental standard intrinsic functions (with argument = initialization expression) - transformational standard intrinsic functions (constrain: dito), not NULL() - NULL() without non-initialization expression type parameters - Inquiry function where argument is either an initialization expression - or when not needed - properties are not deferred/assumed or noninit. expr. From modules: - IEEE_SELECTED_REAL_KIND (Remark: This seems to allow command_line_argument(), but this is technically not possible! -- well, if it is not supported, "0" can be returned) Fortran 95: - elemental functions: Only with initi.expr. of integer/character type - Transformational functions: Only REPEAT, RESHAPE, SELECTED_INT_KIND, SELECTED_REAL_KIND, TRANSFER, TRIM: w/ init.expr.- - NULL - Array inquiry function but not ALLOCATED [i.e.: lbound, ubound, shape, size, ] - BIT_SIZE, LEN, KIND - Numeric inquiry function: digits, epsilon,huge,maxexponent, minexponent, precision, radix,range,tiny I don't think GFC_STD_GNU allows more than Fortran 2003 (and extra intrinsics of -std=gnu are filtered out earlier). Current problems: --------------------------- real :: p real, parameter :: x = TRANSFER('a',p) end Error: Parameter 'p' at (1) has not been declared or is a variable, which does not reduce to a constant expression Works with g95, fails with ifort, f95, sunf95. I believe this is valid in Fortran 95 (and Fortran 2003) --------------------------- real, parameter :: x = dot_product( (/1/), (/2/)) 1 Error: transformational intrinsic 'dot_product' at (1) is not permitted in an initialization expression - Should be valid in Fortran 2003 - fails also in g95, f95, ifort Presumably analogously: matmul, ... ---------------------------
Some more points (thanks to Richard Main for pointing out): Not all inquiry functions are allowed but only "specification inquiry" listed in 7.1.6: - Array inquiry (14.5.7; lbound, ubound, shape, size) - bit_size - len - kind - new_line - numeric inquiry (13.5.8, digits, epsilon, huge, maxexponent, minexponent, precision, radix, range, tiny) - type parameter inquiry (6.1.3): designator % type-parm-name (examples: a%kind, a%len, b(10)%kind, p%len) - IEEE inquiry function (14.9.1: IEEE_support_flag, IEEE_support_flag; IEEE_support_datatype, IEEE_support_denormal, IEEE_support_divide, IEEE_support_inf, IEEE_support_io, IEEE_support_nan, IEEE_support_rounding, IEEE_support_sqrt, IEEE_support_standard, IEEE_support_underflow_control
Subject: Bug number PR29962 A patch for this bug has been added to the patch tracker. The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2006-11/msg01799.html
Subject: Bug 29962 Author: burnus Date: Mon Dec 4 20:02:43 2006 New Revision: 119505 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=119505 Log: fortran/ 2006-12-04 Tobias Burnus <burnus@net-b.de> PR fortran/29962 * expr.c (check_intrinsic_op): Allow noninteger exponents for F2003. testsuite/ 2006-12-04 Tobias Burnus <burnus@net-b.de> PR fortran/29962 * initialization_4.f90: Test noninteger exponents (-std=f95). * initialization_5.f90: New test for noninteger exponents with -std=f2003 Added: trunk/gcc/testsuite/gfortran.dg/initialization_5.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/expr.c trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/gfortran.dg/initialization_4.f90
TRANSFER is rejected at initialization expression (w/ -std=f95 & f2003) but it is allowed per 7.1.6.1 Constant expression / initialization expression (F95 standard): "(5) A reference to one of the transformational functions REPEAT, RESHAPE, SELECTED_INT_KIND, SELECTED_REAL_KIND, TRANSFER, or TRIM, where each argument is an initialization expression," gfortran -std=f95 rejects it with: Evaluation of nonstandard initialization expression
Subject: Bug 29962 Author: dfranke Date: Sun Jul 22 16:31:11 2007 New Revision: 126826 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=126826 Log: gcc/fortran: 2007-07-22 Daniel Franke <franke.daniel@gmail.com> PR fortran/29962 PR fortran/31253 PR fortran/31265 PR fortran/31639 * gfortran.h (gfc_intrinsic_sym): Changed members elemental, pure, generic, specific, actual_ok, noreturn into bits of a bitfield, added bits for inquiry, transformational, conversion. * check.c (non_init_transformational): Removed, removed all callers. * intrinsic.c (enum class): New. (add_sym*): Replaced argument elemetal by enum class. Changed all callers. (add_functions): Assign appropriate classes to intrinsic functions. (add_subroutines): Assign appropriate classes to intrinsic subroutines. (add_conv): Set conversion attribute. (gfc_init_expr_extensions): Removed, removed all callers. (gfc_intrinsic_func_interface): Reimplemented check for non-standard initializatione expressions. * expr.c (check_specification_function): New. (gfc_is_constant_expr): Added check for specification functions. (check_init_expr_arguments): New. (check_inquiry): Changed return value to MATCH, added checks for inquiry functions defined by F2003. (check_transformational): New. (check_null): New. (check_elemental): New. (check_conversion): New. (check_init_expr): Call new check functions, add more specific error messages. gcc/testsuite: 2007-07-22 Daniel Franke <franke.daniel@gmail.com> PR fortran/29962 * gfortran.dg/array_initializer_1.f90: Removed warning. * gfortran.dg/initialization_1.f90: Adjusted messages. * gfortran.dg/nested_modules_6.f90: Removed warning. PR fortran/31253 * gfortran.dg/initialization_7.f90: New test. PR fortran/31639 * gfortran.dg/initialization_8.f90: New test. Added: trunk/gcc/testsuite/gfortran.dg/initialization_7.f90 trunk/gcc/testsuite/gfortran.dg/initialization_8.f90 Modified: trunk/gcc/fortran/check.c trunk/gcc/fortran/expr.c trunk/gcc/fortran/gfortran.h trunk/gcc/fortran/intrinsic.c trunk/gcc/testsuite/gfortran.dg/array_initializer_1.f90 trunk/gcc/testsuite/gfortran.dg/initialization_1.f90 trunk/gcc/testsuite/gfortran.dg/nested_modules_6.f90
Daniel, could you update the bug status; e.g. mark it as fixed or write what still needs to be done.
Changed the title as init expressions are not restricted to the previously named function. The following is a list of items I am aware of that need to be done before init expressions are complete: TODO for F95, 7.1.6.1: * nothing?! TODO for F2003, 7.1.6, Specification Inquiry: * "(7)a type parameter inquiry (6.1.3)" TODO for F2003, 7.1.7: * simplifiers for transformational intrinsics other than those listed by F95 * anything related to IEEE (see also PR29383) * "(9) A kind type parameter of the derived type being defined" Please add to this list whatever I may have missed :)
Wonderful, I just had a look at this bug. Implementing transformational functions in the compiler will be a lot of joy. See gfc_simplify_reshape for the delights this brings.
*** Bug 38205 has been marked as a duplicate of this bug. ***
Transformational intrinsics, one down: PACK (PR32890). Left: * all, any, count * maxloc, minloc * maxval, minval (generic case) * product, sum * dot_product, matmul, transpose * unpack, spread * cshift, eoshift
Subject: Bug 29962 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 29962 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 29962 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
Subject: Bug 29962 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 29962 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 29962 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
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.
Closing as duplicate of pr45689. *** This bug has been marked as a duplicate of bug 45689 ***