public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/49234] New: -Wstrict-overflow gives obviously unwarranted warning
@ 2011-05-30 17:14 jim at meyering dot net
  2011-05-30 20:45 ` [Bug tree-optimization/49234] " rguenth at gcc dot gnu.org
                   ` (30 more replies)
  0 siblings, 31 replies; 32+ messages in thread
From: jim at meyering dot net @ 2011-05-30 17:14 UTC (permalink / raw)
  To: gcc-bugs

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.


^ permalink raw reply	[flat|nested] 32+ messages in thread

end of thread, other threads:[~2015-06-26 20:31 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-30 17:14 [Bug c/49234] New: -Wstrict-overflow gives obviously unwarranted warning jim at meyering dot net
2011-05-30 20:45 ` [Bug tree-optimization/49234] " rguenth at gcc dot gnu.org
2011-05-31  8:44 ` [Bug tree-optimization/49234] [4.4/4.5/4.7/4.7 Regression] " jakub at gcc dot gnu.org
2011-05-31  9:06 ` jakub at gcc dot gnu.org
2011-08-01 14:04 ` rguenth at gcc dot gnu.org
2012-03-13 15:10 ` [Bug tree-optimization/49234] [4.5/4.7/4.8/4.7/4.8 " jakub at gcc dot gnu.org
2012-07-02 11:37 ` rguenth at gcc dot gnu.org
2013-02-28 13:51 ` aldyh at gcc dot gnu.org
2013-02-28 15:49 ` aldyh at gcc dot gnu.org
2013-02-28 16:01 ` [Bug tree-optimization/49234] [4.5/4.6/4.7/4.8 " aldyh at gcc dot gnu.org
2013-02-28 20:41 ` manu at gcc dot gnu.org
2013-03-01 11:46 ` rguenth at gcc dot gnu.org
2013-03-01 14:53 ` ian at airs dot com
2013-03-01 19:18 ` aldyh at redhat dot com
2013-03-01 19:23 ` ian at airs dot com
2013-03-01 19:34 ` aldyh at redhat dot com
2013-03-04  9:58 ` rguenther at suse dot de
2013-03-05 18:01 ` aldyh at gcc dot gnu.org
2013-03-06  8:56 ` [Bug tree-optimization/49234] [4.6/4.7/4.8 " rguenth at gcc dot gnu.org
2013-03-06 16:12 ` aldyh at gcc dot gnu.org
2013-03-06 16:19 ` ian at airs dot com
2013-03-06 16:28 ` aldyh at gcc dot gnu.org
2013-03-07  8:37 ` rguenther at suse dot de
2013-04-12  8:40 ` [Bug tree-optimization/49234] [4.6/4.7/4.8/4.9 " rguenth at gcc dot gnu.org
2013-04-12 15:18 ` [Bug tree-optimization/49234] [4.7/4.8/4.9 " jakub at gcc dot gnu.org
2014-06-12 13:48 ` [Bug tree-optimization/49234] [4.7/4.8/4.9/4.10 " rguenth at gcc dot gnu.org
2014-12-19 13:32 ` [Bug tree-optimization/49234] [4.8/4.9/5 " jakub at gcc dot gnu.org
2015-02-27 19:14 ` aldyh at gcc dot gnu.org
2015-03-02  9:18 ` [Bug tree-optimization/49234] [4.8/4.9 " rguenth at gcc dot gnu.org
2015-06-23  8:25 ` rguenth at gcc dot gnu.org
2015-06-26 20:00 ` [Bug tree-optimization/49234] [4.9 " jakub at gcc dot gnu.org
2015-06-26 20:31 ` jakub at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).