https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66582
Bug ID: 66582 Summary: -Wstrict-overflow issues invalid warning. Product: gcc Version: 4.8.4 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: matthias.meixner at verifone dot com Target Milestone: --- Compiling the code below gives a warning when compiled as follows. gcc -O3 -Wall -c opt.c -DSHOWWARN opt.c: In function ‘test’: opt.c:18:9: warning: assuming signed overflow does not occur when assuming that (X + c) >= X is always true [-Wstrict-overflow] if(tst > last || tst < first) return 1234; ^ opt.c:13:23: warning: assuming signed overflow does not occur when assuming that (X + c) >= X is always true [-Wstrict-overflow] if (first > tst && tst > last ) return 1234; The strange thing is that it does not give any warning at all, when compiled using: gcc -O3 -Wall -c opt.c The difference between the two is just the order of the comparisons which should not make any real difference. This is the code that was used: ================================== int get(int *a, int *b); int test() { int last,tst,first; get(&last,&first); tst = last; if (tst <=0) tst += 9999; if (first > last) { if (first > tst && tst > last ) return 1234; } else { #ifdef SHOWWARN if(tst > last || tst < first) return 1234; #else if(tst < first || tst > last) return 1234; #endif } return 4321; }