http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48432
Summary: -Wstrict-overflow incorrectly warns for Emacs src/font.c Product: gcc Version: 4.6.0 Status: UNCONFIRMED Severity: minor Priority: P3 Component: middle-end AssignedTo: unassig...@gcc.gnu.org ReportedBy: egg...@gnu.org When compiling the GNU Emacs trunk with a GCC 4.6.0 that I built on RHEL 5.6 (x86-64), I ran into a problem when compiling src/font.c that I narrowed down to the following stripped-down test case. When I compile this test case with gcc -S -Wstrict-overflow -O2 f.c the output is: f.c: In function 'font_list_entities': f.c:38:35: warning: assuming signed overflow does not occur when simplifying co nditional to constant [-Wstrict-overflow] The warning is incorrect, since signed overflow is impossible here. There are two 'int' variables, one of which is assigned only 0 or 1, and the other which is assigned only values ranging from 6 through 12. Changing either 'int' variable to 'unsigned' makes the warning go away. I'm not sure whether this bug is the same as earlier bug reports I filed in this area (PR48228, PR48267), but it's not obviously the same so I figured I should be safe and file it. It did take some time to track down. ----- extern unsigned foo0 (void); extern unsigned foo2 (unsigned, unsigned); static unsigned font_delete_unmatched (unsigned vec, unsigned spec, unsigned int size) { unsigned val = 0; while (1) { if (spec) { val = foo2 (vec, val); continue; } } return val; } unsigned font_list_entities (unsigned frame, unsigned spec) { unsigned val = 0; int need_filtering = 0; int i; for (i = 6; i < 13; i++) { if (foo0 ()) need_filtering = 1; if (i == 10) i++; } while (foo0 ()) if (need_filtering) val = font_delete_unmatched (val, need_filtering ? spec : 0, 0); return 0; }