public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/103103] New: Incorrect integer optimization omits x < 0 comparison
@ 2021-11-05 21:03 k.melekhin at gmail dot com
2021-11-05 21:10 ` [Bug c/103103] " pinskia at gcc dot gnu.org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: k.melekhin at gmail dot com @ 2021-11-05 21:03 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103103
Bug ID: 103103
Summary: Incorrect integer optimization omits x < 0 comparison
Product: gcc
Version: 11.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: k.melekhin at gmail dot com
Target Milestone: ---
Created attachment 51739
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51739&action=edit
Simple test program + version info
On higher optimization levels O2,O3 the following code omits the "newsz < 0"
comparison, likely due to invalid optimization / assumtion that value will
never change and always be 0, however this is incorrect.
See attachment, shows very simple test to reproduce. Also my gcc version
included
in that file comment.
Gcc's output with -O0 is correct. Tested with other C compilers and they
generate correct output on any optimization level.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c/103103] Incorrect integer optimization omits x < 0 comparison
2021-11-05 21:03 [Bug c/103103] New: Incorrect integer optimization omits x < 0 comparison k.melekhin at gmail dot com
@ 2021-11-05 21:10 ` pinskia at gcc dot gnu.org
2021-11-05 21:11 ` pinskia at gcc dot gnu.org
2021-11-05 21:49 ` k.melekhin at gmail dot com
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-05 21:10 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103103
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |INVALID
Status|UNCONFIRMED |RESOLVED
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Signed integer overflow is undefined and gcc is doing a valid transformation.
Use either unsigned integer arthemaric or -fwrapv.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c/103103] Incorrect integer optimization omits x < 0 comparison
2021-11-05 21:03 [Bug c/103103] New: Incorrect integer optimization omits x < 0 comparison k.melekhin at gmail dot com
2021-11-05 21:10 ` [Bug c/103103] " pinskia at gcc dot gnu.org
@ 2021-11-05 21:11 ` pinskia at gcc dot gnu.org
2021-11-05 21:49 ` k.melekhin at gmail dot com
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-05 21:11 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103103
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Also you can detect this at runtime with -fsanitize=undefined.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c/103103] Incorrect integer optimization omits x < 0 comparison
2021-11-05 21:03 [Bug c/103103] New: Incorrect integer optimization omits x < 0 comparison k.melekhin at gmail dot com
2021-11-05 21:10 ` [Bug c/103103] " pinskia at gcc dot gnu.org
2021-11-05 21:11 ` pinskia at gcc dot gnu.org
@ 2021-11-05 21:49 ` k.melekhin at gmail dot com
2 siblings, 0 replies; 4+ messages in thread
From: k.melekhin at gmail dot com @ 2021-11-05 21:49 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103103
--- Comment #3 from Kyryl Melekhin <k.melekhin at gmail dot com> ---
Thank you!
I figured that this has something to do with being UB behavior with int
overflow, however it's strange to find this kind of bug only on 1 compiler,
with no possible warnings or idications that something is wrong. Perhaps a
warning of UB into overflow from compiler be nice.
Have a good day.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-11-05 21:49 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-05 21:03 [Bug c/103103] New: Incorrect integer optimization omits x < 0 comparison k.melekhin at gmail dot com
2021-11-05 21:10 ` [Bug c/103103] " pinskia at gcc dot gnu.org
2021-11-05 21:11 ` pinskia at gcc dot gnu.org
2021-11-05 21:49 ` k.melekhin at gmail dot com
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).