+2020-05-10 Harald Anlauf <anlauf@gmx.de>
+
+ PR fortran/93499
+ * arith.c (gfc_divide): Catch division by zero.
+ (eval_intrinsic_f3): Safeguard for NULL operands.
+
2020-05-05 Steve Kargl <kargl@gcc.gnu.org>
Harald Anlauf <anlauf@gmx.de>
gfc_expr *result;
eval_f f;
+ if (!op1 && !op2)
+ return NULL;
+
result = reduce_binary0 (op1, op2);
if (result != NULL)
return eval_type_intrinsic0(op, result);
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:
+ gfc_internal_error ("gfc_divide(): Bad basic type");
+ }
+ 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);
}
--- /dev/null
+! { dg-do compile }
+! PR 93499 - this used to ICE. Original test case by Gerhard Steinmetz.
+
+program p
+ integer :: a((0.)/0) ! { dg-error "Division by zero" }
+ type t(n)
+ integer, len :: n
+ end type t
+ type(t((0)/0)) :: x ! { dg-error "Division by zero" }
+end