[FORTRAN] ICE in gfc_conv_array_constructor_expr PR93497

Message ID c790b549-4d3d-6a17-8cfd-786182baf29b@codethink.co.uk
State New
Headers show
Series
  • [FORTRAN] ICE in gfc_conv_array_constructor_expr PR93497
Related show

Commit Message

Mark Eggleston May 12, 2020, 3:08 p.m.
Please find attached for PR93497. This patch was posted as a comment to 
the PR, I've checked it added a test case. It has the side affect of 
changing the errors for three other test cases which have modified 
accordingly.

The commit message is as follows:

fortran : ICE in gfc_conv_array_constructor_expr PR93497

Invalid expressions, such as those involving array constructors,
used for the length of character types will cause an ICE.

2020-05-12  Steven G. Kargl  <kargl@gcc.gnu.org>

gcc/fortran/

     PR fortran/93497
     * decl.c (char_len_param_value) : Check whether character
     length expression is of type EXPR_OP and if so simplify it.
     * resolve.c (resolve_charlen) : Reject length if it has a
     rank.

2020-05-12  Mark Eggleston <markeggleston@gcc.gnu.org>

gcc/testsuite/

     PR fortran/93497
     * gfortran.dg/pr88025.f90: Change in wording of error.
     * gfortran.dg/pr93497.f90: New test.
     * gfortran.dg/pr93714_1.f90: Change in wording of errors.
     * gfortran.dg/pr93714_2.f90: Change in wording of errors.

Note: the dates will be updated as necessary when the patch is committed.

Tested using make check-fortran on x86_64 for branches master, 
releases/gcc-8, releases/gcc-9 and releases/gcc-10.

OK to commit to master and to backport to releases/gcc-8, releases/gcc-9 
and releases/gcc-10?

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

Comments

Tobias Burnus May 13, 2020, 8:54 a.m. | #1
On 5/12/20 5:08 PM, Mark Eggleston wrote:

> fortran : ICE in gfc_conv_array_constructor_expr PR93497


"F" in "Fortran". Extra space before ":".

> PR fortran/93497

>     * decl.c (char_len_param_value) : Check whether character


Likewise. (Do you like French typography? There, one uses a space before
(and after) the colon.)

> OK to commit to master and to backport to releases/gcc-8,

> releases/gcc-9 and releases/gcc-10?


Otherwise: LGTM. However, as it is just an ICE-on-invalid code, I'd
prefer if you do not backport it to GCC 8, which will soon see its last
release and then the branch will be closed.

Cheers,

Tobias

-----------------
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander Walter

Patch

From 143b9911a9c8420c9906a41b7a96376bad1753c4 Mon Sep 17 00:00:00 2001
From: Mark Eggleston <markeggleston@gcc.gnu.org>
Date: Thu, 7 May 2020 08:29:14 +0100
Subject: [PATCH] fortran : ICE in gfc_conv_array_constructor_expr PR93497

Invalid expressions, such as those involving array constructors,
used for the length of character types will cause an ICE.

2020-05-12  Steven G. Kargl  <kargl@gcc.gnu.org>

gcc/fortran/

	PR fortran/93497
	* decl.c (char_len_param_value) : Check whether character
	length expression is of type EXPR_OP and if so simplify it.
	* resolve.c (resolve_charlen) : Reject length if it has a
	rank.

2020-05-12  Mark Eggleston  <markeggleston@gcc.gnu.org>

gcc/testsuite/

	PR fortran/93497
	* gfortran.dg/pr88025.f90: Change in wording of error.
	* gfortran.dg/pr93497.f90: New test.
	* gfortran.dg/pr93714_1.f90: Change in wording of errors.
	* gfortran.dg/pr93714_2.f90: Change in wording of errors.
---
 gcc/fortran/decl.c                      | 5 +++++
 gcc/fortran/resolve.c                   | 2 +-
 gcc/testsuite/gfortran.dg/pr88025.f90   | 2 +-
 gcc/testsuite/gfortran.dg/pr93497.f90   | 8 ++++++++
 gcc/testsuite/gfortran.dg/pr93714_1.f90 | 4 ++--
 gcc/testsuite/gfortran.dg/pr93714_2.f90 | 4 ++--
 6 files changed, 19 insertions(+), 6 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/pr93497.f90

diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c
index d650407da41..9cc81361f43 100644
--- a/gcc/fortran/decl.c
+++ b/gcc/fortran/decl.c
@@ -1077,6 +1077,11 @@  char_len_param_value (gfc_expr **expr, bool *deferred)
   if (!gfc_expr_check_typed (*expr, gfc_current_ns, false))
     return MATCH_ERROR;
 
+  /* If gfortran gets an EXPR_OP, try to simplifiy it.  This catches things
+     like CHARACTER(([1])).   */
+  if ((*expr)->expr_type == EXPR_OP)
+    gfc_simplify_expr (*expr, 1);
+
   if ((*expr)->expr_type == EXPR_FUNCTION)
     {
       if ((*expr)->ts.type == BT_INTEGER
diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index fd3b025a84f..ed1705f62ba 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -12356,7 +12356,7 @@  resolve_charlen (gfc_charlen *cl)
 	}
 
       /* cl->length has been resolved.  It should have an integer type.  */
-      if (cl->length->ts.type != BT_INTEGER)
+      if (cl->length->ts.type != BT_INTEGER || cl->length->rank != 0)
 	{
 	  gfc_error ("Scalar INTEGER expression expected at %L",
 		     &cl->length->where);
diff --git a/gcc/testsuite/gfortran.dg/pr88025.f90 b/gcc/testsuite/gfortran.dg/pr88025.f90
index 96172fae76a..c51390f1434 100644
--- a/gcc/testsuite/gfortran.dg/pr88025.f90
+++ b/gcc/testsuite/gfortran.dg/pr88025.f90
@@ -2,6 +2,6 @@ 
 ! PR fortran/88025
 program p
    type t
-      character(('')) :: c = 'c'    ! { dg-error "must be of INTEGER type" }
+      character(('')) :: c = 'c'  ! { dg-error "Scalar INTEGER expression expected" }
    end type
 end
diff --git a/gcc/testsuite/gfortran.dg/pr93497.f90 b/gcc/testsuite/gfortran.dg/pr93497.f90
new file mode 100644
index 00000000000..612b41cd8ca
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr93497.f90
@@ -0,0 +1,8 @@ 
+! { dg-do compile } 
+
+program p
+   print *, [character(((/1/))) :: 'a','b'] ! { dg-error "Scalar INTEGER expression expected" }
+   print *, [character(([1])) :: 'a','b']   ! { dg-error "Scalar INTEGER expression expected" }
+   print *, [character(1+[1]) :: 'a','b']   ! { dg-error "Scalar INTEGER expression expected" }
+end
+
diff --git a/gcc/testsuite/gfortran.dg/pr93714_1.f90 b/gcc/testsuite/gfortran.dg/pr93714_1.f90
index 40f4a4bf89f..e55812c76de 100644
--- a/gcc/testsuite/gfortran.dg/pr93714_1.f90
+++ b/gcc/testsuite/gfortran.dg/pr93714_1.f90
@@ -7,5 +7,5 @@  program test
    character, pointer :: b => a
 end program
 
-! { dg-error "must be of INTEGER type" " " { target *-*-* } 6 }
-! { dg-error "does not have the TARGET attribute" " " { target *-*-* } 7 }
+! { dg-error "Scalar INTEGER expression expected" " " { target *-*-* } 6 }
+! { dg-error "Different types in pointer assignment" " " { target *-*-* } 7 }
diff --git a/gcc/testsuite/gfortran.dg/pr93714_2.f90 b/gcc/testsuite/gfortran.dg/pr93714_2.f90
index 86658f28859..23d53508f1f 100644
--- a/gcc/testsuite/gfortran.dg/pr93714_2.f90
+++ b/gcc/testsuite/gfortran.dg/pr93714_2.f90
@@ -7,5 +7,5 @@  program test
    character(:), pointer :: b => a
 end program
 
-! { dg-error "must be of INTEGER type" " " { target *-*-* } 6 }
-! { dg-error "does not have the TARGET attribute" " " { target *-*-* } 7 }
+! { dg-error "Scalar INTEGER expression expected" " " { target *-*-* } 6 }
+! { dg-error "Different types in pointer assignment" " " { target *-*-* } 7 }
-- 
2.11.0