From 439606a90c79c921dc1d0bed9a3871448d8858c1 Mon Sep 17 00:00:00 2001 From: mpolacek Date: Fri, 24 Apr 2015 11:49:52 +0000 Subject: [PATCH] PR c/61534 * input.h (from_macro_expansion_at): Define. * c-common.c (warn_logical_operator): Bail if either operand comes from a macro expansion. * c-c++-common/pr61534-1.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@222406 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 5 +++++ gcc/c-family/ChangeLog | 6 ++++++ gcc/c-family/c-common.c | 7 +++++++ gcc/input.h | 4 ++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/c-c++-common/pr61534-1.c | 13 +++++++++++++ 6 files changed, 40 insertions(+) create mode 100644 gcc/testsuite/c-c++-common/pr61534-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index b302e36..4bb3679 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2015-04-24 Marek Polacek + + PR c/61534 + * input.h (from_macro_expansion_at): Define. + 2015-04-24 Thomas Preud'homme * config/arm/unknown-elf.h (ASM_OUTPUT_ALIGNED_DECL_LOCAL): fix diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 3373549..270ef70 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,9 @@ +2015-04-24 Marek Polacek + + PR c/61534 + * c-common.c (warn_logical_operator): Bail if either operand comes + from a macro expansion. + 2015-04-10 Bernhard Reutner-Fischer PR target/55143 diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 7fe7fa6..b09bbb8 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -1697,6 +1697,13 @@ warn_logical_operator (location_t location, enum tree_code code, tree type, && code != TRUTH_OR_EXPR) return; + /* We don't want to warn if either operand comes from a macro + expansion. ??? This doesn't work with e.g. NEGATE_EXPR yet; + see PR61534. */ + if (from_macro_expansion_at (EXPR_LOCATION (op_left)) + || from_macro_expansion_at (EXPR_LOCATION (op_right))) + return; + /* Warn if &&/|| are being used in a context where it is likely that the bitwise equivalent was intended by the programmer. That is, an expression such as op && MASK diff --git a/gcc/input.h b/gcc/input.h index 7a0483f..93eb6ed 100644 --- a/gcc/input.h +++ b/gcc/input.h @@ -70,6 +70,10 @@ extern location_t input_location; header, but expanded in a non-system file. */ #define in_system_header_at(LOC) \ (linemap_location_in_system_header_p (line_table, LOC)) +/* Return a positive value if LOCATION is the locus of a token that + comes from a macro expansion, O otherwise. */ +#define from_macro_expansion_at(LOC) \ + ((linemap_location_from_macro_expansion_p (line_table, LOC))) void dump_line_table_statistics (void); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index bbc0b24..c493bd8 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-04-24 Marek Polacek + + PR c/61534 + * c-c++-common/pr61534-1.c: New test. + 2015-04-24 Thomas Preud'homme Steven Bosscher diff --git a/gcc/testsuite/c-c++-common/pr61534-1.c b/gcc/testsuite/c-c++-common/pr61534-1.c new file mode 100644 index 0000000..1e304f0 --- /dev/null +++ b/gcc/testsuite/c-c++-common/pr61534-1.c @@ -0,0 +1,13 @@ +/* PR c/61534 */ +/* { dg-options "-Wlogical-op" } */ + +extern int xxx; +#define XXX !xxx +int +test (void) +{ + if (XXX && xxx) /* { dg-bogus "logical" } */ + return 4; + else + return 0; +} -- 2.7.4