[PATCH] Teach builtin clz, ctz, and popcount to be const

Richard Smith richard at metafoo.co.uk
Tue Jun 11 13:21:20 PDT 2013

On Tue, Jun 11, 2013 at 1:14 PM, Arthur O'Dwyer
<arthur.j.odwyer at gmail.com> wrote:
> On Tue, Jun 11, 2013 at 12:26 PM, Richard Smith <richard at metafoo.co.uk> wrote:
>>> > On Tue, Jun 11, 2013 at 12:18:55AM -0600, Justin Bogner wrote:
>>> >> The clz, ctz, and popcount builtins are trivial to add constant folded
>>> >> implementations of, and gcc accepts them in const contexts.
> [...]
>> A testcase which is less likely to pass by accident would be better (for
>> instance, your popcount tests would succeed if the builtin just returned its
>> argument, and tests with a '1' in the sign bit would be useful).
>> You should also ensure that __builtin_clz(0) and __builtin_ctz(0) are not
>> treated as constants.
> I may be displaying my ignorance here, but is it also necessary to test
> that __builtin_clz(0x123456789ABCDEF0LL) even in a constant context
> returns (int)0 and not (int)3?  (Because it truncates its argument.)

Seems reasonable to test that, although it's more of a test that we're
building the AST for __builtin_clz properly.

More information about the cfe-commits mailing list