Commit 75d1c004 by Steven G. Kargl

re PR fortran/86045 (ICE in reduce_binary_ac, at fortran/arith.c:1308)

2018-06-07  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/86045
	* simplify.c (gfc_simplify_mod): Re-arrange code to test whether
	'P' is zero and issue an error if it is.

2018-06-07  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/86045
	* gfortran.dg/pr86045.f90: New test.

From-SVN: r261286
parent dc23fb4d
2018-06-07 Steven G. Kargl <kargl@gcc.gnu.org>
PR fortran/86045
* simplify.c (gfc_simplify_mod): Re-arrange code to test whether
'P' is zero and issue an error if it is.
2018-06-06 Thomas Koenig <tkoenig@gcc.gnu.org> 2018-06-06 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/85641 PR fortran/85641
......
...@@ -5473,41 +5473,46 @@ gfc_simplify_mod (gfc_expr *a, gfc_expr *p) ...@@ -5473,41 +5473,46 @@ gfc_simplify_mod (gfc_expr *a, gfc_expr *p)
gfc_expr *result; gfc_expr *result;
int kind; int kind;
if (a->expr_type != EXPR_CONSTANT || p->expr_type != EXPR_CONSTANT) /* First check p. */
if (p->expr_type != EXPR_CONSTANT)
return NULL; return NULL;
kind = a->ts.kind > p->ts.kind ? a->ts.kind : p->ts.kind; /* p shall not be 0. */
result = gfc_get_constant_expr (a->ts.type, kind, &a->where); switch (p->ts.type)
switch (a->ts.type)
{ {
case BT_INTEGER: case BT_INTEGER:
if (mpz_cmp_ui (p->value.integer, 0) == 0) if (mpz_cmp_ui (p->value.integer, 0) == 0)
{ {
/* Result is processor-dependent. */ gfc_error ("Argument %qs of MOD at %L shall not be zero",
gfc_error ("Second argument MOD at %L is zero", &a->where); "P", &p->where);
gfc_free_expr (result);
return &gfc_bad_expr; return &gfc_bad_expr;
} }
mpz_tdiv_r (result->value.integer, a->value.integer, p->value.integer);
break; break;
case BT_REAL: case BT_REAL:
if (mpfr_cmp_ui (p->value.real, 0) == 0) if (mpfr_cmp_ui (p->value.real, 0) == 0)
{ {
/* Result is processor-dependent. */ gfc_error ("Argument %qs of MOD at %L shall not be zero",
gfc_error ("Second argument of MOD at %L is zero", &p->where); "P", &p->where);
gfc_free_expr (result);
return &gfc_bad_expr; return &gfc_bad_expr;
} }
break;
default:
gfc_internal_error ("gfc_simplify_mod(): Bad arguments");
}
if (a->expr_type != EXPR_CONSTANT)
return NULL;
kind = a->ts.kind > p->ts.kind ? a->ts.kind : p->ts.kind;
result = gfc_get_constant_expr (a->ts.type, kind, &a->where);
if (a->ts.type == BT_INTEGER)
mpz_tdiv_r (result->value.integer, a->value.integer, p->value.integer);
else
{
gfc_set_model_kind (kind); gfc_set_model_kind (kind);
mpfr_fmod (result->value.real, a->value.real, p->value.real, mpfr_fmod (result->value.real, a->value.real, p->value.real,
GFC_RND_MODE); GFC_RND_MODE);
break;
default:
gfc_internal_error ("gfc_simplify_mod(): Bad arguments");
} }
return range_check (result, "MOD"); return range_check (result, "MOD");
......
2018-06-07 Steven G. Kargl <kargl@gcc.gnu.org>
PR fortran/86045
* gfortran.dg/pr86045.f90: New test.
2018-06-07 Marek Polacek <polacek@redhat.com> 2018-06-07 Marek Polacek <polacek@redhat.com>
* g++.dg/cpp0x/range-for9.C: Adjust dg-error. * g++.dg/cpp0x/range-for9.C: Adjust dg-error.
......
! { dg-do compile }
program p
logical :: a(2) = (mod([2,3],0) == 0) ! { dg-error "shall not be zero" }
integer :: b = count(mod([2,3],0) == 0) ! { dg-error "shall not be zero" }
integer :: c = all(mod([2,3],0) == 0) ! { dg-error "shall not be zero" }
integer :: d = any(mod([2,3],0) == 0) ! { dg-error "shall not be zero" }
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment