From 6ce0c450c4fefd85f09026e0f9df6cbb901f5f9b Mon Sep 17 00:00:00 2001 From: mueller Date: Wed, 31 Jan 2007 13:43:40 +0000 Subject: [PATCH] 2007-01-31 Dirk Mueller * c-common.c (warn_about_parentheses): Separate warning about un-parenthized sequence of comparison operators from the one which is supposed to warn about x <= y <= z. * testsuite/gcc.dg/Wparentheses-2.c: Update and add new tests. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@121421 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 6 +++ gcc/c-common.c | 23 ++++++--- gcc/testsuite/ChangeLog | 4 ++ gcc/testsuite/gcc.dg/Wparentheses-2.c | 90 ++++++++++++++++++++++++++++------- 4 files changed, 99 insertions(+), 24 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index ba55b7c..3433a8d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2007-01-31 Dirk Mueller + + * c-common.c (warn_about_parentheses): Separate warning about + un-parenthized sequence of comparison operators from the one + which is supposed to warn about x <= y <= z. + 2007-01-31 Uros Bizjak * optabs.h (enum optab_index): Add new OTI_isinf. diff --git a/gcc/c-common.c b/gcc/c-common.c index 1bd59ff..cfd3829 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -6750,12 +6750,23 @@ warn_about_parentheses (enum tree_code code, enum tree_code code_left, "suggest parentheses around comparison in operand of &"); } - /* Similarly, check for cases like 1<=i<=10 that are probably errors. */ - if (TREE_CODE_CLASS (code) == tcc_comparison - && (TREE_CODE_CLASS (code_left) == tcc_comparison - || TREE_CODE_CLASS (code_right) == tcc_comparison)) - warning (OPT_Wparentheses, "comparisons like X<=Y<=Z do not " - "have their mathematical meaning"); + if (code == EQ_EXPR || code == NE_EXPR) + { + if (TREE_CODE_CLASS (code_left) == tcc_comparison + || TREE_CODE_CLASS (code_right) == tcc_comparison) + warning (OPT_Wparentheses, + "suggest parentheses around comparison in operand of %s", + code == EQ_EXPR ? "==" : "!="); + } + else if (TREE_CODE_CLASS (code) == tcc_comparison) + { + if ((TREE_CODE_CLASS (code_left) == tcc_comparison + && code_left != NE_EXPR && code_left != EQ_EXPR) + || (TREE_CODE_CLASS (code_right) == tcc_comparison + && code_right != NE_EXPR && code_right != EQ_EXPR)) + warning (OPT_Wparentheses, "comparisons like X<=Y<=Z do not " + "have their mathematical meaning"); + } } /* If LABEL (a LABEL_DECL) has not been used, issue a warning. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3553541..137fea5 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2007-01-31 Dirk Mueller + + gcc.dg/Wparentheses-2.c: Update and add new tests. + 2007-01-31 Ira Rosen * gcc.dg/vect/vect-37.c: Restore the original behaivior - xfail to diff --git a/gcc/testsuite/gcc.dg/Wparentheses-2.c b/gcc/testsuite/gcc.dg/Wparentheses-2.c index e4110a8..51038c2 100644 --- a/gcc/testsuite/gcc.dg/Wparentheses-2.c +++ b/gcc/testsuite/gcc.dg/Wparentheses-2.c @@ -10,58 +10,112 @@ int foo (int); int bar (int a, int b, int c) { - foo (a <= b <= c); /* { dg-warning "comparison" "correct warning" } */ + foo (a <= b <= c); /* { dg-warning "mathematical meaning" "correct warning" } */ foo ((a <= b) <= c); foo (a <= (b <= c)); - foo (1 <= 2 <= c); /* { dg-warning "comparison" "correct warning" } */ + foo (1 <= 2 <= c); /* { dg-warning "mathematical meaning" "correct warning" } */ foo ((1 <= 2) <= c); foo (1 <= (2 <= c)); - foo (1 <= 2 <= 3); /* { dg-warning "comparison" "correct warning" } */ + foo (1 <= 2 <= 3); /* { dg-warning "mathematical meaning" "correct warning" } */ foo ((1 <= 2) <= 3); foo (1 <= (2 <= 3)); - foo (a > b > c); /* { dg-warning "comparison" "correct warning" } */ + foo (a > b > c); /* { dg-warning "mathematical meaning" "correct warning" } */ foo ((a > b) > c); foo (a > (b > c)); - foo (1 > 2 > c); /* { dg-warning "comparison" "correct warning" } */ + foo (1 > 2 > c); /* { dg-warning "mathematical meaning" "correct warning" } */ foo ((1 > 2) > c); foo (1 > (2 > c)); - foo (1 > 2 > 3); /* { dg-warning "comparison" "correct warning" } */ + foo (1 > 2 > 3); /* { dg-warning "mathematical meaning" "correct warning" } */ foo ((1 > 2) > 3); foo (1 > (2 > 3)); - foo (a < b <= c); /* { dg-warning "comparison" "correct warning" } */ + foo (a < b <= c); /* { dg-warning "mathematical meaning" "correct warning" } */ foo ((a < b) <= c); foo (a < (b <= c)); - foo (1 < 2 <= c); /* { dg-warning "comparison" "correct warning" } */ + foo (1 < 2 <= c); /* { dg-warning "mathematical meaning" "correct warning" } */ foo ((1 < 2) <= c); foo (1 < (2 <= c)); - foo (1 < 2 <= 3); /* { dg-warning "comparison" "correct warning" } */ + foo (1 < 2 <= 3); /* { dg-warning "mathematical meaning" "correct warning" } */ foo ((1 < 2) <= 3); foo (1 < (2 <= 3)); - foo (a <= b > c); /* { dg-warning "comparison" "correct warning" } */ + foo (a <= b > c); /* { dg-warning "mathematical meaning" "correct warning" } */ foo ((a <= b) > c); foo (a <= (b > c)); - foo (1 <= 2 > c); /* { dg-warning "comparison" "correct warning" } */ + foo (1 <= 2 > c); /* { dg-warning "mathematical meaning" "correct warning" } */ foo ((1 <= 2) > c); foo (1 <= (2 > c)); - foo (1 <= 2 > 3); /* { dg-warning "comparison" "correct warning" } */ + foo (1 <= 2 > 3); /* { dg-warning "mathematical meaning" "correct warning" } */ foo ((1 <= 2) > 3); foo (1 <= (2 > 3)); - foo (a <= b == c); /* { dg-warning "comparison" "correct warning" } */ + foo (a <= b == c); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */ foo ((a <= b) == c); foo (a <= (b == c)); - foo (1 <= 2 == c); /* { dg-warning "comparison" "correct warning" } */ + foo (1 <= 2 == c); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */ foo ((1 <= 2) == c); foo (1 <= (2 == c)); - foo (1 <= 2 == 3); /* { dg-warning "comparison" "correct warning" } */ + foo (1 <= 2 == 3); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */ foo ((1 <= 2) == 3); foo (1 <= (2 == 3)); - foo (a != b != c); /* { dg-warning "comparison" "correct warning" } */ + foo (a != b != c); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */ foo ((a != b) != c); foo (a != (b != c)); - foo (1 != 2 != c); /* { dg-warning "comparison" "correct warning" } */ + foo (1 != 2 != c); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */ foo ((1 != 2) != c); foo (1 != (2 != c)); - foo (1 != 2 != 3); /* { dg-warning "comparison" "correct warning" } */ + foo (1 != 2 != 3); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */ foo ((1 != 2) != 3); foo (1 != (2 != 3)); + foo (a < b == c); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */ + foo ((a < b) == c); + foo (a < (b == c)); + foo (a > b == c); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */ + foo ((a > b) == c); + foo (a > (b == c)); + foo (a == b < c); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */ + foo ((a == b) < c); + foo (a == (b < c)); + foo (a == b > c); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */ + foo ((a == b) > c); + foo (a == (b > c)); + foo (a == b == c); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */ + foo ((a == b) == c); + foo (a == (b == c)); + foo (1 == 2 == 3); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */ + foo ((1 == 2) == 3); + foo (1 == (2 == 3)); + foo (1 < 2 == 3); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */ + foo ((1 < 2) == 3); + foo (1 < (2 == 3)); + foo (1 > 2 == 3); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */ + foo ((1 > 2) == 3); + foo (1 > (2 == 3)); + foo (1 == 2 < 3); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */ + foo ((1 == 2) < 3); + foo (1 == (2 < 3)); + foo (1 == 2 > 3); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */ + foo ((1 == 2) > 3); + foo (1 == (2 > 3)); + foo (a < b != c); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */ + foo ((a < b) != c); + foo (a < (b != c)); + foo (a > b != c); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */ + foo ((a > b) != c); + foo (a > (b != c)); + foo (a != b < c); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */ + foo ((a != b) < c); + foo (a != (b < c)); + foo (a != b > c); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */ + foo ((a != b) > c); + foo (a != (b > c)); + foo (1 < 2 != 3); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */ + foo ((1 < 2) != 3); + foo (1 < (2 != 3)); + foo (1 > 2 != 3); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */ + foo ((1 > 2) != 3); + foo (1 > (2 != 3)); + foo (1 != 2 < 3); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */ + foo ((1 != 2) < 3); + foo (1 != (2 < 3)); + foo (1 != 2 > 3); /* { dg-warning "suggest parentheses around comparison" "correct warning" } */ + foo ((1 != 2) > 3); + foo (1 != (2 > 3)); } -- 2.7.4