[Regression,Fortran] ICE: Invalid expression in gfc_element_size PR93601

Message ID 2a20bfff-f7df-3942-3790-7f08b5bd97b1@codethink.co.uk
State New
Headers show
Series
  • [Regression,Fortran] ICE: Invalid expression in gfc_element_size PR93601
Related show

Commit Message

Mark Eggleston Feb. 17, 2020, 2:07 p.m.
Please find attached a fix for PR93601.

gcc/fortran/ChangeLogs

     Steven G. Kargl  <kargl@gcc.gnu.org>

     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/ChangeLogs

     Mark Eggleston  <mark.eggleston@codethink.com>

     PR fortran/93601
     * gfortran.dg/pr93601.f90 : New test.

Test using make with check-fortran on master at

https://gcc.gnu.org/g:f82617f229b336d856c18313339b14657e05c129

OK to commit?

-- 
https://www.codethink.co.uk/privacy.html

Comments

Thomas Koenig Feb. 17, 2020, 10:06 p.m. | #1
Hi Mark and Steve,

> OK to commit?


Yes. Again, thanks a lot!

Regards

	Thomas

Patch

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

diff --git a/gcc/fortran/match.c b/gcc/fortran/match.c
index a74cb8c5c19..5713dc20180 100644
--- a/gcc/fortran/match.c
+++ b/gcc/fortran/match.c
@@ -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.  */
diff --git a/gcc/testsuite/gfortran.dg/pr93601.f90 b/gcc/testsuite/gfortran.dg/pr93601.f90
new file mode 100644
index 00000000000..495447c637b
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr93601.f90
@@ -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