Skip to content

cranelift: reject big-endian atomic_cas.i128 on x64 - #15464

Open
larancibia wants to merge 1 commit into
bytecodealliance:mainfrom
larancibia:cranelift/x64-reject-be-atomic-cas-i128
Open

larancibia wants to merge 1 commit into
bytecodealliance:mainfrom
larancibia:cranelift/x64-reject-be-atomic-cas-i128

Conversation

@larancibia

Copy link
Copy Markdown

The x64 lowering rule for atomic_cas.i128 in cranelift/codegen/src/isa/x64/lower.isle matched (mem_flags_data flags) instead of (little_or_native_endian flags). Unlike the fits_in_64 atomic_cas rule right above it and the other x64 atomic lowering rules (atomic_load, atomic_store, atomic_rmw), this let atomic_cas.i128 big compile silently into a little-endian lock cmpxchg16b without byte-swapping.

This switches the rule to (little_or_native_endian flags) and adds atomic_cas.i64 and atomic_cas.i128 cases to cranelift/filetests/filetests/isa/x64/big-endian.clif (enabling has_cmpxchg16b on the target line so the i128 case exercises the endianness check rather than failing on the CPU feature check).

Tested locally with:

  • clif-util test cranelift/filetests/filetests/isa/x64/big-endian.clif (failed before the fix with Expected compilation failure but compilation succeeded, passes after)
  • clif-util test cranelift/filetests/filetests/isa/x64/atomic-*.clif cranelift/filetests/filetests/isa/x64/atomic_cas_const_addr.clif

The x64 ISLE lowering rule for `atomic_cas` on `i128` matched
`(mem_flags_data flags)` instead of `(little_or_native_endian flags)`,
so big-endian `atomic_cas.i128` silently lowered to a little-endian
`lock cmpxchg16b` instead of failing compilation like the other x64
atomic rules.

Switch the rule to `(little_or_native_endian flags)` and add
`atomic_cas.i64` and `atomic_cas.i128` cases to x64 `big-endian.clif`
(enabling `has_cmpxchg16b` on the target line so the `i128` test
exercises the endianness guard rather than failing on the feature check).
@larancibia
larancibia requested a review from a team as a code owner November 25, 2026 23:56
@larancibia
larancibia requested review from cfallin and removed request for a team November 25, 2026 23:56
@github-actions github-actions Bot added cranelift Issues related to the Cranelift code generator cranelift:area:x64 Issues related to x64 codegen labels Nov 26, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cranelift:area:x64 Issues related to x64 codegen cranelift Issues related to the Cranelift code generator

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant