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; }
Confirmed. Similar to PR48022, this time from VRP.
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.
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).
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
Fixed for 4.7.
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
And 4.6.1. I'm not planning to backport further as it's also an optimization change.
*** Bug 48432 has been marked as a duplicate of this bug. ***