On Fri, 25 Jul 2014, Richard Biener wrote:

> Note the slight complication with static initializers that _do_ have
> to simplify to something (well, maybe not with -ftrapv ...).  Joseph,
> I can easily make fold fail if you don't explicitely use a constant
> folding API (int_const_binop) and -ftrapv is set.  Is it valid to
> reject
> 
> static int x = __INT_MAX__ + 1;
> 
> with an initializer-not-constant error?

Yes - -pedantic-errors already gives an error there, as it should.  Of 
course

static int x = 1 ? 0 : __INT_MAX__ + 1;

must not give an error, whereas one is OK (and required with 
-pedantic-errors) for

static int x = 0 * (__INT_MAX__ + 1);

(one of the cases where the answer you get is the same as if C integers 
had an infinite range, where some people are less concerned about ensuring 
runtime errors occur - like e.g. x * 2 / 2 - I think the starting point 
should be generating such errors whenever overflow occurs in the 
abstract machine and then possibly having options to omit some such 
errors).

(I tend to the view that -ftrapv should map to 
-fsanitize=signed-integer-overflow -fsanitize-undefined-trap-on-error so 
we only have the one implementation of these checks to get right and to 
optimize as much as possible.)

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

Reply via email to