Skip to content
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

Fix handling of large branch values in cranelift_frontend::Switch #8422

Merged
merged 1 commit into from Apr 21, 2024

Conversation

bjorn3
Copy link
Contributor

@bjorn3 bjorn3 commented Apr 20, 2024

Previously trying to branch on a i128 with a branch value larger than i64::MAX after truncating to u64 would result in the branch value incorrectly getting interpreted as a value with the upper 64 bits being 1 rather than 0.

Fixes rust-lang/rustc_codegen_cranelift#1484

Previously trying to branch on a i128 with a branch value larger than
i64::MAX after truncating to u64 would result in the branch value incorrectly
getting interpreted as a value with the upper 64 bits being 1 rather than 0.
@bjorn3 bjorn3 requested a review from a team as a code owner April 20, 2024 11:29
@bjorn3 bjorn3 requested review from elliottt and removed request for a team April 20, 2024 11:29
@github-actions github-actions bot added the cranelift Issues related to the Cranelift code generator label Apr 20, 2024
Comment on lines +293 to +294
assert!(u64::try_from(y).is_ok());
bx.ins().icmp_imm(cond, x, y as i64)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assert/conversion combination is a little surprising. If y converts to u64, doesn't that mean that there's a possibility that it would produce a negative i64 value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A negative i64 here is fine as the value on which we are operating is at most a 64bit integer and thus no implicit sign extension of the immediate will be done by icmp_imm.

@elliottt elliottt added this pull request to the merge queue Apr 21, 2024
Merged via the queue into bytecodealliance:main with commit 4d25a4f Apr 21, 2024
21 checks passed
@bjorn3 bjorn3 deleted the fix_switch_u128_handling branch April 22, 2024 09:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cranelift Issues related to the Cranelift code generator
Projects
None yet
Development

Successfully merging this pull request may close these issues.

u128 comparison fails with opt-level 1
2 participants