[cfe-dev] Incongruency in __builtin_constant_p with pointer argument

Jonathan Sauer jonathan.sauer at gmx.de
Thu Apr 28 09:47:52 PDT 2011


Hello,

>> From http://gcc.gnu.org/onlinedocs/gcc-4.4.5/gcc/Other-Builtins.html:
> 
>> You can use the built-in function __builtin_constant_p to determine
>> if a value is known to be constant at compile-time and hence that GCC
>> can perform constant-folding on expressions involving that value. The
>> argument of the function is the value to test. The function returns
>> the integer 1 if the argument is known to be a compile-time constant
>> and 0 if it is not known to be a compile-time constant. A return of 0
>> does not indicate that the value is not a constant, but merely that
>> GCC cannot prove it is a constant with the specified value of the -O
>> option.
> 
> I think that clang is right to consider pointer to static memory region
> to be constant at compile-time and hence candidate to constant-folding.
> (note that the documentation does not say "constant with a known value
> at compile-time", but "value known to be constant at compile time").

But "candidate to constant-folding" requires the latter, I think. E.g. "a + 2" cannot be
folded if the value of "a" is not known at compile-time, even if it happens to be constant.


Jonathan





More information about the cfe-dev mailing list