From: Mark Eggleston Date: Thu, 7 May 2020 07:29:14 +0000 (+0100) Subject: Fortran : ICE in gfc_conv_array_constructor_expr PR93497 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f9f98e59a7f6663f31b671c44998190079097f97;p=gcc.git Fortran : ICE in gfc_conv_array_constructor_expr PR93497 Invalid expressions, such as those involving array constructors, used for the length of character types will cause an ICE. 2020-05-13 Steven G. Kargl gcc/fortran/ PR fortran/93497 * decl.c (char_len_param_value): Check whether character length expression is of type EXPR_OP and if so simplify it. * resolve.c (resolve_charlen): Reject length if it has a rank. 2020-05-13 Mark Eggleston gcc/testsuite/ PR fortran/93497 * gfortran.dg/pr88025.f90: Change in wording of error. * gfortran.dg/pr93497.f90: New test. * gfortran.dg/pr93714_1.f90: Change in wording of errors. * gfortran.dg/pr93714_2.f90: Change in wording of errors. --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 9ce70f7b461..becfda4c5fa 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,11 @@ +2020-05-13 Steven G. Kargl + + PR fortran/93497 + * decl.c (char_len_param_value): Check whether character + length expression is of type EXPR_OP and if so simplify it. + * resolve.c (resolve_charlen): Reject length if it has a + rank. + 2020-05-13 Tobias Burnus PR fortran/94690 diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c index d650407da41..9cc81361f43 100644 --- a/gcc/fortran/decl.c +++ b/gcc/fortran/decl.c @@ -1077,6 +1077,11 @@ char_len_param_value (gfc_expr **expr, bool *deferred) if (!gfc_expr_check_typed (*expr, gfc_current_ns, false)) return MATCH_ERROR; + /* If gfortran gets an EXPR_OP, try to simplifiy it. This catches things + like CHARACTER(([1])). */ + if ((*expr)->expr_type == EXPR_OP) + gfc_simplify_expr (*expr, 1); + if ((*expr)->expr_type == EXPR_FUNCTION) { if ((*expr)->ts.type == BT_INTEGER diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index 88ba88d8bf3..f6e10ea379c 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -12358,7 +12358,7 @@ resolve_charlen (gfc_charlen *cl) } /* cl->length has been resolved. It should have an integer type. */ - if (cl->length->ts.type != BT_INTEGER) + if (cl->length->ts.type != BT_INTEGER || cl->length->rank != 0) { gfc_error ("Scalar INTEGER expression expected at %L", &cl->length->where); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 4f602ed6f31..76b14d3c11b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2020-05-13 Mark Eggleston + + PR fortran/93497 + * gfortran.dg/pr88025.f90: Change in wording of error. + * gfortran.dg/pr93497.f90: New test. + * gfortran.dg/pr93714_1.f90: Change in wording of errors. + * gfortran.dg/pr93714_2.f90: Change in wording of errors. + 2020-05-13 Patrick Palka PR c++/70642 diff --git a/gcc/testsuite/gfortran.dg/pr88025.f90 b/gcc/testsuite/gfortran.dg/pr88025.f90 index 96172fae76a..c51390f1434 100644 --- a/gcc/testsuite/gfortran.dg/pr88025.f90 +++ b/gcc/testsuite/gfortran.dg/pr88025.f90 @@ -2,6 +2,6 @@ ! PR fortran/88025 program p type t - character(('')) :: c = 'c' ! { dg-error "must be of INTEGER type" } + character(('')) :: c = 'c' ! { dg-error "Scalar INTEGER expression expected" } end type end diff --git a/gcc/testsuite/gfortran.dg/pr93497.f90 b/gcc/testsuite/gfortran.dg/pr93497.f90 new file mode 100644 index 00000000000..612b41cd8ca --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr93497.f90 @@ -0,0 +1,8 @@ +! { dg-do compile } + +program p + print *, [character(((/1/))) :: 'a','b'] ! { dg-error "Scalar INTEGER expression expected" } + print *, [character(([1])) :: 'a','b'] ! { dg-error "Scalar INTEGER expression expected" } + print *, [character(1+[1]) :: 'a','b'] ! { dg-error "Scalar INTEGER expression expected" } +end + diff --git a/gcc/testsuite/gfortran.dg/pr93714_1.f90 b/gcc/testsuite/gfortran.dg/pr93714_1.f90 index 40f4a4bf89f..e55812c76de 100644 --- a/gcc/testsuite/gfortran.dg/pr93714_1.f90 +++ b/gcc/testsuite/gfortran.dg/pr93714_1.f90 @@ -7,5 +7,5 @@ program test character, pointer :: b => a end program -! { dg-error "must be of INTEGER type" " " { target *-*-* } 6 } -! { dg-error "does not have the TARGET attribute" " " { target *-*-* } 7 } +! { dg-error "Scalar INTEGER expression expected" " " { target *-*-* } 6 } +! { dg-error "Different types in pointer assignment" " " { target *-*-* } 7 } diff --git a/gcc/testsuite/gfortran.dg/pr93714_2.f90 b/gcc/testsuite/gfortran.dg/pr93714_2.f90 index 86658f28859..23d53508f1f 100644 --- a/gcc/testsuite/gfortran.dg/pr93714_2.f90 +++ b/gcc/testsuite/gfortran.dg/pr93714_2.f90 @@ -7,5 +7,5 @@ program test character(:), pointer :: b => a end program -! { dg-error "must be of INTEGER type" " " { target *-*-* } 6 } -! { dg-error "does not have the TARGET attribute" " " { target *-*-* } 7 } +! { dg-error "Scalar INTEGER expression expected" " " { target *-*-* } 6 } +! { dg-error "Different types in pointer assignment" " " { target *-*-* } 7 }