Fortran : ICE in gfc_check_reshape PR95585

Message ID 6899dcde-9e3c-61fb-ad89-0d852041dfd6@codethink.co.uk
State New
Headers show
Series
  • Fortran : ICE in gfc_check_reshape PR95585
Related show

Commit Message

Mark Eggleston June 18, 2020, 8:11 a.m.
Please find attached fix for PR95585.

OK to commit and backport?

Commit message:

Fortran  : ICE in gfc_check_reshape PR95585

Issue an error where an array is used before its definition
instead of an ICE.

2020-06-18  Steven G. Kargl  <kargl@gcc.gnu.org>

gcc/fortran/

     PR fortran/PR95585
     *check.c (gfc_check_reshape): Add check for a value when
     the symbol has an attribute flavor FL_PARAMETER.

2020-06-17  Mark Eggleston <markeggleston@gcc.gnu.org>

gcc/testsuite/

     PR fortran/95585
     * gfortran.dg/pr95585.f90: New test.


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

Comments

Richard Sandiford via Gcc-patches June 20, 2020, 10:22 a.m. | #1
Hi Mark,

> Please find attached fix for PR95585.

> 

> OK to commit and backport?


OK for master.

For backport: Again, I am not sure we need this, but the fix
is simple enough. So, I probably wouldn't backport this (it's not a
regression), but I'll leave that up to you.

Regards

	Thomas
Richard Sandiford via Gcc-patches July 14, 2020, 3:13 a.m. | #2
OK to commit and Backport.

On 6/18/20 1:11 AM, Mark Eggleston wrote:
> Please find attached fix for PR95585.

>

> OK to commit and backport?

>

> Commit message:

>

> Fortran  : ICE in gfc_check_reshape PR95585

>

> Issue an error where an array is used before its definition

> instead of an ICE.

>

> 2020-06-18  Steven G. Kargl  <kargl@gcc.gnu.org>

>

> gcc/fortran/

>

>     PR fortran/PR95585

>     *check.c (gfc_check_reshape): Add check for a value when

>     the symbol has an attribute flavor FL_PARAMETER.

>

> 2020-06-17  Mark Eggleston <markeggleston@gcc.gnu.org>

>

> gcc/testsuite/

>

>     PR fortran/95585

>     * gfortran.dg/pr95585.f90: New test.

>

>

Patch

From ac759f1708e6b325abdb8586ea378fe5b8a234ba Mon Sep 17 00:00:00 2001
From: Mark Eggleston <markeggleston@gcc.gnu.org>
Date: Thu, 11 Jun 2020 06:42:36 +0100
Subject: [PATCH] Fortran  : ICE in gfc_check_reshape PR95585

Issue an error where an array is used before its definition
instead of an ICE.

2020-06-18  Steven G. Kargl  <kargl@gcc.gnu.org>

gcc/fortran/

	PR fortran/PR95585
	*check.c (gfc_check_reshape): Add check for a value when
	the symbol has an attribute flavor FL_PARAMETER.

2020-06-17  Mark Eggleston  <markeggleston@gcc.gnu.org>

gcc/testsuite/

	PR fortran/95585
	* gfortran.dg/pr95585.f90: New test.
---
 gcc/fortran/check.c                   | 3 ++-
 gcc/testsuite/gfortran.dg/pr95585.f90 | 6 ++++++
 2 files changed, 8 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gfortran.dg/pr95585.f90

diff --git a/gcc/fortran/check.c b/gcc/fortran/check.c
index 0afb96c0414..992fbd77727 100644
--- a/gcc/fortran/check.c
+++ b/gcc/fortran/check.c
@@ -4739,7 +4739,8 @@  gfc_check_reshape (gfc_expr *source, gfc_expr *shape,
 	   && shape->ref->u.ar.as->lower[0]->ts.type == BT_INTEGER
 	   && shape->ref->u.ar.as->upper[0]->expr_type == EXPR_CONSTANT
 	   && shape->ref->u.ar.as->upper[0]->ts.type == BT_INTEGER
-	   && shape->symtree->n.sym->attr.flavor == FL_PARAMETER)
+	   && shape->symtree->n.sym->attr.flavor == FL_PARAMETER
+	   && shape->symtree->n.sym->value)
     {
       int i, extent;
       gfc_expr *e, *v;
diff --git a/gcc/testsuite/gfortran.dg/pr95585.f90 b/gcc/testsuite/gfortran.dg/pr95585.f90
new file mode 100644
index 00000000000..b0e6cdc5bea
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr95585.f90
@@ -0,0 +1,6 @@ 
+! { dg-do compile }
+
+program test
+  integer, parameter :: a(2) = reshape([1, 2], a) ! { dg-error "before its definition" }
+end program
+
-- 
2.11.0