OSDN Git Service

2007-03-14 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
authormanu <manu@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 14 Mar 2007 18:37:37 +0000 (18:37 +0000)
committermanu <manu@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 14 Mar 2007 18:37:37 +0000 (18:37 +0000)
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

gcc/ChangeLog
gcc/c-common.c
gcc/c-common.h
gcc/c-typeck.c
gcc/cp/ChangeLog
gcc/cp/typeck.c

index bfbf8f3..3dbd130 100644 (file)
@@ -1,3 +1,11 @@
+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
index 6543bd0..f82a84b 100644 (file)
@@ -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"
index f47fa8e..b2739c3 100644 (file)
@@ -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  */
index e45c5e0..eca1066 100644 (file)
@@ -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)
        {
index a56322b..5f0490c 100644 (file)
@@ -1,3 +1,9 @@
+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.
index e8f1a18..ac6eb2b 100644 (file)
@@ -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)
        {