From d5e4dab84324f3c31eeaf3bf22dd96503d34e654 Mon Sep 17 00:00:00 2001
From: Mark Eggleston <markeggleston@gcc.gnu.org>
Date: Fri, 7 Feb 2020 15:33:38 +0000
Subject: [PATCH] [Fortran] ICE: Invalid expression in gfc_element_size PR93601
ICE occurs when assigning a BOZ constant to an class(*) variable
with the allocatable attribute. Use of BOZ constants outside
data statements and int/real/dble/cmplx intrinsics is not allowed.
Original patch provided by Steven G. Kargl <kargl@gcc.gnu.org>.
gcc/fortran/ChangeLog
PR fortran/93601
* match.c (gfc_match_assignment) : Reject assignment if
the lhs stype is BT_CLASS and the rhs type is BT_BOZ.
gcc/testsuite/ChangeLog
PR fortran/93601
* gfortran.dg/pr93601.f90 : New test.
---
gcc/fortran/match.c | 10 ++++++++++
gcc/testsuite/gfortran.dg/pr93601.f90 | 7 +++++++
2 files changed, 17 insertions(+)
create mode 100644 gcc/testsuite/gfortran.dg/pr93601.f90
@@ -1348,6 +1348,16 @@ gfc_match_assignment (void)
rvalue = NULL;
m = gfc_match (" %e%t", &rvalue);
+ if (m == MATCH_YES
+ && rvalue->ts.type == BT_BOZ
+ && lvalue->ts.type == BT_CLASS)
+ {
+ m = MATCH_ERROR;
+ gfc_error ("BOZ literal constant at %L is neither a DATA statement "
+ "value nor an actual argument of INT/REAL/DBLE/CMPLX "
+ "intrinsic subprogram", &rvalue->where);
+ }
+
if (lvalue->expr_type == EXPR_CONSTANT)
{
/* This clobbers %len and %kind. */
new file mode 100644
@@ -0,0 +1,7 @@
+! { dg-do compile }
+
+program p
+ class(*), allocatable :: z
+ z = z'1' ! { dg-error "BOZ literal constant at" }
+end
+
--
2.11.0