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

--- Comment #17 from Hu Lin <lin1.hu at intel dot com> ---
(In reply to Jakub Jelinek from comment #16)
> (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.

OK, that look like GCC's -ftrapv is not the same as clang's. Then my added
condition should be (optimize || !TYPE_OVERFLOW_SANITIZED (type)). 

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

I made a mistake on this line, it should be
+   (if (!TYPE_OVERFLOW_SANITIZED (type))
     (if (!ANY_INTEGRAL_TYPE_P (type)
         || TYPE_OVERFLOW_WRAPS (type))
      (negate (view_convert @1))
      (view_convert (negate @1))))

I can't just modify the preexisting if, the optimization shouldn't be used with
-fsanitize=undefined.

Reply via email to