From: Steven G. Kargl Date: Wed, 10 Jan 2018 21:31:43 +0000 (+0000) Subject: [multiple changes] X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=266404a8d62b99ab6dd6579bbd33fca32e91ca3b;p=gcc.git [multiple changes] 2018-01-10 Steven G. Kargl PR fortran/83093 * resolve.c (resolve_charlen): Check the type of cl->length after resolution. 2018-01-10 Steven G. Kargl PR fortran/83093 * gfortran.dg/allocate_with_typespec_7.f90: New test. From-SVN: r256455 --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 05ea28ec69f..6bad1a6e1d2 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2018-01-10 Steven G. Kargl + + PR fortran/83093 + * resolve.c (resolve_charlen): Check the type of cl->length + after resolution. + 2018-01-10 Janne Blomqvist PR fortran/83740 diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index 57155cddf68..195048354a8 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -11664,10 +11664,17 @@ resolve_charlen (gfc_charlen *cl) specification_expr = saved_specification_expr; return false; } + + /* cl->length has been resolved. It should have an integer type. */ + if (cl->length->ts.type != BT_INTEGER) + { + gfc_error ("Scalar INTEGER expression expected at %L", + &cl->length->where); + return false; + } } else { - if (!resolve_index_expr (cl->length)) { specification_expr = saved_specification_expr; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 5fdb4701b06..825224d8e58 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-01-10 Steven G. Kargl + + PR fortran/83093 + * gfortran.dg/allocate_with_typespec_7.f90: New test. + 2018-01-10 Peter Bergner PR target/83399 diff --git a/gcc/testsuite/gfortran.dg/allocate_with_typespec_7.f90 b/gcc/testsuite/gfortran.dg/allocate_with_typespec_7.f90 new file mode 100644 index 00000000000..feb6c8c16cf --- /dev/null +++ b/gcc/testsuite/gfortran.dg/allocate_with_typespec_7.f90 @@ -0,0 +1,14 @@ +! { dg-do compile } +! PR Fortran/83093 +! Contributed by Gerhard Steinmetz +program p + integer, parameter :: n(2) = [1,2] + real :: x = 2 + character(:), allocatable :: z, zz, zzz + character(:), allocatable :: y, yy + allocate (character(a) :: z) ! { dg-error "Scalar INTEGER expression" } + allocate (character(x) :: zz) ! { dg-error "Scalar INTEGER expression" } + allocate (character((1.0)) :: z) ! { dg-error "Scalar INTEGER expression" } + allocate (character(y) :: y) ! { dg-error "Scalar INTEGER expression" } + allocate (character(n(1:2)) :: y)! { dg-error "Scalar INTEGER expression" } +end