Bug 52560 - if (r == -1) causes 'assuming signed overflow does not occur when simplifying conditional to constant'
Summary: if (r == -1) causes 'assuming signed overflow does not occur when simplifying...
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
Depends on:
Blocks:
 
Reported: 2012-03-12 11:18 UTC by Richard W.M. Jones
Modified: 2015-11-11 22:22 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2012-03-12 00:00:00


Attachments
50-line reproducer (325 bytes, application/octet-stream)
2012-03-12 12:30 UTC, jim
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Richard W.M. Jones 2012-03-12 11:18:55 UTC
Here is the reproducer:

wget 'http://oirase.annexia.org/strict-overflow-warning.i.xz'
unxz strict-overflow-warning.i.xz
gcc -std=gnu99 -O2 -Wstrict-overflow -c strict-overflow-warning.i

The warning is:

  inspect_fs_unix.c: In function ‘check_fstab’:
  inspect_fs_unix.c:1075:6: warning: assuming signed overflow does not occur when simplifying conditional to constant [-Wstrict-overflow]

However the code doesn't look like anything should be simplified,
or a warning:

  n_app_md_devices = map_app_md_devices (g, &app_map);
  if (n_app_md_devices == -1) goto error;

where map_app_md_devices is a function that returns an int:

  static int map_app_md_devices (guestfs_h *g, Hash_table **map);

and n_app_md_devices is also an int.

I've tried this on several versions of gcc:

gcc (GCC) 4.7.0 20120308 (Red Hat 4.7.0-0.19)
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

(for further build info, go to:
http://koji.fedoraproject.org/koji/buildinfo?buildID=305760
and click 'build logs')

Same thing with this gcc from Ubuntu 11.10:

$ gcc --version
gcc (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

We think this first started happening in gcc 4.5.1.
Comment 1 jim 2012-03-12 12:30:20 UTC
Created attachment 26877 [details]
50-line reproducer
Comment 2 Richard Biener 2012-03-12 13:22:32 UTC
It certainly inlines the function, does not figures out the loop does not run and then computes n's value-range as is [0, +INF(OVF)] and thus when simplifying
the return value comparison against -1 it says it assumes that n++ does not wrap.

Looks ok to me, though it is all because of dead code and thus a missed
VRP of some sort.
Comment 3 Richard W.M. Jones 2012-03-12 16:30:45 UTC
I see that this is actually a bug in our code.  I pushed
the following fix to libguestfs:
https://github.com/libguestfs/libguestfs/commit/d66dd2260c724bdfe57a8595aac37c8e9173cee5
Comment 4 Martin Sebor 2015-11-11 22:22:41 UTC
6.0.0 20151111 doesn't issue any warnings on either the original translation unit or the smaller test case in attachment 26877 [details].  Since comment #3 indicates the test case was buggy it doesn't seem like there's anything for us to do.

Resolving as Invalid.