diff options
Diffstat (limited to 'src/passes/MultiMemoryLowering.cpp')
-rw-r--r-- | src/passes/MultiMemoryLowering.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/passes/MultiMemoryLowering.cpp b/src/passes/MultiMemoryLowering.cpp index 9e9637b36..527a15804 100644 --- a/src/passes/MultiMemoryLowering.cpp +++ b/src/passes/MultiMemoryLowering.cpp @@ -304,12 +304,17 @@ struct MultiMemoryLowering : public Pass { sizeLocal, builder.makeMemorySize(combinedMemory, memoryInfo))); } - // TODO: Check the result of makeMemoryGrow for errors and return the error - // instead + // Attempt to grow the combinedMemory. If -1 returns, enough memory could + // not be allocated, so return -1. functionBody = builder.blockify( functionBody, - builder.makeDrop(builder.makeMemoryGrow( - builder.makeLocalGet(0, pointerType), combinedMemory, memoryInfo))); + builder.makeIf( + builder.makeBinary( + EqInt32, + builder.makeMemoryGrow( + builder.makeLocalGet(0, pointerType), combinedMemory, memoryInfo), + builder.makeConst(-1)), + builder.makeReturn(builder.makeConst(-1)))); // If we are not growing the last memory, then we need to copy data, // shifting it over to accomodate the increase from page_delta |