Re: [RFC] Mitigating unexpected arithmetic overflow
From: Al Viro
Date: Thu May 09 2024 - 13:54:37 EST
On Thu, May 09, 2024 at 08:38:28AM -0700, Linus Torvalds wrote:
> Going the other way is similar:
>
> all_bits = low_bits + ((u64) high_bits << 16) << 16);
>
> and again, the compiler will recognize this idiom and do the right
> thing (and if 'all_bits' is only 32-bit, the compiler will optimize
> the high bit noise away).
Umm... That would make sense if it was
all_bits = low_bits + ((T) high_bits << 16) << 16);
with possibly 32bit T. But the way you wrote that (with u64) it's
pointless - u64 _can_ be shifted by 32 just fine.