Validate natural alignment for atomic memory operations - #8966
Conversation
Preserve memarg alignment in IR for atomic load/store/RMW/cmpxchg/wait/notify (including field delegations) so non-natural alignment fails validation. Fixes WebAssembly#8962 Signed-off-by: Gaurav Chaudhary <chaudharygaurav2004@gmail.com>
|
Thanks for the PR! Will take a look in the next few days |
|
Thanks for the PR! One high-level comment on the approach: this PR stores a redundant So let's change the approach and make this a parse-time failure instead. This is different from what the spec says but in general we don't distinguish the two in Binaryen (the spec test runner allows either type of failure for |
Fixes #8962
Atomic memory instructions were parsing
memargalignment but not keeping it in the IR for RMW, cmpxchg, wait, and notify. The builder also forced natural alignment, so invalid alignment from WAT or binary input was silently normalized and passed validation.The threads proposal requires atomic accesses to use natural alignment (see WebAssembly/threads#242). Binaryen should reject invalid modules rather than accept them.
This PR stores
alignon all atomic memory IR nodes, threads it through WAT/binary parsing and printing, and validates it centrally via the existingvalidateAlignment(..., isAtomic=true)check. The DeAlign pass skips atomic load/store so it does not rewrite their alignment. Adds lit tests and unskipsthreads/atomic.wast.Test plan
test/lit/validation/atomic-alignment.wasttest/lit/passes/dealign-atomics.wastthreads/atomic.wast(unskipped)