OSDN Git Service

gcc/
authorpzhao <pzhao@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 7 May 2010 08:18:06 +0000 (08:18 +0000)
committerMasaki Muranaka <monaka@monami-software.com>
Sun, 23 May 2010 05:02:07 +0000 (14:02 +0900)
2010-05-07  Shujing Zhao  <pearly.zhao@oracle.com>

        * c-typeck.c (build_binary_op): Warn ordered comparison of pointer
        with null pointer and also warn about ordered comparison of zero
        with pointer if -Wextra.

gcc/testsuite/
2010-05-07  Shujing Zhao  <pearly.zhao@oracle.com>

        * gcc.dg/ordered-comparison-1.c: New test.
        * gcc.dg/ordered-comparison-2.c: New test.
        * gcc.dg/ordered-comparison-3.c: New test.
        * gcc.dg/ordered-comparison-4.c: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@159145 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/c-typeck.c
gcc/testsuite/ChangeLog

index 5839779..f1885a9 100644 (file)
@@ -1,3 +1,9 @@
+2010-05-07  Shujing Zhao  <pearly.zhao@oracle.com>
+
+       * c-typeck.c (build_binary_op): Warn ordered comparison of pointer
+       with null pointer and also warn about ordered comparison of zero with
+       pointer if -Wextra.
+
 2010-05-05  Andreas Simbuerger  <simbuerg@fim.uni-passau.de>
 
        * graphite-blocking.c
index 96b2ab1..2f66d6a 100644 (file)
@@ -9625,6 +9625,11 @@ build_binary_op (location_t location, enum tree_code code,
              else if (TREE_CODE (TREE_TYPE (type0)) == FUNCTION_TYPE)
                pedwarn (location, OPT_pedantic, "ISO C forbids "
                         "ordered comparisons of pointers to functions");
+             else if (null_pointer_constant_p (orig_op0)
+                      || null_pointer_constant_p (orig_op1))
+               warning_at (location, OPT_Wextra,
+                           "ordered comparison of pointer with null pointer");
+
            }
          else if (!addr_space_superset (as0, as1, &as_common))
            {
@@ -9649,13 +9654,17 @@ build_binary_op (location_t location, enum tree_code code,
                     "ordered comparison of pointer with integer zero");
          else if (extra_warnings)
            warning_at (location, OPT_Wextra,
-                    "ordered comparison of pointer with integer zero");
+                       "ordered comparison of pointer with integer zero");
        }
       else if (code1 == POINTER_TYPE && null_pointer_constant_p (orig_op0))
        {
          result_type = type1;
-         pedwarn (location, OPT_pedantic,
-                  "ordered comparison of pointer with integer zero");
+         if (pedantic)
+           pedwarn (location, OPT_pedantic,
+                    "ordered comparison of pointer with integer zero");
+         else if (extra_warnings)
+           warning_at (location, OPT_Wextra,
+                       "ordered comparison of pointer with integer zero");
        }
       else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
        {
index 1377bcb..50397ef 100644 (file)
@@ -1,3 +1,10 @@
+2010-05-07  Shujing Zhao  <pearly.zhao@oracle.com>
+
+       * gcc.dg/ordered-comparison-1.c: New test.
+       * gcc.dg/ordered-comparison-2.c: New test.
+       * gcc.dg/ordered-comparison-3.c: New test.
+       * gcc.dg/ordered-comparison-4.c: New test.
+
 2010-05-06  Mike Stump  <mikestump@comcast.net>
 
        PR objc/35165