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
25 changes: 25 additions & 0 deletions test/lit/passes/safe-heap-start-import.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited.
;; RUN: wasm-opt %s --safe-heap -S -o - | filecheck %s

;; 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))
(memory 1 1)

;; CHECK: (start $start)
(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)
)
)