http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48228
Summary: incorrect signed overflow warning when only 0 and 1 are used Product: gcc Version: 4.5.2 Status: UNCONFIRMED Severity: minor Priority: P3 Component: c AssignedTo: unassig...@gcc.gnu.org ReportedBy: egg...@gnu.org Created attachment 23747 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=23747 "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; }