From: Paul Thomas Date: Sun, 18 Dec 2005 14:01:00 +0000 (+0000) Subject: re PR fortran/25018 (Segfault with simple expression) X-Git-Tag: releases/gcc-4.2.0~5252 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e7f79e123c1536f13c4fb2196ad08067f0b256fb;p=thirdparty%2Fgcc.git re PR fortran/25018 (Segfault with simple expression) 2005-12-18 Paul Thomas PR fortran/25018 *expr.c(check_inquiry): Return FAILURE if there is no symtree to provide a name. Error/warning for assumed character length argument to LEN for an initialization expression, using GFC_GNU_STD. Add an argument to flag that the expression is not restricted. (check_init_expr): Improve the message for a failing variable. (gfc_match_init_expr): Call check_enquiry again to make sure that unsimplified expressions are not causing unnecessary errors. 2005-12-18 Paul Thomas PR fortran/25018 *gfortran.dg/initialization_1.f90: New test. *gfortran.dg/enum_5.f90: Change dg-error to new message. *gfortran.dg/g77/980616-0.f: The same. From-SVN: r108753 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 55a7b0b8d82c..b2b30097ac75 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,74 +1,3 @@ -2005-12-16 Kazu Hirata - - * parser.c, pt.c: Fix comment typos. - -2005-12-13 Petr Machata - - PR c++/24907 - * parser.c (cp_parser_simple_declaration): Require comma at the - beginning of processing second and later declarators, instead of - allowing the comma at the end of each iteration. - -2005-12-12 Mark Mitchell - - PR c++/25300 - * tree.c (build_qualified_name): Return error_mark_node for - erroneous input. - -2005-12-10 Mark Mitchell - - PR c++/25337 - * pt.c (tsubst_copy_and_build): Permit dependent types for the - object in a class member access expression. - -2005-12-10 Terry Laurenzo - - PR java/9861 - * mangle.c (write_bare_function_type): Mangle return type for - methods of Java classes - -2005-12-08 Théodore Papadopoulo - - * call.c (build_conditional_expr): Print types in error messages. - -2005-12-07 Volker Reichelt - - * expr.c (cxx_expand_expr): Call gcc_unreachable instead of abort. - -2005-12-07 Volker Reichelt - - * cp-gimplify.c (gimplify_cp_loop): Use fold_build3. - -2005-12-07 Rafael Ávila de Espíndola - - * Make-lang.in (c++.all.build, c++.install-normal): Remove. - -2005-12-07 Rafael Ávila de Espíndola - - * Make-lang.in: Remove all dependencies on s-gtype. - -2005-12-06 Aldy Hernandez - - PR C++/24138 - * decl.c (reshape_init_array_1): Handle max_index of -1. - -2005-12-06 Roger Sayle - - * typeck.c (build_binary_op): Issue warning if either operand of a - comparison operator is a string literal, except for testing equality - or inequality against NULL. - -2005-12-06 Roger Sayle - - PR c++/25263 - * decl.c (compute_array_index_type): Check that itype is an - INTEGER_CST node before testing/clearing TREE_OVERFLOW. - -2005-12-05 Daniel Berlin - - * ptree.c (cxx_print_decl): Update to check for decl_common - structure. - 2005-12-02 Mark Mitchell PR c++/24173 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 98e624a830ec..8dbcc233b448 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,14 @@ +2005-12-18 Paul Thomas + + PR fortran/25018 + *expr.c(check_inquiry): Return FAILURE if there is no symtree to + provide a name. Error/warning for assumed character length argument + to LEN for an initialization expression, using GFC_GNU_STD. Add an + argument to flag that the expression is not restricted. + (check_init_expr): Improve the message for a failing variable. + (gfc_match_init_expr): Call check_enquiry again to make sure that + unsimplified expressions are not causing unnecessary errors. + 2005-12-17 Steven G. Kargl Tobias Schlueter diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c index 1ceec01eae03..c1451e38cb01 100644 --- a/gcc/fortran/expr.c +++ b/gcc/fortran/expr.c @@ -1365,7 +1365,7 @@ not_numeric: this problem here. */ static try -check_inquiry (gfc_expr * e) +check_inquiry (gfc_expr * e, int not_restricted) { const char *name; @@ -1379,6 +1379,10 @@ check_inquiry (gfc_expr * e) int i; + /* An undeclared parameter will get us here (PR25018). */ + if (e->symtree == NULL) + return FAILURE; + name = e->symtree->n.sym->name; for (i = 0; inquiry_function[i]; i++) @@ -1407,6 +1411,15 @@ check_inquiry (gfc_expr * e) e->ts = e->symtree->n.sym->ts; } + /* Assumed character length will not reduce to a constant expression + with LEN, as required by the standard. */ + if (i == 4 && not_restricted + && e->symtree->n.sym->ts.type == BT_CHARACTER + && e->symtree->n.sym->ts.cl->length == NULL) + gfc_notify_std (GFC_STD_GNU, "assumed character length " + "variable '%s' in constant expression at %L", + e->symtree->n.sym->name, &e->where); + return SUCCESS; } @@ -1440,7 +1453,7 @@ check_init_expr (gfc_expr * e) case EXPR_FUNCTION: t = SUCCESS; - if (check_inquiry (e) != SUCCESS) + if (check_inquiry (e, 1) != SUCCESS) { t = SUCCESS; for (ap = e->value.function.actual; ap; ap = ap->next) @@ -1478,7 +1491,8 @@ check_init_expr (gfc_expr * e) break; } - gfc_error ("Variable '%s' at %L cannot appear in an initialization " + gfc_error ("Parameter '%s' at %L has not been declared or is " + "a variable, which does not reduce to a constant " "expression", e->symtree->n.sym->name, &e->where); t = FAILURE; break; @@ -1557,8 +1571,14 @@ gfc_match_init_expr (gfc_expr ** result) return MATCH_ERROR; } - if (!gfc_is_constant_expr (expr)) - gfc_internal_error ("Initialization expression didn't reduce %C"); + /* Not all inquiry functions are simplified to constant expressions + so it is necessary to call check_inquiry again. */ + if (!gfc_is_constant_expr (expr) + && check_inquiry (expr, 1) == FAILURE) + { + gfc_error ("Initialization expression didn't reduce %C"); + return MATCH_ERROR; + } *result = expr; @@ -1637,7 +1657,7 @@ static try restricted_intrinsic (gfc_expr * e) { /* TODO: Check constraints on inquiry functions. 7.1.6.2 (7). */ - if (check_inquiry (e) == SUCCESS) + if (check_inquiry (e, 0) == SUCCESS) return SUCCESS; return restricted_args (e->value.function.actual); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b7e00b9046a7..5ecdf09c40cf 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2005-12-18 Paul Thomas + + PR fortran/25018 + *gfortran.dg/initialization_1.f90: New test. + *gfortran.dg/enum_5.f90: Change dg-error to new message. + *gfortran.dg/g77/980616-0.f: The same. + 2005-12-17 Steven G. Kargl * PR fortran/25458 diff --git a/gcc/testsuite/gfortran.dg/enum_5.f90 b/gcc/testsuite/gfortran.dg/enum_5.f90 index a095cfe1bf35..9ff2efa9c5a4 100644 --- a/gcc/testsuite/gfortran.dg/enum_5.f90 +++ b/gcc/testsuite/gfortran.dg/enum_5.f90 @@ -6,7 +6,7 @@ program main integer :: i = 1 enum, bind (c) ! { dg-warning "New in Fortran 2003" } - enumerator :: red, black = i ! { dg-error "cannot appear" } + enumerator :: red, black = i ! { dg-error "is a variable" } enumerator :: blue = 1 end enum junk ! { dg-error "Syntax error" } diff --git a/gcc/testsuite/gfortran.dg/g77/980616-0.f b/gcc/testsuite/gfortran.dg/g77/980616-0.f index 75bd05e93ad6..069b611eb149 100644 --- a/gcc/testsuite/gfortran.dg/g77/980616-0.f +++ b/gcc/testsuite/gfortran.dg/g77/980616-0.f @@ -5,6 +5,6 @@ c { dg-do compile } * Date: Mon, 15 Jun 1998 21:54:32 -0500 * From: Ian A Watson * Subject: Mangler Crash - EQUIVALENCE(I,glerf(P)) ! { dg-error "cannot appear" "cannot appear" } + EQUIVALENCE(I,glerf(P)) ! { dg-error "is a variable" "is a variable" } COMMON /foo/ glerf(3) c { dg-error "end of file" "end of file" { target *-*-* } 0 } diff --git a/gcc/testsuite/gfortran.dg/initialization_1.f90 b/gcc/testsuite/gfortran.dg/initialization_1.f90 new file mode 100644 index 000000000000..f13145946aad --- /dev/null +++ b/gcc/testsuite/gfortran.dg/initialization_1.f90 @@ -0,0 +1,38 @@ +!==================initialization_1.f90====================== + +! { dg-do compile } +! Tests fix for PR25018 in which an ICE resulted from using a +! variable in a parameter initialization expression. In the course +! of developing the fix, various other constraints and limitations +! were tested. +! +! Contributed by Paul Thomas +! +module const +! The next line is the original error + real(8), parameter :: g = - sqrt(2._8) * Gf ! { dg-error "not been declared or is a variable" } +contains + subroutine foo(ch1, x, y) + character(*) :: ch1 + +! This is OK because it is a restricted expression. + character(len(ch1)) :: ch2 + + real(8) :: x (1:2, *) + real(8) :: y (0:,:) + +! However, this gives a warning because it is an initialization expression. + integer :: l1 = len (ch1) ! { dg-warning "assumed character length variable" } + +! Dependence on upper bound of final dimension of assumed size array knocks these out. + integer :: m1 = size (x, 2) ! { dg-error "not a valid dimension index" } + integer :: m2(2) = shape (x) ! { dg-error "assumed size array" } + +! These are warnings because they are gfortran extensions. + integer :: m3 = size (x, 1) ! { dg-warning "Evaluation of nonstandard initialization" } + integer :: m4(2) = shape (z) ! { dg-warning "Evaluation of nonstandard initialization" } + +! This does not depend on non-constant properties. + real(8) :: big = huge (x) + end subroutine foo +end module const