Skip to content
Merged
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
12 changes: 9 additions & 3 deletions src/passes/Directize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,15 @@ struct FunctionDirectizer : public WalkerPass<PostWalker<FunctionDirectizer>> {

// Everything looks good!
auto name = std::get<CallUtils::Known>(info).target;
replaceCurrent(
Builder(*getModule())
.makeCall(name, operands, original->type, original->isReturn));
auto results = getModule()->getFunction(name)->getResults();
replaceCurrent(Builder(*getModule())
.makeCall(name, operands, results, original->isReturn));

// When we call a function of a subtype of the call_indirect's call type, we
// may be refining results.
if (results != original->type) {
changedTypes = true;
}
}
};

Expand Down
37 changes: 37 additions & 0 deletions test/lit/passes/directize-gc.wast
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,40 @@
)
)

;; call_indirect using the supertype. The direct call has a more refined type,
;; which we must update the IR to.
(module
(rec
;; CHECK: (rec
;; CHECK-NEXT: (type $super (sub (func (result (ref any)))))
(type $super (sub (func (result (ref any)))))
;; CHECK: (type $sub (sub $super (func (result (ref none)))))
(type $sub (sub $super (func (result (ref none)))))
)

;; CHECK: (table $table 42 funcref)
(table $table 42 funcref)
;; CHECK: (elem $elem (i32.const 0) $sub)
(elem $elem (i32.const 0) $sub)

;; CHECK: (func $super (type $super) (result (ref any))
;; CHECK-NEXT: (block $show-type (result (ref none))
;; CHECK-NEXT: (call $sub)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $super (type $super) (result (ref any))
(block $show-type (result (ref any))
(call_indirect $table (type $super)
(i32.const 0)
)
)
)

;; CHECK: (func $sub (type $sub) (result (ref none))
;; CHECK-NEXT: (unreachable)
;; CHECK-NEXT: )
(func $sub (type $sub) (result (ref none))
(unreachable)
)
)

Loading