re PR c/21438 (Warning about division by zero depends on lexical form)

2007-03-14  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>

	PR c/21438
	* c-common.h (warn_for_div_by_zero): Declare.
	* c-common.c (warn_for_div_by_zero): Define.
	* c-typeck.c (build_binary_op): Call warn_for_div_zero instead of
	warning.
cp/
	* typeck.c (build_binary_op): Call warn_for_div_zero instead of
	warning.

From-SVN: r122925
parent 925af765
2007-03-14 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
PR c/21438
* c-common.h (warn_for_div_by_zero): Declare.
* c-common.c (warn_for_div_by_zero): Define.
* c-typeck.c (build_binary_op): Call warn_for_div_zero instead of
warning.
2007-03-14 Richard Sandiford <richard@codesourcery.com> 2007-03-14 Richard Sandiford <richard@codesourcery.com>
* Makefile.in (PREPROCESSOR_DEFINES): Add directory terminators * Makefile.in (PREPROCESSOR_DEFINES): Add directory terminators
......
...@@ -7032,4 +7032,17 @@ c_build_cdtor_fns (void) ...@@ -7032,4 +7032,17 @@ c_build_cdtor_fns (void)
struct gcc_targetcm targetcm = TARGETCM_INITIALIZER; struct gcc_targetcm targetcm = TARGETCM_INITIALIZER;
#endif #endif
/* Warn for division by zero according to the value of DIVISOR. */
void
warn_for_div_by_zero (tree divisor)
{
/* If DIVISOR is zero, and has integral type, issue a warning about
division by zero. Do not issue a warning if DIVISOR has a
floating-point type, since we consider 0.0/0.0 a valid way of
generating a NaN. */
if (skip_evaluation == 0 && integer_zerop (divisor))
warning (OPT_Wdiv_by_zero, "division by zero");
}
#include "gt-c-common.h" #include "gt-c-common.h"
...@@ -871,6 +871,7 @@ extern void warn_array_subscript_with_type_char (tree); ...@@ -871,6 +871,7 @@ extern void warn_array_subscript_with_type_char (tree);
extern void warn_about_parentheses (enum tree_code, enum tree_code, extern void warn_about_parentheses (enum tree_code, enum tree_code,
enum tree_code); enum tree_code);
extern void warn_for_unused_label (tree label); extern void warn_for_unused_label (tree label);
extern void warn_for_div_by_zero (tree divisor);
/* In c-gimplify.c */ /* In c-gimplify.c */
......
...@@ -7848,10 +7848,7 @@ build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1, ...@@ -7848,10 +7848,7 @@ build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
case FLOOR_DIV_EXPR: case FLOOR_DIV_EXPR:
case ROUND_DIV_EXPR: case ROUND_DIV_EXPR:
case EXACT_DIV_EXPR: case EXACT_DIV_EXPR:
/* Floating point division by zero is a legitimate way to obtain warn_for_div_by_zero (op1);
infinities and NaNs. */
if (skip_evaluation == 0 && integer_zerop (op1))
warning (OPT_Wdiv_by_zero, "division by zero");
if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
|| code0 == COMPLEX_TYPE || code0 == VECTOR_TYPE) || code0 == COMPLEX_TYPE || code0 == VECTOR_TYPE)
...@@ -7891,8 +7888,7 @@ build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1, ...@@ -7891,8 +7888,7 @@ build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
case TRUNC_MOD_EXPR: case TRUNC_MOD_EXPR:
case FLOOR_MOD_EXPR: case FLOOR_MOD_EXPR:
if (skip_evaluation == 0 && integer_zerop (op1)) warn_for_div_by_zero (op1);
warning (OPT_Wdiv_by_zero, "division by zero");
if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE) if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
{ {
......
2007-03-14 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
PR c/21438
* typeck.c (build_binary_op): Call warn_for_div_zero instead of
warning.
2007-03-13 Alexandre Oliva <aoliva@redhat.com> 2007-03-13 Alexandre Oliva <aoliva@redhat.com>
* cp/repo.c (init_repo): Initialize random_seed saved options. * cp/repo.c (init_repo): Initialize random_seed saved options.
......
...@@ -3169,10 +3169,7 @@ build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1, ...@@ -3169,10 +3169,7 @@ build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
{ {
enum tree_code tcode0 = code0, tcode1 = code1; enum tree_code tcode0 = code0, tcode1 = code1;
if (TREE_CODE (op1) == INTEGER_CST && integer_zerop (op1)) warn_for_div_by_zero (op1);
warning (OPT_Wdiv_by_zero, "division by zero in %<%E / 0%>", op0);
else if (TREE_CODE (op1) == REAL_CST && real_zerop (op1))
warning (OPT_Wdiv_by_zero, "division by zero in %<%E / 0.%>", op0);
if (tcode0 == COMPLEX_TYPE || tcode0 == VECTOR_TYPE) if (tcode0 == COMPLEX_TYPE || tcode0 == VECTOR_TYPE)
tcode0 = TREE_CODE (TREE_TYPE (TREE_TYPE (op0))); tcode0 = TREE_CODE (TREE_TYPE (TREE_TYPE (op0)));
...@@ -3206,10 +3203,7 @@ build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1, ...@@ -3206,10 +3203,7 @@ build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
case TRUNC_MOD_EXPR: case TRUNC_MOD_EXPR:
case FLOOR_MOD_EXPR: case FLOOR_MOD_EXPR:
if (code1 == INTEGER_TYPE && integer_zerop (op1)) warn_for_div_by_zero (op1);
warning (OPT_Wdiv_by_zero, "division by zero in %<%E %% 0%>", op0);
else if (code1 == REAL_TYPE && real_zerop (op1))
warning (OPT_Wdiv_by_zero, "division by zero in %<%E %% 0.%>", op0);
if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE) if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
{ {
......
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