From 7ac6a832c3122846bcd0aa81af47f0e62519da92 Mon Sep 17 00:00:00 2001 From: Alessandro Fanfarillo Date: Sun, 3 Jun 2012 07:21:50 -0600 Subject: [PATCH] re PR fortran/48831 (check.c: Constant expression (PARAMETER array element) rejected as nonconstant) 2012-06-03 Alessandro Fanfarillo Tobias Burnus PR fortran/48831 * gfortran.h (gfc_check_init_expr): Add prototype declaration of function. * check.c (kind_check): Change if condition to use to gfc_check_init_expr. * expr.c (check_init_expr): Remove forward declaration and static keyword. Change name in gfc_check_init_expr. 2012-06-03 Alessandro Fanfarillo PR fortran/48831 * gfortran.dg/parameter_array_element_2.f90: New. Co-Authored-By: Tobias Burnus From-SVN: r188152 --- gcc/fortran/ChangeLog | 14 ++++++++++ gcc/fortran/check.c | 2 +- gcc/fortran/expr.c | 28 ++++++++----------- gcc/fortran/gfortran.h | 1 + gcc/testsuite/ChangeLog | 5 ++++ .../gfortran.dg/parameter_array_element_2.f90 | 16 +++++++++++ 6 files changed, 48 insertions(+), 18 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/parameter_array_element_2.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index a75ab0a2c44a..a561a8c803eb 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,17 @@ +2012-06-03 Alessandro Fanfarillo + Tobias Burnus + + PR fortran/48831 + * gfortran.h (gfc_check_init_expr): Add prototype declaration + of function. + * check.c (kind_check): Change if condition to use + to gfc_check_init_expr. + * expr.c (check_init_expr): Remove forward declaration + and static keyword. Change name in gfc_check_init_expr. + (scalarize_intrinsic_call, check_init_expr_arguments, + check_inquiry, check_conversion, gfc_reduce_init_expr): Update + call to gfc_check_init_expr. + 2012-05-31 Steven Bosscher * trans-common.c: Do not include output.h. diff --git a/gcc/fortran/check.c b/gcc/fortran/check.c index afeb653a5a8f..9926f0506f62 100644 --- a/gcc/fortran/check.c +++ b/gcc/fortran/check.c @@ -163,7 +163,7 @@ kind_check (gfc_expr *k, int n, bt type) if (scalar_check (k, n) == FAILURE) return FAILURE; - if (k->expr_type != EXPR_CONSTANT) + if (gfc_check_init_expr (k) != SUCCESS) { gfc_error ("'%s' argument of '%s' intrinsic at %L must be a constant", gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic, diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c index bde62d587418..4765afa367fc 100644 --- a/gcc/fortran/expr.c +++ b/gcc/fortran/expr.c @@ -1943,12 +1943,6 @@ et0 (gfc_expr *e) } -/* Check an intrinsic arithmetic operation to see if it is consistent - with some type of expression. */ - -static gfc_try check_init_expr (gfc_expr *); - - /* Scalarize an expression for an elemental intrinsic call. */ static gfc_try @@ -1994,7 +1988,7 @@ scalarize_intrinsic_call (gfc_expr *e) for (; a; a = a->next) { /* Check that this is OK for an initialization expression. */ - if (a->expr && check_init_expr (a->expr) == FAILURE) + if (a->expr && gfc_check_init_expr (a->expr) == FAILURE) goto cleanup; rank[n] = 0; @@ -2231,7 +2225,7 @@ check_init_expr_arguments (gfc_expr *e) gfc_actual_arglist *ap; for (ap = e->value.function.actual; ap; ap = ap->next) - if (check_init_expr (ap->expr) == FAILURE) + if (gfc_check_init_expr (ap->expr) == FAILURE) return MATCH_ERROR; return MATCH_YES; @@ -2319,7 +2313,7 @@ check_inquiry (gfc_expr *e, int not_restricted) &ap->expr->where); return MATCH_ERROR; } - else if (not_restricted && check_init_expr (ap->expr) == FAILURE) + else if (not_restricted && gfc_check_init_expr (ap->expr) == FAILURE) return MATCH_ERROR; if (not_restricted == 0 @@ -2437,8 +2431,8 @@ check_conversion (gfc_expr *e) intrinsics in the context of initialization expressions. If FAILURE is returned an error message has been generated. */ -static gfc_try -check_init_expr (gfc_expr *e) +gfc_try +gfc_check_init_expr (gfc_expr *e) { match m; gfc_try t; @@ -2449,7 +2443,7 @@ check_init_expr (gfc_expr *e) switch (e->expr_type) { case EXPR_OP: - t = check_intrinsic_op (e, check_init_expr); + t = check_intrinsic_op (e, gfc_check_init_expr); if (t == SUCCESS) t = gfc_simplify_expr (e, 0); @@ -2573,11 +2567,11 @@ check_init_expr (gfc_expr *e) break; case EXPR_SUBSTRING: - t = check_init_expr (e->ref->u.ss.start); + t = gfc_check_init_expr (e->ref->u.ss.start); if (t == FAILURE) break; - t = check_init_expr (e->ref->u.ss.end); + t = gfc_check_init_expr (e->ref->u.ss.end); if (t == SUCCESS) t = gfc_simplify_expr (e, 0); @@ -2592,14 +2586,14 @@ check_init_expr (gfc_expr *e) if (t == FAILURE) break; - t = gfc_check_constructor (e, check_init_expr); + t = gfc_check_constructor (e, gfc_check_init_expr); if (t == FAILURE) break; break; case EXPR_ARRAY: - t = gfc_check_constructor (e, check_init_expr); + t = gfc_check_constructor (e, gfc_check_init_expr); if (t == FAILURE) break; @@ -2629,7 +2623,7 @@ gfc_reduce_init_expr (gfc_expr *expr) gfc_init_expr_flag = true; t = gfc_resolve_expr (expr); if (t == SUCCESS) - t = check_init_expr (expr); + t = gfc_check_init_expr (expr); gfc_init_expr_flag = false; if (t == FAILURE) diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h index 1143314db7ba..759074aa01ac 100644 --- a/gcc/fortran/gfortran.h +++ b/gcc/fortran/gfortran.h @@ -2708,6 +2708,7 @@ gfc_actual_arglist *gfc_copy_actual_arglist (gfc_actual_arglist *); const char *gfc_extract_int (gfc_expr *, int *); bool is_subref_array (gfc_expr *); bool gfc_is_simply_contiguous (gfc_expr *, bool); +gfc_try gfc_check_init_expr (gfc_expr *); gfc_expr *gfc_build_conversion (gfc_expr *); void gfc_free_ref_list (gfc_ref *); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 946fb3f59fc3..cb5c8820323d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2012-06-03 Alessandro Fanfarillo + + PR fortran/48831 + * gfortran.dg/parameter_array_element_2.f90: New. + 2012-06-03 Oleg Endo PR target/53512 diff --git a/gcc/testsuite/gfortran.dg/parameter_array_element_2.f90 b/gcc/testsuite/gfortran.dg/parameter_array_element_2.f90 new file mode 100644 index 000000000000..352ed57f545b --- /dev/null +++ b/gcc/testsuite/gfortran.dg/parameter_array_element_2.f90 @@ -0,0 +1,16 @@ +! { dg-do compile } +! PR fortran/48831 +! Contributed by Tobias Burnus + +program p1 + implicit none + integer, parameter :: i1 = kind(0) + integer, parameter :: i2(1) = [i1] + integer(kind=i2(1)) :: i3 + + i3 = int(0, i1) + print *, i3 + + i3 = int(0, i2(1)) ! This line gives an error when compiling. + print *, i3 +end program p1