[cfe-dev] Incongruency in __builtin_constant_p with pointer argument

Abramo Bagnara abramo.bagnara at gmail.com
Mon May 2 23:13:35 PDT 2011


Il 27/04/2011 23:30, Abramo Bagnara ha scritto:
> 
> $ cat t.c
> typedef const int * ptr;
> 
> const int i = 0;
> const ptr p = &i;
> 
> int a[__builtin_constant_p(i) ? 1 : -1];
> int b[__builtin_constant_p(p) ? 1 : -1];
> 
> $ clang -S t.c
> t.c:7:7: error: 'b' declared as an array with a negative size
> int b[__builtin_constant_p(p) ? 1 : -1];
>       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 1 error generated.
> $ gcc -S t.c
> t.c:6: error: size of array ‘a’ is negative
> t.c:7: error: size of array ‘b’ is negative
> 
> I'm perfectly fine with the fact that clang treats const typed variable
> as evaluatable constant (although gcc don't), but this should be the
> same for both cases.
> 
> The fix is trivial and I'll commit it myself, but before I'd like to
> know if it is preferred that __builtin_constant_p returns true for both
> or false for both.

Ping.

We have also other fixes for clang constant expr evaluator, but we need
to know the wanted policy. Currently it is not clear what is wishable
and implementation is often incongruent.

Also it need to be decided if __builtin_constant_p is tied to constant
expr evaluator or not, i.e. if the value returned by this builtin should
be the same of constant expr evaluator once taken in account the side
effects.



More information about the cfe-dev mailing list