From a2ec7c4aafbcd517eb563f1df32eedf39b27141b Mon Sep 17 00:00:00 2001 From: "Steven G. Kargl" Date: Thu, 5 Mar 2020 11:41:14 +0000 Subject: [PATCH] Fortran: ICE in gfc_code2string PR93792 A BOZ constant can not appear as a component inialiser for a derived type. gcc/fortran/ChangeLog: PR93792 * decl.c (variable_decl): If param and initializer check for BOZ, if found, output an error, set m to MATCH_ERROR and goto cleanup. gcc/testsuite/ChangeLog: PR93792 * gfortran.dg/pr93792.f90: New test. --- gcc/fortran/ChangeLog | 7 +++++++ gcc/fortran/decl.c | 11 ++++++++++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gfortran.dg/pr93792.f90 | 17 +++++++++++++++++ 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gfortran.dg/pr93792.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index e3957fb..90e1cab 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,10 @@ +2020-03-05 Steven G. Kargl + + PR fortran/93792 + * decl.c (variable_decl): If param and initializer check + for BOZ, if found, output an error, set m to MATCH_ERROR + and goto cleanup. + 2020-03-02 Andrew Benson PR fortran/93486 diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c index 7382fea..2f458c4 100644 --- a/gcc/fortran/decl.c +++ b/gcc/fortran/decl.c @@ -2929,7 +2929,16 @@ variable_decl (int elem) goto cleanup; } else if (param && initializer) - param->value = gfc_copy_expr (initializer); + { + if (initializer->ts.type == BT_BOZ) + { + gfc_error ("BOZ literal constant at %L cannot appear as an " + "initializer", &initializer->where); + m = MATCH_ERROR; + goto cleanup; + } + param->value = gfc_copy_expr (initializer); + } } /* Before adding a possible initilizer, do a simple check for compatibility diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 7dcc80d..851e0e9 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2020-03-05 Mark Eggleston + + PR fortran/93792 + * gfortran.dg/pr93792.f90: New test. + 2020-03-05 Delia Burduv * gcc.target/arm/simd/bf16_ma_1.c: New test. diff --git a/gcc/testsuite/gfortran.dg/pr93792.f90 b/gcc/testsuite/gfortran.dg/pr93792.f90 new file mode 100644 index 0000000..960d050 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr93792.f90 @@ -0,0 +1,17 @@ +! { dg-do compile } +! Original test case by Gernhard Steinmetz. + +module m + type t(n) + integer, len :: n = z'1' + end type +end +program p + use m + type(t(:)), allocatable :: z +end + +! { dg-error "Parameterized type 't' does not have a component" " " { target *-*-* } 5 } +! { dg-error "BOZ literal constant at .1. cannot appear" " " { target *-*-* } 6 } +! { dg-error "Cannot open module file" " " { target *-*-* } 10 } +! { dg-excess-errors "compilation terminated" } -- 2.7.4