-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Arithmetic tests are expecting the wrong result. VM int32, int64, uint64 evaluation does not match runtime. #11138
Comments
The tests are completely wrong and linked to VM bug #9572. Forcing runtime evaluation, we should get all 0: proc doShl(T: typedesc[SomeSignedInt], shift: int): T =
1.T shl shift
block:
let t0 = doShl(int8, 8)
let t1 = doShl(int16, 16)
let t2 = doShl(int32, 32)
let t3 = doShl(int64, 64)
echo t0
echo t1
echo t2
echo t3 Merely using a Edit: Unsigned u64 is wrong as well and showstopper for bigint library that want to do compile-time shifts like Stint Lines 132 to 141 in 3d0190f
Edit 2: |
To be honest, I don't understand these tests. Bitshifting these amount of bits in C is undefined behavior. Since the |
Maybe because Nim is not C and it's defined behavior in Nim? Wasn't that hard to figure it out, was it... |
Well the results are inconsistent and blocking megatest on arm nightlies. Please suggest a fix - either when arm or removing these overflow bit-shift tests altogether. |
Looks like the behavior is architecture dependent, see: stackoverflow. If that is the case, the tests are tied to specific architecture. If we want to make VM and runtime produce the same result, we should not let it have undefined behavior as in C, but should define the behavior for both VM and runtime in case of shift overflow. |
The tests in discussion have been removed by new, because they were incorrect. |
Test in tarithm.nim fails on armv6 and armv7 but passes on arm64.
https://github.com/nim-lang/Nim/blob/devel/tests/arithm/tarithm.nim#L129
Expected value is 1 but actual is 0. Tested 1 << 32 on a real RPi and it is 0 there as well. Seems like the test needs to be updated.
The text was updated successfully, but these errors were encountered: