Bug 31602 - Overflow warning causes GDB -Werror build failure
Summary: Overflow warning causes GDB -Werror build failure
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: 4.2.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-04-17 13:21 UTC by Daniel Jacobowitz
Modified: 2007-04-24 23:27 UTC (History)
2 users (show)

See Also:
Host:
Target: mips-linux-gnu
Build:
Known to work:
Known to fail:
Last reconfirmed: 2007-04-18 15:14:27


Attachments
Proposed patch (1.28 KB, patch)
2007-04-20 16:17 UTC, Ian Lance Taylor
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Jacobowitz 2007-04-17 13:21:36 UTC
GCC HEAD now warns about this testcase for mips-linux, reduced from gdb/value.c.  Compile with -O2 -Wall:

extern int foo();
int show_values (void)
{
  int i;
  static int num;

  if (num <= 0)
    num = 1;

  for (i = num; i < num + 10; i++)
    foo();

  return i;
}

overflow.c:10: warning: assuming signed overflow does not occur when assuming that (X + c) >= X is always true

I think that the problem arises when we assume that the loop is executed at least once; the initial condition is num < num + 10.  However the warning does not arise if num is an argument to the function instead of a static variable.

Unfortunately the warning appears to be correct.  I say unfortunately because there's no apparent way to avoid the warning - which sounds more like -Wextra to -Wall.  Does this this example contradict the "easy to avoid" statement in the -Wstrict-overflow=1 documentation?
Comment 1 Daniel Jacobowitz 2007-04-17 13:26:09 UTC
Subject: Re:   New: Overflow warning causes
	GDB -Werror build failure

On Tue, Apr 17, 2007 at 12:21:36PM -0000, drow at gcc dot gnu dot org wrote:
> GCC HEAD now warns about this testcase for mips-linux, reduced from
> gdb/value.c.

The warning also occurs once in top.c:

for (offset = num; offset < num + Hist_print && offset < hist_len; offset++)

Comment 2 Ian Lance Taylor 2007-04-18 15:14:27 UTC
Yes, the warning is happening because gcc relies on undefined signed overflow when assuming that it will execute the loop at least once.  Of course when using -fwrapv the loop should not be executed at all when num > INT_MAX - 10.

I'll try to figure out what to do about this.
Comment 3 Ian Lance Taylor 2007-04-20 16:17:18 UTC
Created attachment 13394 [details]
Proposed patch

This patch fixes the test case in the PR.  I am testing it.  It would be interesting to hear whether it also fixes the actual code in gdb.
Comment 4 Daniel Jacobowitz 2007-04-20 20:04:22 UTC
Subject: Re:  Overflow warning causes GDB
	-Werror build failure

On Fri, Apr 20, 2007 at 03:17:19PM -0000, ian at airs dot com wrote:
> This patch fixes the test case in the PR.  I am testing it.  It would be
> interesting to hear whether it also fixes the actual code in gdb.

With this patch I can successfully build GDB for mips-linux - thanks!
(barring PR31605).

Comment 5 ian@gcc.gnu.org 2007-04-24 21:44:56 UTC
Subject: Bug 31602

Author: ian
Date: Tue Apr 24 21:44:45 2007
New Revision: 124120

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=124120
Log:
./:
	PR tree-optimization/31602
	* tree-ssa-loop-ch.c (copy_loop_headers): Set TREE_NO_WARNING for
	conditionals in the copied loop header.
	* tree-cfg.c (fold_cond_expr_cond): Don't issue undefined overflow
	warnings if TREE_NO_WARNING is set.
	* doc/invoke.texi (Warning Options): Clarify that
	-Wstrict-overflow does not warn about loops.
testsuite/:
	PR tree-optimization/31602
	* gcc.dg/Wstrict-overflow-11.c: We no longer issue a warning.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/doc/invoke.texi
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gcc.dg/Wstrict-overflow-11.c
    trunk/gcc/tree-cfg.c
    trunk/gcc/tree-ssa-loop-ch.c

Comment 6 ian@gcc.gnu.org 2007-04-24 22:54:32 UTC
Subject: Bug 31602

Author: ian
Date: Tue Apr 24 22:54:22 2007
New Revision: 124127

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=124127
Log:
	PR tree-optimization/31602
	* tree-ssa-loop-ch.c (copy_loop_headers): Set TREE_NO_WARNING for
	conditionals in the copied loop header.
	* tree-cfg.c (fold_cond_expr_cond): Don't issue undefined overflow
	warnings if TREE_NO_WARNING is set.
	* doc/invoke.texi (Warning Options): Clarify that
	-Wstrict-overflow does not warn about loops.

Modified:
    branches/gcc-4_2-branch/gcc/ChangeLog
    branches/gcc-4_2-branch/gcc/doc/invoke.texi
    branches/gcc-4_2-branch/gcc/tree-cfg.c
    branches/gcc-4_2-branch/gcc/tree-ssa-loop-ch.c

Comment 7 Ian Lance Taylor 2007-04-24 23:27:44 UTC
Fixed on mainline and 4.2 branch.