aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDirk Mueller <dmueller@suse.de>2007-01-31 13:43:40 +0000
committerDirk Mueller <mueller@gcc.gnu.org>2007-01-31 13:43:40 +0000
commite7917d06e81b8ec0b763bd479861cb60e029bbb9 (patch)
tree3d17c03e4ce96fde3fa173a9f6e9fbd5991de70e
parentd9f414687eff2b7d3b4ffbd7f0ce00d892d76a90 (diff)
downloadgcc-e7917d06e81b8ec0b763bd479861cb60e029bbb9.zip
gcc-e7917d06e81b8ec0b763bd479861cb60e029bbb9.tar.gz
gcc-e7917d06e81b8ec0b763bd479861cb60e029bbb9.tar.bz2
c-common.c (warn_about_parentheses): Separate warning about un-parenthized sequence of comparison operators from the...
2007-01-31 Dirk Mueller <dmueller@suse.de> * 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. From-SVN: r121421
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/c-common.c23
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gcc.dg/Wparentheses-2.c90
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 <dmueller@suse.de>
+
+ * 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 <ubizjak@gmail.com>
* 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 <dmueller@suse.de>
+
+ gcc.dg/Wparentheses-2.c: Update and add new tests.
+
2007-01-31 Ira Rosen <irar@il.ibm.com>
* 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));
}