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
+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>
* Makefile.in (PREPROCESSOR_DEFINES): Add directory terminators
2007-03-14 Richard Sandiford <richard@codesourcery.com>
* Makefile.in (PREPROCESSOR_DEFINES): Add directory terminators
struct gcc_targetcm targetcm = TARGETCM_INITIALIZER;
#endif
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");
+}
+
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_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);
case FLOOR_DIV_EXPR:
case ROUND_DIV_EXPR:
case EXACT_DIV_EXPR:
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)
if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
|| code0 == COMPLEX_TYPE || code0 == VECTOR_TYPE)
case TRUNC_MOD_EXPR:
case FLOOR_MOD_EXPR:
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)
{
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>
* cp/repo.c (init_repo): Initialize random_seed saved options.
2007-03-13 Alexandre Oliva <aoliva@redhat.com>
* cp/repo.c (init_repo): Initialize random_seed saved options.
{
enum tree_code tcode0 = code0, tcode1 = code1;
{
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)));
if (tcode0 == COMPLEX_TYPE || tcode0 == VECTOR_TYPE)
tcode0 = TREE_CODE (TREE_TYPE (TREE_TYPE (op0)));
case TRUNC_MOD_EXPR:
case FLOOR_MOD_EXPR:
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)
{
if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
{