You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
will trip UB checks. This is caused by an improper implementation of the 128 bit ctlz intrinsic. Currently, this intrinsic first checks if the argument is not 0, and then counts the leading zeroes in the high and low 8 bytes of the value - separately.
This is incorrect: if either the low xor the high bytes are zero, then counting the leading zeroes in those 8 byte numbers is UB.
Here is the relevant part of GIMPLE, which shows the underlying issue:
In the case of param0 = 1_u128, the top if will jump to else. There, the value _2 will be zero(the high 8 bytes of 1_u128 are zero). This means that the value of _3 will also be zero, and on this line:
_4 = __builtin_clzll (_3);
__builtin_clzll will be called with an argument of 0, which is UB.
The text was updated successfully, but these errors were encountered:
I'd like to try to solve this one to get started.
I found what I think is the implementation in src/intrinsic/mod.rs. The first part is fn codegen_intrinsic_call and the other part in fn count_leading_zeros.
One thing I don't know is how to test the changes I will make.
How to run the compiler tests with -Cllvm-args=santize-undefined ?
How to view the update GIMPLE output ?
Is there a smaller test than the whole compiler tests suite to check the behaviour ?
Originally discovered by running compiler tests with
-Cllvm-args=santize-undefined
.Running the following piece of code:
will trip UB checks. This is caused by an improper implementation of the 128 bit ctlz intrinsic. Currently, this intrinsic first checks if the argument is not 0, and then counts the leading zeroes in the high and low 8 bytes of the value - separately.
This is incorrect: if either the low xor the high bytes are zero, then counting the leading zeroes in those 8 byte numbers is UB.
Here is the relevant part of GIMPLE, which shows the underlying issue:
In the case of
param0 = 1_u128
, the topif
will jump toelse
. There, the value_2
will be zero(the high 8 bytes of 1_u128 are zero). This means that the value of_3
will also be zero, and on this line:__builtin_clzll
will be called with an argument of0
, which is UB.The text was updated successfully, but these errors were encountered: