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

Cranelift: miscompilation for shl.i128 with zero shift amount #2679

Closed
bjorn3 opened this issue Feb 23, 2021 · 2 comments
Closed

Cranelift: miscompilation for shl.i128 with zero shift amount #2679

bjorn3 opened this issue Feb 23, 2021 · 2 comments
Labels
bug Incorrect behavior in the current implementation that needs fixing cranelift Issues related to the Cranelift code generator

Comments

@bjorn3
Copy link
Contributor

bjorn3 commented Feb 23, 2021

Steps to Reproduce

  • Codegen 1u128 << 0 using ishl.i128

Expected Results

The resulting value is 1.

Actual Results

The resulting value is 0x10000000000000001.

Versions and Environment

Cranelift version or commit: 98d3e68

Operating system: N/A

Architecture: x86_64

Extra Info

This only happens for a zero shift amount. Any other amount is fine.

@bjorn3 bjorn3 added bug Incorrect behavior in the current implementation that needs fixing cranelift Issues related to the Cranelift code generator labels Feb 23, 2021
@bjorn3
Copy link
Contributor Author

bjorn3 commented Feb 23, 2021

This is responsible for the miscompilation of https://github.com/bjorn3/rustc_codegen_cranelift/issues/1143.

cfallin added a commit to cfallin/wasmtime that referenced this issue Feb 23, 2021
This fixes bytecodealliance#2672 and bytecodealliance#2679, and also fixes an incorrect instruction
emission (`test` with small immediate) that we had missed earlier.

The shift-related fixes have to do with (i) shifts by 0 bits, as a
special case that must be handled; and (ii) shifts by a 128-bit amount,
which we can handle by just dropping the upper half (we only use 3--7
bits of shift amount).

This adjusts the lowerings appropriately, and also adds run-tests to
ensure that the lowerings actually execute correctly (previously we only
had compile-tests with golden lowerings; I'd like to correct this for
more ops eventually, adding run-tests beyond what the Wasm spec and
frontend covers).
@cfallin
Copy link
Member

cfallin commented Feb 26, 2021

Closed with #2682.

@cfallin cfallin closed this as completed Feb 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Incorrect behavior in the current implementation that needs fixing cranelift Issues related to the Cranelift code generator
Projects
None yet
Development

No branches or pull requests

2 participants