Fix Memory64Lowering table.grow and table.copy handling#8311
Closed
sumleo wants to merge 1 commit intoWebAssembly:mainfrom
Closed
Fix Memory64Lowering table.grow and table.copy handling#8311sumleo wants to merge 1 commit intoWebAssembly:mainfrom
sumleo wants to merge 1 commit intoWebAssembly:mainfrom
Conversation
Two bugs in the table64 lowering: 1. visitTableGrow used a plain i64.extend_i32_u on the return value, but table.grow returns -1 on failure. ExtendUInt32 on i32(-1) produces i64(4294967295), not i64(-1). Add the same if/else -1 check pattern already used by visitMemoryGrow. 2. visitTableCopy wrapped curr->size using only the dest table's type, but the size operand is i64 only when both source and dest tables are 64-bit. When tables have mixed types, wrapping an i32 size as if it were i64 causes an assertion failure. Check both tables before wrapping.
Member
|
These fixes look separate, even if they are on the same pass? Please submit separate PRs for them. |
This was referenced Feb 12, 2026
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two bugs in the table64 lowering within
Memory64Lowering:1.
table.growreturn value doesn't handle -1 failurevisitTableGrowuses a plaini64.extend_i32_uon thetable.growreturn value. Buttable.growreturns -1 (i32) on failure, andi64.extend_i32_u(0xFFFFFFFF)produces0x00000000FFFFFFFF(4294967295), not i64 -1 (0xFFFFFFFFFFFFFFFF). Code checkingresult == -1would fail to detect the failure.The analogous
visitMemoryGrowalready has the correct handling: it uses alocal.tee+if/elseto check for -1 and returni64.const -1explicitly.Fix: Apply the same if/else -1 check pattern from
visitMemoryGrowtovisitTableGrow.2.
table.copysize wrapping uses wrong table checkvisitTableCopywrapscurr->sizeusingcurr->destTable, but the wasm spec (andchild-typer.h) defines the size type as i64 only when both source and dest tables are 64-bit. When copying between a 64-bit and a 32-bit table, the size is i32, but wrapping checks only the dest table — causing an assertion failure (assert(ptr->type == Type::i64)) when dest is 64-bit but source is 32-bit.Fix: Check both tables before wrapping the size operand.
Test plan
memory64-lowering.wasttest expectations for the new table.grow outputmemory64-lowering-table-fixes.wastcovering:table.growwith proper -1 if/else handlingtable.copyfrom 64-bit to 32-bit table (size stays i32)table.copyfrom 32-bit to 64-bit table (size stays i32)table.copybetween two 64-bit tables (all operands wrapped)