Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/passes/OptimizeInstructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1589,6 +1589,10 @@ struct OptimizeInstructions
// Given the large amount of potential benefit we can get from a successful
// optimization in GUFA, any reduction there may be a bad idea, so we
// should be very careful and probably *not* remove such casts.
//
// The only case where we are always ok to remove such casts is when lastOpts
// is true, because nothing significant runs after us that can be harmed. That
// logic is in the StripRefiningCasts pass.

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.

Drive-by comment?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes.


// If an instruction traps on a null input, there is no need for a
// ref.as_non_null on that input: we will trap either way (and the binaryen
Expand Down
19 changes: 12 additions & 7 deletions src/wasm-interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -4616,14 +4616,19 @@ class ModuleRunnerBase : public ExpressionRunner<SubType> {
if (newSize > memory->max) {
return fail;
}
if (!info.interface()->growMemory(
info.name, (memorySize << pageSizeLog2), (newSize << pageSizeLog2))) {
// We failed to grow the memory in practice, even though it was valid
// to try to do so.
return fail;
// Only grow if we are actually changing the size (otherwise it is wasted
// work, and may OOM unnecessarily).
if (delta != 0) {
if (!info.interface()->growMemory(info.name,
(memorySize << pageSizeLog2),
(newSize << pageSizeLog2))) {
// We failed to grow the memory in practice, even though it was valid
// to try to do so.
return fail;
}
memorySize = newSize;
info.instance->setMemorySize(info.name, memorySize);
}
memorySize = newSize;
info.instance->setMemorySize(info.name, memorySize);
return ret;
}
Flow visitMemoryInit(MemoryInit* curr) {
Expand Down
19 changes: 19 additions & 0 deletions test/lit/exec/memory.grow-huge.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
;; NOTE: Assertions have been generated by update_lit_checks.py --output=fuzz-exec and should not be edited.

;; RUN: wasm-opt %s -all --fuzz-exec-before -q -o /dev/null 2>&1 | filecheck %s

;; The memory here is over 2GB in size. We grow it by size 0, that is, just
;; retrieve the size without changing it. We should not error on an OOM here.

(module
(memory i64 32769)

;; CHECK: [fuzz-exec] export measure
;; CHECK-NEXT: [fuzz-exec] note result: measure => 32769
(func $measure (export "measure") (result i64)
;; This will return the size, 32769, and not -1 to indicate an OOM.
(memory.grow
(i64.const 0)
)
)
)
Loading