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
5 changes: 5 additions & 0 deletions src/passes/I64ToI32Lowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,11 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> {
params.push_back(param);
}
}
// A return call has type unreachable, so take the results from the
// original signature rather than from the call's type.
if (curr->isReturn) {
results = curr->heapType.getSignature().results;
}
return builder->makeCallIndirect(curr->table,
curr->target,
args,
Expand Down
51 changes: 51 additions & 0 deletions test/lit/passes/i64-to-i32-lowering-return-call-indirect.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.

;; RUN: foreach %s %t wasm-opt -all --i64-to-i32-lowering -S -o - | filecheck %s

;; A return_call_indirect must keep the results of its original signature.

(module
;; CHECK: (type $void (func))
(type $void (func))
(type $i64-param (func (param i64) (result i32)))
(table 1 funcref)

;; CHECK: (type $1 (func (result i32)))

;; CHECK: (type $2 (func (param i32 i32) (result i32)))

;; CHECK: (global $i64toi32_i32$HIGH_BITS (mut i32) (i32.const 0))

;; CHECK: (table $0 1 funcref)

;; CHECK: (func $void (type $void)
;; CHECK-NEXT: (return_call_indirect $0 (type $void)
;; CHECK-NEXT: (i32.const 0)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $void
(return_call_indirect (type $void)
(i32.const 0)
)
)

;; CHECK: (func $i64-param (type $1) (result i32)
;; CHECK-NEXT: (local $i64toi32_i32$0 i32)
;; CHECK-NEXT: (return_call_indirect $0 (type $2)
;; CHECK-NEXT: (block (result i32)
;; CHECK-NEXT: (local.set $i64toi32_i32$0
;; CHECK-NEXT: (i32.const 0)
;; CHECK-NEXT: )
;; CHECK-NEXT: (i32.const 1)
;; CHECK-NEXT: )
;; CHECK-NEXT: (local.get $i64toi32_i32$0)
;; CHECK-NEXT: (i32.const 0)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $i64-param (result i32)
(return_call_indirect (type $i64-param)
(i64.const 1)
(i32.const 0)
)
)
)
Loading