Skip to content
Open
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
3 changes: 3 additions & 0 deletions src/passes/SafeHeap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ static std::set<Name> findCalledFunctions(Module* module, Name startFunc) {
auto next = toVisit.back();
toVisit.pop_back();
auto* func = module->getFunction(next);
if (func->imported()) {
continue;
}
for (auto* call : FindAll<Call>(func->body).list) {
addFunction(call->target);
}
Expand Down
28 changes: 28 additions & 0 deletions test/lit/passes/safe-heap-start-import.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited.
;; RUN: wasm-opt %s --safe-heap --enable-threads --enable-simd -S -o - | filecheck %s
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
;; RUN: wasm-opt %s --safe-heap --enable-threads --enable-simd -S -o - | filecheck %s
;; RUN: wasm-opt %s --safe-heap -S -o - | filecheck %s

These features are not used in the testcase.


;; Test that safe-heap does not crash when the start function calls an imported
;; function. The findCalledFunctions helper transitively walks all called
;; functions from the start, and must skip imported functions which have no body.

(module
;; CHECK: (import "env" "some_import" (func $import))
(import "env" "some_import" (func $import))
;; CHECK: (import "env" "emscripten_get_sbrk_ptr" (func $emscripten_get_sbrk_ptr (result i32)))
(import "env" "emscripten_get_sbrk_ptr" (func $emscripten_get_sbrk_ptr (result i32)))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
(import "env" "emscripten_get_sbrk_ptr" (func $emscripten_get_sbrk_ptr (result i32)))

No need for this import.

(memory 1 1 shared)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
(memory 1 1 shared)
(memory 1 1)

No need for this to be shared.


;; CHECK: (start $start)

;; CHECK: (func $start
;; CHECK-NEXT: (call $import)
;; CHECK-NEXT: )
(func $start
;; The start function calls an imported function. Previously this would
;; crash because findCalledFunctions would try to walk the null body of
;; the imported function.
(call $import)
)

(start $start)
Copy link
Member

Choose a reason for hiding this comment

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

By convention we put this before the first function (around line 16, here)

)
Loading