On Fri, 22 Nov 2013, Marek Polacek wrote:

> 3) for integer overflow checking we will want to thwart some of the
>    folding in the C FE.  E.g., I think int a = INT_MAX + 1; is folded
>    in the FE and thus ubsan doesn't detect because it doesn't see
>    any PLUS_EXPR.

Generally, an expression with integer operands that is not an integer 
constant expression because of overflow, division by zero etc. can be 
represented in the C front end either as an INTEGER_CST with TREE_OVERFLOW 
set, or as a C_MAYBE_CONST_EXPR with C_MAYBE_CONST_EXPR_INT_OPERANDS set.  
However, there are certain cases where it's too late to create a 
C_MAYBE_CONST_EXPR (see the in_late_binary_op handling) - though maybe 
those cases aren't ones where overflow can arise (it's more about implicit 
conversions in return, assignment etc.).

So, I suppose you'd want to detect some cases of overflow and generate a 
C_MAYBE_CONST_EXPR instead of the present INTEGER_CST.

(Actually, there's a case for this sanitizing disabling all folding of 
expressions that could overflow except when required by the standard, so 
that intermediate overflows don't get optimized out, or implicitly 
converted to modulo arithmetic, etc. - of course if most folding moves to 
happen later on GIMPLE, you get that automatically.)

-- 
Joseph S. Myers
jos...@codesourcery.com

Reply via email to