From de55efd5a26ac59b22099af9384d9014ca522576 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Wed, 4 May 2016 13:46:15 +0000 Subject: [PATCH] re PR c/48778 (gcc 4.6 -Waddress adds unhelpful new warning case when using from a macro) 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 | 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.30.2