Bug 48228 - incorrect signed overflow warning when only 0 and 1 are used
Summary: incorrect signed overflow warning when only 0 and 1 are used
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.5.2
: P3 minor
Target Milestone: 4.6.1
Assignee: Richard Biener
URL:
Keywords:
: 48432 (view as bug list)
Depends on:
Blocks:
 
Reported: 2011-03-22 07:37 UTC by Paul Eggert
Modified: 2011-04-04 09:19 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work: 4.6.1, 4.7.0
Known to fail: 4.6.0
Last reconfirmed: 2011-03-22 10:23:40


Attachments
"gcc -v -save-temps -S -Wstrict-overflow -O2 scroll.c" output (881 bytes, text/plain)
2011-03-22 07:37 UTC, Paul Eggert
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Eggert 2011-03-22 07:37:12 UTC
Created attachment 23747 [details]
"gcc -v -save-temps -S -Wstrict-overflow -O2 scroll.c" output

I ran into this problem when compiling the GNU Emacs trunk with a GCC
4.5.2 that I built on RHEL 5.5 (x86-64).  I narrowed it down to the
following stripped-down test case.

When I compile the following program with "gcc -S -Wstrict-overflow -O2"
GCC reports "warning: assuming signed overflow does not occur when
simplifying conditional to constant".  This warning is bogus, since
signed overflow is obviously impossible in this function: all the
types and values are unsigned, except for one variable that is only
assigned 0 and 1 to.


unsigned int
do_scrolling (unsigned int window_size, unsigned int writecost)
{
  unsigned int i = window_size;

  int terminal_window_p = 0;
  unsigned int queue = 0;

  for (i = window_size; i; i--)
    {
      if (writecost < i)
	++queue;
      else if (writecost & 1)
	terminal_window_p = 1;
    }

  if (queue > 0)
    {
      if (!terminal_window_p)
	{
	  terminal_window_p = 1;
	}
    }

  if (terminal_window_p)
    return 100;
  return 0;
}
Comment 1 Richard Biener 2011-03-22 10:23:40 UTC
Confirmed.  Similar to PR48022, this time from VRP.
Comment 2 Richard Biener 2011-03-22 10:29:28 UTC
Hm, not similar.  We have

Visiting PHI node: terminal_window_p_24 = PHI <terminal_window_p_3(8)>

    Argument #0 (8 -> 9 executable)
        terminal_window_p_3
        Value: [0, 1]
Found new range for terminal_window_p_24: [0, +INF(OVF)]

which in the end triggers this.
Comment 3 Richard Biener 2011-03-22 10:46:49 UTC
Which happens because of our way of handling iteration with PHIs.  Which
of course is very overly conservative with single-arg PHIs (or PHIs w/o
backedges).
Comment 4 Richard Biener 2011-03-22 12:40:16 UTC
Author: rguenth
Date: Tue Mar 22 12:40:09 2011
New Revision: 171287

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=171287
Log:
2011-03-22  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/48228
	* tree-vrp.c (vrp_visit_phi_node): Do not stop propagating
	for single-arg PHIs.

	* gcc.dg/Wstrict-overflow-23.c: New testcase.

Added:
    trunk/gcc/testsuite/gcc.dg/Wstrict-overflow-23.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-vrp.c
Comment 5 Richard Biener 2011-03-22 14:46:46 UTC
Fixed for 4.7.
Comment 6 Richard Biener 2011-03-28 10:14:40 UTC
Author: rguenth
Date: Mon Mar 28 10:14:34 2011
New Revision: 171595

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=171595
Log:
2011-03-28  Richard Guenther  <rguenther@suse.de>

	Backport from mainline
	2011-03-24  Richard Guenther  <rguenther@suse.de>

	PR middle-end/48269
	* tree-object-size.c (addr_object_size): Do not double-account
	for MEM_REF offsets.

	* gcc.dg/builtin-object-size-10.c: New testcase.

	2011-03-22  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/48228
	* tree-vrp.c (vrp_visit_phi_node): Do not stop propagating
	for single-arg PHIs.

	* gcc.dg/Wstrict-overflow-23.c: New testcase.

	2011-03-17  Richard Guenther  <rguenther@suse.de>

	PR middle-end/48134
	* tree-ssa.c (insert_debug_temp_for_var_def): If we propagated
	a value make sure to fold the statement.

	* gcc.dg/pr48134.c: New testcase.

	2011-03-15  Richard Guenther  <rguenther@suse.de>

	PR middle-end/48031
	* fold-const.c (fold_indirect_ref_1): Do not create new variable-sized
	or variable-indexed array accesses when in gimple form.

Added:
    branches/gcc-4_6-branch/gcc/testsuite/gcc.dg/Wstrict-overflow-23.c
    branches/gcc-4_6-branch/gcc/testsuite/gcc.dg/builtin-object-size-10.c
    branches/gcc-4_6-branch/gcc/testsuite/gcc.dg/pr48134.c
Modified:
    branches/gcc-4_6-branch/gcc/ChangeLog
    branches/gcc-4_6-branch/gcc/fold-const.c
    branches/gcc-4_6-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_6-branch/gcc/tree-object-size.c
    branches/gcc-4_6-branch/gcc/tree-ssa.c
    branches/gcc-4_6-branch/gcc/tree-vrp.c
Comment 7 Richard Biener 2011-03-28 10:21:54 UTC
And 4.6.1.  I'm not planning to backport further as it's also an optimization
change.
Comment 8 Jakub Jelinek 2011-04-04 09:19:37 UTC
*** Bug 48432 has been marked as a duplicate of this bug. ***