On Tue, Nov 03, 2026 at 10:43:27AM +0100, [email protected] wrote:
> From: Kyrylo Tkachov <[email protected]>
>
> cfn_clz::fold_range computes the minimum of the result from the upper
> bound of the argument, and cfn_ctz::fold_range computes the maximum of
> the result from it. This is wrong for a signed argument with negative
> values, because a negative value has the sign bit set. For
>
> _1 = .CLZ (x_4(D));
> _2 = _1 > 0;
>
> with int x_4(D), evrp computes
>
> Global Exported: _1 = [irange] int [1, 31]
.CLZ/.CTZ is only defined for unsigned types, not for signed ones.
The fact that __GIMPLE parsing doesn't reject all kinds of invalid
stuff doesn't mean it is valid.
else if (!TYPE_UNSIGNED (TREE_TYPE (args[0])))
{
if (complain)
error_at (ARG_LOCATION (0),
"argument 1 in call to function "
"%qE has signed type",
fndecl);
return false;
}
in c-common.cc rejects signed arguments to __builtin_clzg/__builtin_ctzg
etc. (they are allowed (and required) for __builtin_ffsg and
__builtin_clrsbg).
Jakub