Skip to content

Commit bc5c222

Browse files
committed
Fix issues in count_leading_zeroes
1 parent 071606b commit bc5c222

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/intrinsic/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -889,10 +889,17 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
889889
// TODO(antoyo): use width?
890890
let arg_type = arg.get_type();
891891
let result_type = self.u32_type;
892+
let arg = if arg_type.is_signed(self.cx) {
893+
let new_type = arg_type.to_unsigned(self.cx);
894+
self.gcc_int_cast(arg, new_type)
895+
} else {
896+
arg
897+
};
898+
let arg_type = arg.get_type();
892899
let count_leading_zeroes =
893900
// TODO(antoyo): write a new function Type::is_compatible_with(&Type) and use it here
894901
// instead of using is_uint().
895-
if arg_type.is_uint(self.cx) {
902+
if arg_type.is_uchar(self.cx) || arg_type.is_ushort(self.cx) || arg_type.is_uint(self.cx) {
896903
"__builtin_clz"
897904
}
898905
else if arg_type.is_ulong(self.cx) {

0 commit comments

Comments
 (0)