+2015-07-01 Thomas Koenig <tkoenig@gcc.gnu.org>
+
+ * arith.c (gfc_arith_divide): With -Winteger-division,
+ warn about contant integer division if there is a non-zero
+ remainder.
+ * invoke.texi: Document -Winteger-division.
+ * lang.opt: Add -Winteger-division.
+
2015-06-25 Andrew MacLeod <amacleod@redhat.com>
* f95-lang.c: Remove ipa-ref.h and plugin-api.h from include list.
break;
}
- mpz_tdiv_q (result->value.integer, op1->value.integer,
- op2->value.integer);
+ if (warn_integer_division)
+ {
+ mpz_t r;
+ mpz_init (r);
+ mpz_tdiv_qr (result->value.integer, r, op1->value.integer,
+ op2->value.integer);
+
+ if (mpz_cmp_si (r, 0) != 0)
+ {
+ char *p;
+ p = mpz_get_str (NULL, 10, result->value.integer);
+ gfc_warning_now (OPT_Winteger_division, "Integer division "
+ "truncated to constant %qs at %L", p,
+ &op1->where);
+ free (p);
+ }
+ mpz_clear (r);
+ }
+ else
+ mpz_tdiv_q (result->value.integer, op1->value.integer,
+ op2->value.integer);
+
break;
case BT_REAL:
@option{-Wconversion}, @option{-Wsurprising}, @option{-Wc-binding-type},
@option{-Wintrinsics-std}, @option{-Wno-tabs}, @option{-Wintrinsic-shadow},
@option{-Wline-truncation}, @option{-Wtarget-lifetime},
-@option{-Wreal-q-constant} and @option{-Wunused}.
+@option{-Winteger-division}, @option{-Wreal-q-constant} and @option{-Wunused}.
@item -Waliasing
@opindex @code{Waliasing}
Warn if a procedure is called that has neither an explicit interface
nor has been declared as @code{EXTERNAL}.
+@item -Winteger-division
+@opindex @code{Winteger-division}
+@cindex warnings, integer division
+@cindex warnings, division of integers
+Warn if a constant integer division truncates it result.
+As an example, 3/5 evaluates to 0.
+
@item -Wintrinsics-std
@opindex @code{Wintrinsics-std}
@cindex warnings, non-standard intrinsics
Fortran Warning Var(warn_implicit_procedure)
Warn about called procedures not explicitly declared
+Winteger-division
+Fortran Warning Var(warn_integer_division) LangEnabledBy(Fortran,Wall)
+Warn about constant integer divisions with truncated results
+
Wline-truncation
Fortran Warning Var(warn_line_truncation) LangEnabledBy(Fortran,Wall) Init(-1)
Warn about truncated source lines
+2015-07-01 Thomas Koenig <tkoenig@gcc.gnu.org>
+
+ * gfortran.dg/warn_conversion_8.f90: New test.
+
2015-07-01 Bernd Edlinger <bernd.edlinger@hotmail.de>
PR rtl-optimization/61047
--- /dev/null
+! { dg-do compile }
+! { dg-options "-Winteger-division" }
+program main
+ integer, parameter :: n = 23
+ integer, parameter :: m = n*(n+1)/2 ! No warning
+ integer, parameter :: i = n*(n+1)/17 ! { dg-warning "Integer division truncated to constant" }
+ print *, 3/5 ! { dg-warning "Integer division truncated to constant" }
+end program main