biggdawg320 opened PR #14712 from biggdawg320:jobscout/14693-cranelift-miscompile-on-aarch64-w-o-lse to bytecodealliance:main:
On aarch64 targets without LSE, the
atomic_cas.i32compare-and-swap loop compared the expected value against the loaded value using a full 64-bitcmp, unlike the I8/I16 cases which already masked to their own width via UXTB/UXTH. Sinceireduceis a free no-op that doesn't clear unused high bits, an i32 expected value derived from an i64 with garbage upper bits could cause the comparison to spuriously fail even though the low 32 bits matched, silently skipping the swap. The fix special-cases I32 to clear thesfbit so the comparison only looks at the low 32 bits (cmp w27, w26), matching the i8/i16 treatment. Updated the pre-existing isa/aarch64/atomic-cas.clif fixture and the cranelift-codegen emit_tests.rs golden binary encoding forAtomicCASLoop { ty: I32 }(both previously asserted the old, buggy 64-bit comparison), and added runtests/issue14693.clif as a behavioral regression test.Note: cranelift/filetests/filetests/isa/aarch64/issue14693.clif, flagged by review as a near-duplicate of atomic-cas.clif, is left in place unchanged — it is already correct and harmless (passes post-fix), but my available tooling has no file-delete/rename operation, only content edits, so I could not remove it. It is safe to
git rmduring merge; runtests/issue14693.clif plus the corrected atomic-cas.clif already provide equivalent coverage without it.Fixes #14693
Testing
- Added a test (
cranelift/filetests/filetests/isa/aarch64/issue14693.clif,cranelift/filetests/filetests/runtests/issue14693.clif) that fails on the current code and passes with this change.- The surrounding tests pass:
cargo test -p cranelift-tools --test filetests --locked
_This change was drafted with AI assistance (Claude) and verified against the project's own test suite before submission._
biggdawg320 requested wasmtime-compiler-reviewers for a review on PR #14712.
biggdawg320 requested cfallin for a review on PR #14712.
github-actions[bot] added the label cranelift on PR #14712.
github-actions[bot] added the label cranelift:area:aarch64 on PR #14712.
:thumbs_up: cfallin submitted PR review.
cfallin added PR #14712 aarch64: fix atomic_cas.i32 miscompile without LSE to the merge queue.
cfallin removed PR #14712 aarch64: fix atomic_cas.i32 miscompile without LSE from the merge queue.
:check: cfallin merged PR #14712.
Last updated: Oct 31 2026 at 23:03 UTC