Skip to content

Commit 12c1945

Browse files
committed
do not assume anything about the top bits in llvm intrinsics receiving i8/i16 values - while normally we can assume that the top bits are clear due to how LLVM creates the call, if the call is an ffi or constructed in a non-clang way (see rust-lang/rust#39119) then we must be careful
1 parent 62dfd0f commit 12c1945

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/library.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -951,15 +951,15 @@ LibraryManager.library = {
951951
llvm_ctlz_i8: function(x, isZeroUndef) {
952952
x = x | 0;
953953
isZeroUndef = isZeroUndef | 0;
954-
return (Math_clz32(x) | 0) - 24 | 0;
954+
return (Math_clz32(x & 0xff) | 0) - 24 | 0;
955955
},
956956

957957
llvm_ctlz_i16__asm: true,
958958
llvm_ctlz_i16__sig: 'ii',
959959
llvm_ctlz_i16: function(x, isZeroUndef) {
960960
x = x | 0;
961961
isZeroUndef = isZeroUndef | 0;
962-
return (Math_clz32(x) | 0) - 16 | 0
962+
return (Math_clz32(x & 0xffff) | 0) - 16 | 0
963963
},
964964

965965
llvm_ctlz_i64__asm: true,

0 commit comments

Comments
 (0)