re PR c/48778 (gcc 4.6 -Waddress adds unhelpful new warning case when using from...
authorMarek Polacek <polacek@redhat.com>
Wed, 4 May 2016 13:46:15 +0000 (13:46 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Wed, 4 May 2016 13:46:15 +0000 (13:46 +0000)
PR c/48778
* c-typeck.c (build_binary_op): Don't issue -Waddress warnings
for macro expansions.

* gcc.dg/Waddress-2.c: New test.

From-SVN: r235878

gcc/c/ChangeLog
gcc/c/c-typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/Waddress-2.c [new file with mode: 0644]

index 8ac13e31f424bdd52a8b9d0a0608d6db830ae70c..517a8c6c02ec3fbe4c3790bf94cdcdcfa9490eaa 100644 (file)
@@ -1,3 +1,9 @@
+2016-05-04  Marek Polacek  <polacek@redhat.com>
+
+       PR c/48778
+       * c-typeck.c (build_binary_op): Don't issue -Waddress warnings
+       for macro expansions.
+
 2016-05-03  Marek Polacek  <polacek@redhat.com>
 
        PR c/70859
index 204702e505e17fc2555e3e4c8b6d910a09e7da24..861aa12ae2de5c2c9a4d33d0083ee9c0fe015092 100644 (file)
@@ -11067,7 +11067,8 @@ build_binary_op (location_t location, enum tree_code code,
       else if (code0 == POINTER_TYPE && null_pointer_constant_p (orig_op1))
        {
          if (TREE_CODE (op0) == ADDR_EXPR
-             && decl_with_nonnull_addr_p (TREE_OPERAND (op0, 0)))
+             && decl_with_nonnull_addr_p (TREE_OPERAND (op0, 0))
+             && !from_macro_expansion_at (location))
            {
              if (code == EQ_EXPR)
                warning_at (location,
@@ -11087,7 +11088,8 @@ build_binary_op (location_t location, enum tree_code code,
       else if (code1 == POINTER_TYPE && null_pointer_constant_p (orig_op0))
        {
          if (TREE_CODE (op1) == ADDR_EXPR
-             && decl_with_nonnull_addr_p (TREE_OPERAND (op1, 0)))
+             && decl_with_nonnull_addr_p (TREE_OPERAND (op1, 0))
+             && !from_macro_expansion_at (location))
            {
              if (code == EQ_EXPR)
                warning_at (location,
index 6c1397d78c0e63aea8afe9129817c31404ab7ba7..ddde8776f6b4067826feeca2e62d8fea4ba5e689 100644 (file)
@@ -1,3 +1,8 @@
+2016-05-04  Marek Polacek  <polacek@redhat.com>
+
+       PR c/48778
+       * gcc.dg/Waddress-2.c: New test.
+
 2016-05-04  Alan Modra  <amodra@gmail.com>
 
        * gcc.target/powerpc/pr70866.c: New.
diff --git a/gcc/testsuite/gcc.dg/Waddress-2.c b/gcc/testsuite/gcc.dg/Waddress-2.c
new file mode 100644 (file)
index 0000000..4d927f6
--- /dev/null
@@ -0,0 +1,24 @@
+/* PR c/48778 */
+/* { dg-do compile } */
+/* { dg-options "-Waddress" } */
+
+#define NULL ((void *) 0)
+
+#define M1(b) ((b) != NULL ? 0 : (b))
+#define M2(b) ((b) == NULL ? 0 : (b))
+#define M3(b) (NULL != (b) ? 0 : (b))
+#define M4(b) (NULL == (b) ? 0 : (b))
+
+int
+func (int b)
+{
+  if (M1 (&b) > 0)
+    return 1;
+  if (M2 (&b) > 0)
+    return 2;
+  if (M3 (&b) > 0)
+    return 3;
+  if (M4 (&b) > 0)
+    return 4;
+  return 0;
+}