public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/114700] New: Front-end optimization generates wrong code with -ftrapv.
@ 2024-04-12  2:22 lin1.hu at intel dot com
  2024-04-12  2:34 ` [Bug middle-end/114700] " pinskia at gcc dot gnu.org
                   ` (19 more replies)
  0 siblings, 20 replies; 21+ messages in thread
From: lin1.hu at intel dot com @ 2024-04-12  2:22 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114700

            Bug ID: 114700
           Summary: Front-end optimization generates wrong code with
                    -ftrapv.
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: lin1.hu at intel dot com
  Target Milestone: ---

We test GCC vs Clang with -ftrapv, and test is 
z = c  - y  - c + a  + y - b;
https://godbolt.org/z/EW1xTsazG

We think the clang is right, the overflow judgment should be performed after
each operation. But the front-end generates a - b directly, looks like there's
a bug in the front-end's handling of -ftrapv.

-ftrapv
This option generates traps for signed overflow on addition, subtraction,
multiplication operations. The options -ftrapv and -fwrapv override each other,
so using -ftrapv -fwrapv on the command-line results in -fwrapv being
effective. Note that only active options override, so using -ftrapv -fwrapv
-fno-wrapv on the command-line results in -ftrapv being effective.


We have another question, we found the front-end won't optimize z = c - y + a -
c, while z = c - y - c + a will, is this for any particular reason or is it a
bug?

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

end of thread, other threads:[~2024-04-17  1:50 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-12  2:22 [Bug c/114700] New: Front-end optimization generates wrong code with -ftrapv lin1.hu at intel dot com
2024-04-12  2:34 ` [Bug middle-end/114700] " pinskia at gcc dot gnu.org
2024-04-12  2:47 ` lin1.hu at intel dot com
2024-04-12  2:47 ` lin1.hu at intel dot com
2024-04-12  3:21 ` pinskia at gcc dot gnu.org
2024-04-12  3:26 ` pinskia at gcc dot gnu.org
2024-04-12  3:35 ` pinskia at gcc dot gnu.org
2024-04-12  3:53 ` lin1.hu at intel dot com
2024-04-12  3:56 ` lin1.hu at intel dot com
2024-04-12  5:56 ` rguenth at gcc dot gnu.org
2024-04-12  6:33 ` [Bug middle-end/114700] Front-end optimization generates wrong code with -fsanitize=undefined xry111 at gcc dot gnu.org
2024-04-12  6:44 ` lin1.hu at intel dot com
2024-04-12  7:12 ` lin1.hu at intel dot com
2024-04-12  7:14 ` xry111 at gcc dot gnu.org
2024-04-12  8:51 ` lin1.hu at intel dot com
2024-04-12 10:15 ` [Bug middle-end/114700] middle-end " jakub at gcc dot gnu.org
2024-04-12 10:25 ` jakub at gcc dot gnu.org
2024-04-15  3:43 ` [Bug middle-end/114700] middle-end optimization generates causes -fsanitize=undefined not to happen in some cases lin1.hu at intel dot com
2024-04-15  6:49 ` jakub at gcc dot gnu.org
2024-04-15  7:44 ` lin1.hu at intel dot com
2024-04-17  1:50 ` lin1.hu at intel 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).