Skip to content

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

Merged
cfallin merged 1 commit into
bytecodealliance:mainfrom
larancibia:cranelift/x64-reject-be-atomic-cas-i128
Nov 29, 2026
Merged

cfallin merged 1 commit into
bytecodealliance:mainfrom
larancibia:cranelift/x64-reject-be-atomic-cas-i128

Conversation

@larancibia

Copy link
Copy Markdown
Contributor

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

@cfallin cfallin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, good catch!

@cfallin
cfallin added this pull request to the merge queue Nov 29, 2026
Merged via the queue into bytecodealliance:main with commit 88b8d15 Nov 29, 2026
56 checks passed
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.

2 participants