From: Richard Biener Date: Thu, 9 Oct 2014 08:20:53 +0000 (+0000) Subject: re PR tree-optimization/63445 (request: make -Wstrict-overflow avoid a class of false... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ee68591e69621b4fdbbd925044b66b6147800cf9;p=gcc.git re PR tree-optimization/63445 (request: make -Wstrict-overflow avoid a class of false positives) 2014-10-09 Richard Biener PR tree-optimization/63445 * tree-vrp.c (simplify_cond_using_ranges): Only warn about overflow for non-equality compares. * gcc.dg/Wstrict-overflow-26.c: New testcase. From-SVN: r216028 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 85bc3619af5..b8b9f3019a8 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2014-10-09 Richard Biener + + PR tree-optimization/63445 + * tree-vrp.c (simplify_cond_using_ranges): Only warn about + overflow for non-equality compares. + 2014-10-09 Uros Bizjak PR rtl-optimization/57003 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b282bc7a429..a8870ea3de7 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2014-10-09 Richard Biener + + PR tree-optimization/63445 + * gcc.dg/Wstrict-overflow-26.c: New testcase. + 2014-10-08 Pat Haugen * gcc.dg/vmx/3c-01a.c: Add default options from vmx.exp. diff --git a/gcc/testsuite/gcc.dg/Wstrict-overflow-26.c b/gcc/testsuite/gcc.dg/Wstrict-overflow-26.c new file mode 100644 index 00000000000..ef805b56d25 --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wstrict-overflow-26.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -Wstrict-overflow" } */ + +int +f (int i, int j) +{ + unsigned int c = 0; + if (i < j) + { + unsigned int n = j - i; + unsigned int i; + for (i = 0; i < n; i++) /* { dg-bogus "signed overflow" } */ + c++; + } + return c; +} diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index 011db78d734..7ca05284ede 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -9189,8 +9189,9 @@ simplify_cond_using_ranges (gimple stmt) /* If the range overflowed and the user has asked for warnings when strict overflow semantics were used to optimize code, issue an appropriate warning. */ - if ((is_negative_overflow_infinity (vr->min) - || is_positive_overflow_infinity (vr->max)) + if (cond_code != EQ_EXPR && cond_code != NE_EXPR + && (is_negative_overflow_infinity (vr->min) + || is_positive_overflow_infinity (vr->max)) && issue_strict_overflow_warning (WARN_STRICT_OVERFLOW_CONDITIONAL)) { location_t location;