[Bug middle-end/114700] middle-end optimization generates wrong code with -fsanitize=undefined

2024-04-12 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114700

--- Comment #16 from Jakub Jelinek  ---
(In reply to Hu Lin from comment #11)
> I think it doesn't mean that's not a bug with -ftrapv, it should preserve
> all overflow traps. Because it doesn't work, we use -fsanitize=undefined
> instead of it.
> 
> refer: Gcc's trapv is known not always to work correctly.

No, -ftrapv isn't a debugging tool.  There is no overflow in the expression
that GCC actually evaluates (into which the expression has been optimized).
If you have overflow in an expression that is never used, GCC with -ftrapv will
also
eliminate it as unused and won't diagnose the trap.
-fsanitize=undefined behaves in that case actually the same with -O1 and higher
(intentionally, to decrease the cost of the sanitization).  So, one needs to
use -O0 -fsanitize=undefined to get as many cases of UB in the program
diagnosed as possible.

[Bug middle-end/114700] middle-end optimization generates wrong code with -fsanitize=undefined

2024-04-12 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114700

Jakub Jelinek  changed:

   What|Removed |Added

 CC||jakub at gcc dot gnu.org

--- Comment #15 from Jakub Jelinek  ---
(In reply to Hu Lin from comment #14)
> Created attachment 57933 [details]
> Untested fix.

When a pattern already has one if, can't you just add that to the preexisting
if rather than adding yet another one.