-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
py/objint_longlong: Fix left shift of negative values. #17734
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
py/objint_longlong: Fix left shift of negative values. #17734
Conversation
Hmm, so running the
(I don't see these locally, but I have a different gcc locally.) This looks a lot like the problem @koxudaxi was describing in #17649... |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #17734 +/- ##
=======================================
Coverage 98.38% 98.38%
=======================================
Files 171 171
Lines 22239 22239
=======================================
Hits 21880 21880
Misses 359 359 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Code size report:
|
d2517f1
to
09c6e9b
Compare
Have pulled out the CI change to its own PR. |
Another option to fix the overflow check would be: if ((int)rhs_val > 62) {
overflow = 1;
} else {
rhs_val = 1ll << (int)rhs_val;
overflow = mp_mul_ll_overflow(lhs_val, rhs_val, &result);
} I am not sure which one would generate the shortest code, given that the compiler might be able to merge the call to |
Neat idea! I tried it, but unfortunately the code size is still a little bigger: (Building the Zephyr qemu cortex-m3 board as
I'm guessing either the calls can't be merged, or marshalling the values is still more work than doing the comparisons required in this version. |
09c6e9b
to
977f0a3
Compare
977f0a3
to
e31ba59
Compare
Previous comment was wrong, left shifting a negative value is UB in C. Use the same approach as small int shifts (from runtime.c). Signed-off-by: Angus Gratton <angus@redyak.com.au>
These tests all depend on generating arbitrarily long (>64-bit) integers. It would be possible to have these tests work in this case I think, as the results are always masked to shorter values. But quite fiddly. So just rename them so they are automatically skipped if the target doesn't have big int support. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
e31ba59
to
096ff8b
Compare
Summary
Closes #17702, thanks to @jepler for running these additional checks.
Note: First version of this PR enabled UBSan for longlong tests, but this surfaced another issue so has been spun out to #17735.
Testing
Trade-offs and Alternatives