From: manu Date: Wed, 14 Mar 2007 18:37:37 +0000 (+0000) Subject: 2007-03-14 Manuel Lopez-Ibanez X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f092582b2ade55c20811f1e42d28ceea856a5ca8;p=thirdparty%2Fgcc.git 2007-03-14 Manuel Lopez-Ibanez 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@122925 138bc75d-0d04-0410-961f-82ee72b054a4 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index bfbf8f38c744..3dbd1301cec8 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2007-03-14 Manuel Lopez-Ibanez + + 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 * Makefile.in (PREPROCESSOR_DEFINES): Add directory terminators diff --git a/gcc/c-common.c b/gcc/c-common.c index 6543bd0f1b7d..f82a84b59145 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -7032,4 +7032,17 @@ c_build_cdtor_fns (void) struct gcc_targetcm targetcm = TARGETCM_INITIALIZER; #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" diff --git a/gcc/c-common.h b/gcc/c-common.h index f47fa8e38150..b2739c3efb32 100644 --- a/gcc/c-common.h +++ b/gcc/c-common.h @@ -871,6 +871,7 @@ extern void warn_array_subscript_with_type_char (tree); extern void warn_about_parentheses (enum tree_code, enum tree_code, enum tree_code); extern void warn_for_unused_label (tree label); +extern void warn_for_div_by_zero (tree divisor); /* In c-gimplify.c */ diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index e45c5e0bf971..eca10668ee65 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -7848,10 +7848,7 @@ build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1, case FLOOR_DIV_EXPR: case ROUND_DIV_EXPR: case EXACT_DIV_EXPR: - /* Floating point division by zero is a legitimate way to obtain - infinities and NaNs. */ - if (skip_evaluation == 0 && integer_zerop (op1)) - warning (OPT_Wdiv_by_zero, "division by zero"); + warn_for_div_by_zero (op1); if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE || code0 == COMPLEX_TYPE || code0 == VECTOR_TYPE) @@ -7891,8 +7888,7 @@ build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1, case TRUNC_MOD_EXPR: case FLOOR_MOD_EXPR: - if (skip_evaluation == 0 && integer_zerop (op1)) - warning (OPT_Wdiv_by_zero, "division by zero"); + warn_for_div_by_zero (op1); if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE) { diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index a56322b47f2b..5f0490c53d3f 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2007-03-14 Manuel Lopez-Ibanez + + PR c/21438 + * typeck.c (build_binary_op): Call warn_for_div_zero instead of + warning. + 2007-03-13 Alexandre Oliva * cp/repo.c (init_repo): Initialize random_seed saved options. diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index e8f1a183fc94..ac6eb2b6f751 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -3169,10 +3169,7 @@ build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1, { enum tree_code tcode0 = code0, tcode1 = code1; - if (TREE_CODE (op1) == INTEGER_CST && integer_zerop (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); + warn_for_div_by_zero (op1); if (tcode0 == COMPLEX_TYPE || tcode0 == VECTOR_TYPE) 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, case TRUNC_MOD_EXPR: case FLOOR_MOD_EXPR: - if (code1 == INTEGER_TYPE && integer_zerop (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); + warn_for_div_by_zero (op1); if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE) {