From a64030feb9ee63f126bfb9880a3d2f5f43b98b3c Mon Sep 17 00:00:00 2001 From: mpolacek Date: Wed, 4 May 2016 13:46:15 +0000 Subject: [PATCH] PR c/48778 * c-typeck.c (build_binary_op): Don't issue -Waddress warnings for macro expansions. * gcc.dg/Waddress-2.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@235878 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/c/ChangeLog | 6 ++++++ gcc/c/c-typeck.c | 6 ++++-- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/Waddress-2.c | 24 ++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/Waddress-2.c diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 8ac13e31f42..517a8c6c02e 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,9 @@ +2016-05-04 Marek Polacek + + PR c/48778 + * c-typeck.c (build_binary_op): Don't issue -Waddress warnings + for macro expansions. + 2016-05-03 Marek Polacek PR c/70859 diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index 204702e505e..861aa12ae2d 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -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, diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6c1397d78c0..ddde8776f6b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-05-04 Marek Polacek + + PR c/48778 + * gcc.dg/Waddress-2.c: New test. + 2016-05-04 Alan Modra * 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 index 00000000000..4d927f67694 --- /dev/null +++ b/gcc/testsuite/gcc.dg/Waddress-2.c @@ -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; +} -- 2.11.4.GIT