From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29486 invoked by alias); 30 May 2011 16:57:15 -0000 Received: (qmail 29471 invoked by uid 22791); 30 May 2011 16:57:14 -0000 X-SWARE-Spam-Status: No, hits=-2.7 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 30 May 2011 16:56:58 +0000 From: "jim at meyering dot net" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/49234] New: -Wstrict-overflow gives obviously unwarranted warning X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Keywords: X-Bugzilla-Severity: minor X-Bugzilla-Who: jim at meyering dot net X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Date: Mon, 30 May 2011 17:14:00 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2011-05/txt/msg03035.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49234 Summary: -Wstrict-overflow gives obviously unwarranted warning Product: gcc Version: 4.7.0 Status: UNCONFIRMED Severity: minor Priority: P3 Component: c AssignedTo: unassigned@gcc.gnu.org ReportedBy: jim@meyering.net Given this code, in file k.c, -O2 -Wstrict-overflow evokes a warning. However, since the only values assigned to "state" are 0, 1 and 2, gcc should be able to determine that no overflow is possible, and hence should issue no warning: char * trim2 (char *d) { int state = 0; char *r; int i; for (i = 0; d[i]; i++) { if (state == 0 && d[i] == ' ') continue; if (state == 0) /* line 13 */ state = 1; if (state == 1) { state = 2; r = d + i; } } if (state == 2) *r = '\0'; return d; } $ gcc -O2 -Wstrict-overflow -c k.c k.c: In function 'trim2': k.c:13:10: warning: assuming signed overflow does not occur when simplifying conditional to constant [-Wstrict-overflow] For the record, until recently I would not have bothered enabling -Wstrict-overflow, due to the high proportion of false-positives, but since I've learned about the risk of this bug, http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33498 I am now more inclined to use -Wstrict-overflow in spite of that.