Fortran : ICE for division by zero in declaration PR95882
authorMark Eggleston <markeggleston@gcc.gnu.org>
Fri, 21 Aug 2020 05:39:30 +0000 (06:39 +0100)
committerMark Eggleston <markeggleston@gcc.gnu.org>
Thu, 27 Aug 2020 14:12:10 +0000 (15:12 +0100)
A length expression containing a divide by zero in a character
declaration will result in an ICE if the constant is anymore
complicated that a contant divided by a constant.

The cause was that char_len_param_value can return MATCH_YES
even if a divide by zero was seen.  Prior to returning check
whether a divide by zero was seen and if so set it to MATCH_ERROR.

2020-08-27  Mark Eggleston  <markeggleston@gcc.gnu.org>

gcc/fortran

PR fortran/95882
* decl.c (char_len_param_value): Check gfc_seen_div0 and
if it is set return MATCH_ERROR.

2020-08-27  Mark Eggleston  <markeggleston@gcc.gnu.org>

gcc/testsuite/

PR fortran/95882
* gfortran.dg/pr95882_1.f90: New test.
* gfortran.dg/pr95882_2.f90: New test.
* gfortran.dg/pr95882_3.f90: New test.
* gfortran.dg/pr95882_4.f90: New test.
* gfortran.dg/pr95882_5.f90: New test.

gcc/fortran/decl.c
gcc/testsuite/gfortran.dg/pr95882_1.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/pr95882_2.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/pr95882_3.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/pr95882_4.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/pr95882_5.f90 [new file with mode: 0644]

index d854b2a..c612b49 100644 (file)
@@ -1146,6 +1146,9 @@ char_len_param_value (gfc_expr **expr, bool *deferred)
       gfc_free_expr (e);
     }
 
+  if (gfc_seen_div0)
+    m = MATCH_ERROR;
+
   return m;
 
 syntax:
diff --git a/gcc/testsuite/gfortran.dg/pr95882_1.f90 b/gcc/testsuite/gfortran.dg/pr95882_1.f90
new file mode 100644 (file)
index 0000000..c254bdd
--- /dev/null
@@ -0,0 +1,8 @@
+! { dg-do compile }
+
+module m
+   type t
+      character(((0)/0)) :: c  ! { dg-error "Division by zero" }
+   end type
+end
+
diff --git a/gcc/testsuite/gfortran.dg/pr95882_2.f90 b/gcc/testsuite/gfortran.dg/pr95882_2.f90
new file mode 100644 (file)
index 0000000..d308f0c
--- /dev/null
@@ -0,0 +1,6 @@
+! { dg-do compile }
+
+module m
+   character(0/(0)) :: c = '123456789'  ! { dg-error "Division by zero" }
+end
+
diff --git a/gcc/testsuite/gfortran.dg/pr95882_3.f90 b/gcc/testsuite/gfortran.dg/pr95882_3.f90
new file mode 100644 (file)
index 0000000..bd84913
--- /dev/null
@@ -0,0 +1,6 @@
+! { dg-do compile }
+
+subroutine s(c)
+   character(((0)/0)) :: c  ! { dg-error "Division by zero" }
+end
+
diff --git a/gcc/testsuite/gfortran.dg/pr95882_4.f90 b/gcc/testsuite/gfortran.dg/pr95882_4.f90
new file mode 100644 (file)
index 0000000..52892d3
--- /dev/null
@@ -0,0 +1,7 @@
+! { dg-do compile }
+
+program p
+   character(((0)/0)) :: c  ! { dg-error "Division by zero" }
+   common /x/ c
+end
+
diff --git a/gcc/testsuite/gfortran.dg/pr95882_5.f90 b/gcc/testsuite/gfortran.dg/pr95882_5.f90
new file mode 100644 (file)
index 0000000..dcdf530
--- /dev/null
@@ -0,0 +1,6 @@
+! { dg-do compile }
+
+program p
+   character(0/(0)) :: c = '123456789'  ! { dg-error "Division by zero" }
+   common c
+end