User account creation filtered due to spam.

Bug 46850 - optimization of inline function leads to incorrect integer comparison result
Summary: optimization of inline function leads to incorrect integer comparison result
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.4.5
: P3 minor
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-12-08 15:31 UTC by brad.king
Modified: 2010-12-08 15:57 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Bash script to reproduce bug (293 bytes, application/x-sh)
2010-12-08 15:31 UTC, brad.king
Details

Note You need to log in before you can comment on or make changes to this bug.
Description brad.king 2010-12-08 15:31:20 UTC
Created attachment 22686 [details]
Bash script to reproduce bug

The output of the attached script is expected to be "0" but is "1".
Tested on GCC 4.4.5, Linux x86_64, but I believe it occurs elsewhere too and in other versions.

At first I encountered the problem with -O2 but then narrowed it down to

  -O -fstrict-overflow -foptimize-sibling-calls -ftree-vrp

as shown in the script.  Adding

  -fno-guess-branch-probability

fixes the problem.  Removing "inline" from the function fixes the problem.
Comment 1 Richard Biener 2010-12-08 15:35:41 UTC
You invoke undefined behavior by overflowing a signed integer.
Comment 2 brad.king 2010-12-08 15:57:25 UTC
[smacks forehead]