diff options
| author | Antoni Boucher <bouanto@zoho.com> | 2025-08-01 11:29:05 -0400 |
|---|---|---|
| committer | Antoni Boucher <bouanto@zoho.com> | 2025-08-01 11:29:05 -0400 |
| commit | bc5c2229d01cd06bfd91476636409d619bd5a807 (patch) | |
| tree | 50d9f2201eeb3ecbd3120225d845f4e2d115101a | |
| parent | 071606b2a385b734fddf27d67a60484dc7df1797 (diff) | |
| download | rust-bc5c2229d01cd06bfd91476636409d619bd5a807.tar.gz rust-bc5c2229d01cd06bfd91476636409d619bd5a807.zip | |
Fix issues in count_leading_zeroes
| -rw-r--r-- | src/intrinsic/mod.rs | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/intrinsic/mod.rs b/src/intrinsic/mod.rs index 21b650bdecd..57bdbad5e53 100644 --- a/src/intrinsic/mod.rs +++ b/src/intrinsic/mod.rs @@ -889,10 +889,17 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> { // TODO(antoyo): use width? let arg_type = arg.get_type(); let result_type = self.u32_type; + let arg = if arg_type.is_signed(self.cx) { + let new_type = arg_type.to_unsigned(self.cx); + self.gcc_int_cast(arg, new_type) + } else { + arg + }; + let arg_type = arg.get_type(); let count_leading_zeroes = // TODO(antoyo): write a new function Type::is_compatible_with(&Type) and use it here // instead of using is_uint(). - if arg_type.is_uint(self.cx) { + if arg_type.is_uchar(self.cx) || arg_type.is_ushort(self.cx) || arg_type.is_uint(self.cx) { "__builtin_clz" } else if arg_type.is_ulong(self.cx) { |
