diff options
author | Paul Thomas <pault@gcc.gnu.org> | 2005-12-18 14:01:00 +0000 |
---|---|---|
committer | Paul Thomas <pault@gcc.gnu.org> | 2005-12-18 14:01:00 +0000 |
commit | e7f79e123c1536f13c4fb2196ad08067f0b256fb (patch) | |
tree | 6c71e69c0e04a0262415dfa77065f7d15252abf8 /gcc/fortran | |
parent | ab9a1ff8ee9df7c87c1b1d75ab2424841694cb7b (diff) | |
download | gcc-e7f79e123c1536f13c4fb2196ad08067f0b256fb.zip gcc-e7f79e123c1536f13c4fb2196ad08067f0b256fb.tar.gz gcc-e7f79e123c1536f13c4fb2196ad08067f0b256fb.tar.bz2 |
re PR fortran/25018 (Segfault with simple expression)
2005-12-18 Paul Thomas <pault@gcc.gnu.org>
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 <pault@gcc.gnu.org>
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
Diffstat (limited to 'gcc/fortran')
-rw-r--r-- | gcc/fortran/ChangeLog | 11 | ||||
-rw-r--r-- | gcc/fortran/expr.c | 32 |
2 files changed, 37 insertions, 6 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 98e624a..8dbcc23 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,14 @@ +2005-12-18 Paul Thomas <pault@gcc.gnu.org> + + 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 <kargls@comcast.net> Tobias Schlueter <tobias.schlueter@physik.uni-muenchen.de> diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c index 1ceec01..c1451e3 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); |