Skip to content

Commit

Permalink
Fortran: prevent redundant integer division truncation warnings [PR10…
Browse files Browse the repository at this point in the history
…8592]

gcc/fortran/ChangeLog:

	PR fortran/108592
	* arith.cc (gfc_arith_divide): Emit integer division truncation
	warnings using gfc_warning instead of gfc_warning_now to prevent
	redundant messages.

gcc/testsuite/ChangeLog:

	PR fortran/108592
	* gfortran.dg/pr108592.f90: New test.
  • Loading branch information
harald-anlauf committed Feb 5, 2023
1 parent f1a4c63 commit d042f11
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gcc/fortran/arith.cc
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ gfc_arith_divide (gfc_expr *op1, gfc_expr *op2, gfc_expr **resultp)
{
char *p;
p = mpz_get_str (NULL, 10, result->value.integer);
gfc_warning_now (OPT_Winteger_division, "Integer division "
gfc_warning (OPT_Winteger_division, "Integer division "
"truncated to constant %qs at %L", p,
&op1->where);
free (p);
Expand Down
8 changes: 8 additions & 0 deletions gcc/testsuite/gfortran.dg/pr108592.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
! { dg-do compile }
! { dg-options "-Winteger-division" }
! PR fortran/108592 - warn only once for truncation of integer division

program foo
if (8 < (20/9)) stop 1 ! { dg-bogus "Integer division.*Integer division" }
! { dg-message "Integer division truncated" "" { target *-*-* } .-1 }
end program

0 comments on commit d042f11

Please sign in to comment.