public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/autopar_devel] PR fortran/95053 - division by zero constants
@ 2020-08-22 21:21 Giuliano Belinassi
  0 siblings, 0 replies; only message in thread
From: Giuliano Belinassi @ 2020-08-22 21:21 UTC (permalink / raw)
  To: gcc-cvs

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

commit d3f41252a7560bab95586a703c0e8089c85a41f2
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Mon May 18 20:27:29 2020 +0200

    PR fortran/95053 - division by zero constants
    
            Partially revert the fix for PR93499.  Replace by checks for valid
            expressions in the declaration of array shape and PDT KIND and LEN
            expressions at a later stage.
    
    gcc/fortran/
    
    2020-05-18  Harald Anlauf  <anlauf@gmx.de>
    
            PR fortran/95053
            * arith.c (gfc_divide): Revert hunk introduced by patch for
            PR93499.
            * decl.c (variable_decl): Generate error for array shape not being
            an INTEGER constant.
            (gfc_get_pdt_instance): Generate error if KIND or LEN expressions
            in declaration of a PDT instance do not simplify to INTEGER
            constants.
    
    gcc/testsuite/
    
    2020-05-18  Harald Anlauf  <anlauf@gmx.de>
    
            PR fortran/95053
            * gfortran.dg/dec_structure_23.f90: Adjust to new error messages.
            * gfortran.dg/pr93499.f90: Adjust to new error messages.
            * gfortran.dg/pr95053_2.f90: New test.
            * gfortran.dg/pr95053_3.f90: New test.

Diff:
---
 gcc/fortran/ChangeLog                          | 11 +++++++++
 gcc/fortran/arith.c                            | 32 --------------------------
 gcc/fortran/decl.c                             | 17 +++++++++++++-
 gcc/testsuite/ChangeLog                        |  8 +++++++
 gcc/testsuite/gfortran.dg/dec_structure_23.f90 |  4 ++--
 gcc/testsuite/gfortran.dg/pr93499.f90          |  4 ++--
 gcc/testsuite/gfortran.dg/pr95053_2.f90        | 10 ++++++++
 gcc/testsuite/gfortran.dg/pr95053_3.f90        | 14 +++++++++++
 8 files changed, 63 insertions(+), 37 deletions(-)

diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index 143402260c2..ab79158f7b6 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,3 +1,14 @@
+2020-05-18  Harald Anlauf  <anlauf@gmx.de>
+
+	PR fortran/95053
+	* arith.c (gfc_divide): Revert hunk introduced by patch for
+	PR93499.
+	* decl.c (variable_decl): Generate error for array shape not being
+	an INTEGER constant.
+	(gfc_get_pdt_instance): Generate error if KIND or LEN expressions
+	in declaration of a PDT instance do not simplify to INTEGER
+	constants.
+
 2020-05-15  Tobias Burnus  <tobias@codesourcery.com>
 
 	PR fortran/94690
diff --git a/gcc/fortran/arith.c b/gcc/fortran/arith.c
index dd72f44d377..c770569eb81 100644
--- a/gcc/fortran/arith.c
+++ b/gcc/fortran/arith.c
@@ -1806,38 +1806,6 @@ gfc_multiply (gfc_expr *op1, gfc_expr *op2)
 gfc_expr *
 gfc_divide (gfc_expr *op1, gfc_expr *op2)
 {
-  if (op2 && op2->expr_type == EXPR_CONSTANT)
-    {
-      arith rc = ARITH_OK;
-      switch (op2->ts.type)
-	{
-	case BT_INTEGER:
-	  /* non-integer divided by integer 0 is handled elsewhere.  */
-	  if (mpz_sgn (op2->value.integer) == 0
-	      && op1->ts.type == BT_INTEGER)
-	    rc = ARITH_DIV0;
-	  break;
-	case BT_REAL:
-	  if (mpfr_sgn (op2->value.real) == 0
-	      && flag_range_check == 1)
-	    rc = ARITH_DIV0;
-	  break;
-	case BT_COMPLEX:
-	  if (mpc_cmp_si_si (op2->value.complex, 0, 0) == 0
-	      && flag_range_check == 1)
-	    rc = ARITH_DIV0;
-	  break;
-	default:
-	  /* basic type is non-numeric, handle this elsewhere.  */
-	  break;
-	}
-      if (rc == ARITH_DIV0)
-	{
-	  gfc_seen_div0 = true;
-	  gfc_error ("Division by zero at %L", &op2->where);
-	  return NULL;
-	}
-    }
   return eval_intrinsic_f3 (INTRINSIC_DIVIDE, gfc_arith_divide, op1, op2);
 }
 
diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c
index 9cc81361f43..3ad5559c3ec 100644
--- a/gcc/fortran/decl.c
+++ b/gcc/fortran/decl.c
@@ -2607,6 +2607,14 @@ variable_decl (int elem)
 	      gfc_free_expr (e);
 	    }
 
+	  if (not_constant && e->ts.type != BT_INTEGER)
+	    {
+	      gfc_error ("Explicit array shape at %C must be constant of "
+			 "INTEGER type and not %s type",
+			 gfc_basic_typename (e->ts.type));
+	      m = MATCH_ERROR;
+	      goto cleanup;
+	    }
 	  if (not_constant)
 	    {
 	      gfc_error ("Explicit shaped array with nonconstant bounds at %C");
@@ -3741,8 +3749,9 @@ gfc_get_pdt_instance (gfc_actual_arglist *param_list, gfc_symbol **sym,
       if (kind_expr)
 	{
 	  /* Try simplification even for LEN expressions.  */
+	  bool ok;
 	  gfc_resolve_expr (kind_expr);
-	  gfc_simplify_expr (kind_expr, 1);
+	  ok = gfc_simplify_expr (kind_expr, 1);
 	  /* Variable expressions seem to default to BT_PROCEDURE.
 	     TODO find out why this is and fix it.  */
 	  if (kind_expr->ts.type != BT_INTEGER
@@ -3753,6 +3762,12 @@ gfc_get_pdt_instance (gfc_actual_arglist *param_list, gfc_symbol **sym,
 			 gfc_basic_typename (kind_expr->ts.type));
 	      goto error_return;
 	    }
+	  if (kind_expr->ts.type == BT_INTEGER && !ok)
+	    {
+	      gfc_error ("The parameter expression at %C does not "
+			 "simplify to an INTEGER constant");
+	      goto error_return;
+	    }
 
 	  tail->expr = gfc_copy_expr (kind_expr);
 	}
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 008e4483169..858eb60c609 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,11 @@
+2020-05-18  Harald Anlauf  <anlauf@gmx.de>
+
+	PR fortran/95053
+	* gfortran.dg/dec_structure_23.f90: Adjust to new error messages.
+	* gfortran.dg/pr93499.f90: Adjust to new error messages.
+	* gfortran.dg/pr95053_2.f90: New test.
+	* gfortran.dg/pr95053_3.f90: New test.
+
 2020-05-18  Marek Polacek  <polacek@redhat.com>
 
 	PR c++/95143
diff --git a/gcc/testsuite/gfortran.dg/dec_structure_23.f90 b/gcc/testsuite/gfortran.dg/dec_structure_23.f90
index 78db344e0fc..39e5369c056 100644
--- a/gcc/testsuite/gfortran.dg/dec_structure_23.f90
+++ b/gcc/testsuite/gfortran.dg/dec_structure_23.f90
@@ -13,8 +13,8 @@ program p
   integer :: nn
   real :: rr
   structure /s/
-    integer x(n)    /1/   ! { dg-error "array with nonconstant bounds" }
+    integer x(n)    /1/   ! { dg-error "must be constant of INTEGER type" }
     integer xx(nn)  /1/   ! { dg-error "array with nonconstant bounds" }
-    integer xxx(rr) /1.0/ ! { dg-error "array with nonconstant bounds" }
+    integer xxx(rr) /1.0/ ! { dg-error "must be constant of INTEGER type" }
   end structure
 end
diff --git a/gcc/testsuite/gfortran.dg/pr93499.f90 b/gcc/testsuite/gfortran.dg/pr93499.f90
index 7a414bb6016..e3e1eda7781 100644
--- a/gcc/testsuite/gfortran.dg/pr93499.f90
+++ b/gcc/testsuite/gfortran.dg/pr93499.f90
@@ -2,9 +2,9 @@
 ! PR 93499 - this used to ICE. Original test case by Gerhard Steinmetz.
 
 program p
-  integer :: a((0.)/0)  ! { dg-error "Division by zero" }
+  integer :: a((0.)/0)  ! { dg-error "must be constant of INTEGER type" }
   type t(n)
      integer, len :: n
   end type t
-  type(t((0)/0))  :: x  ! { dg-error "Division by zero" }
+  type(t((0)/0))  :: x  ! { dg-error "does not simplify to an INTEGER constant" }
 end
diff --git a/gcc/testsuite/gfortran.dg/pr95053_2.f90 b/gcc/testsuite/gfortran.dg/pr95053_2.f90
new file mode 100644
index 00000000000..7bb941ab46e
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr95053_2.f90
@@ -0,0 +1,10 @@
+! { dg-do compile }
+! PR 95053 - make sure we do not regress on 521.wrf_r from spec2017
+!
+function f (x)
+  real, parameter :: cldeps = 0.
+  f = 0.
+  if (cldeps > 0.) then
+     f = floor (x/cldeps) * cldeps
+  end if
+end function f
diff --git a/gcc/testsuite/gfortran.dg/pr95053_3.f90 b/gcc/testsuite/gfortran.dg/pr95053_3.f90
new file mode 100644
index 00000000000..eae3d8fc41e
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr95053_3.f90
@@ -0,0 +1,14 @@
+! { dg-do compile }
+! Related to PR 93499 - this used to ICE.
+
+program p
+  type t(n)
+     integer, kind :: n
+  end type t
+  type u(n)
+     integer, len :: n
+  end type u
+  type(t((0)/0))  :: x  ! { dg-error "does not simplify to an INTEGER" }
+  type(t((0.)/0)) :: y  ! { dg-error "must be of INTEGER type" }
+  type(u(0/(0.))) :: z  ! { dg-error "must be of INTEGER type" }
+end


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-08-22 21:21 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-22 21:21 [gcc/devel/autopar_devel] PR fortran/95053 - division by zero constants Giuliano Belinassi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).