Commit a68ae2e1 by Marek Polacek Committed by Marek Polacek

c-common.c (warn_logical_operator): Use tree_int_cst_equal when comparing INTEGER_CSTs.

	* c-common.c (warn_logical_operator): Use tree_int_cst_equal
	when comparing INTEGER_CSTs.

	* c-c++-common/Wlogical-op-3.c: New test.

From-SVN: r224853
parent 171561ca
2015-06-23 Marek Polacek <polacek@redhat.com>
* c-common.c (warn_logical_operator): Use tree_int_cst_equal
when comparing INTEGER_CSTs.
2015-06-22 Pierre-Marie de Rodat <derodat@adacore.com>
* c-ada-spec.h (cpp_operation): Add HAS_DEPENDENT_TEMPLATE_ARGS.
......
......@@ -1838,7 +1838,8 @@ warn_logical_operator (location_t location, enum tree_code code, tree type,
}
/* Or warn if the operands have exactly the same range, e.g.
A > 0 && A > 0. */
else if (low0 == low1 && high0 == high1)
else if (tree_int_cst_equal (low0, low1)
&& tree_int_cst_equal (high0, high1))
{
if (or_op)
warning_at (location, OPT_Wlogical_op,
......
2015-06-23 Marek Polacek <polacek@redhat.com>
* c-c++-common/Wlogical-op-3.c: New test.
2015-06-23 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/66254
......
/* { dg-do compile } */
/* { dg-options "-Wlogical-op" } */
void
fn1 (int a)
{
const int x = a;
if (x && x) {} /* { dg-warning "logical .and. of equal expressions" } */
if (x && (int) x) {} /* { dg-warning "logical .and. of equal expressions" } */
if ((int) x && x) {} /* { dg-warning "logical .and. of equal expressions" } */
if ((int) x && (int) x) {} /* { dg-warning "logical .and. of equal expressions" } */
}
void
fn2 (int a)
{
const int x = a;
if (x || x) {} /* { dg-warning "logical .or. of equal expressions" } */
if (x || (int) x) {} /* { dg-warning "logical .or. of equal expressions" } */
if ((int) x || x) {} /* { dg-warning "logical .or. of equal expressions" } */
if ((int) x || (int) x) {} /* { dg-warning "logical .or. of equal expressions" } */
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment