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
This commit is contained in:
Dirk Mueller 2007-01-31 13:43:40 +00:00 committed by Dirk Mueller
parent d9f414687e
commit e7917d06e8
4 changed files with 99 additions and 24 deletions

View File

@ -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.

View File

@ -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. */

View File

@ -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

View File

@ -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));
}