Skip to content

Commit 304264e

Browse files
Samuel Kostialtlively
Samuel Kostial
authored andcommitted
[lld][WebAssembly] Emit all return types of multivalue functions
We previously were incorrectly emitting only the first result type. Differential Revision: https://reviews.llvm.org/D85783
1 parent e2040d3 commit 304264e

File tree

2 files changed

+82
-2
lines changed

2 files changed

+82
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.o %s
2+
# RUN: wasm-ld %t.o -o %t.wasm
3+
# RUN: obj2yaml %t.wasm | FileCheck %s
4+
5+
.globl _start
6+
.globl fn_i32
7+
.globl fn_i32_i32
8+
.globl fn_i32_i64
9+
.globl fn_i64_f64_i32_f32
10+
11+
12+
_start:
13+
.functype _start () -> ()
14+
call fn_i32
15+
drop
16+
call fn_i32_i32
17+
drop
18+
drop
19+
call fn_i32_i64
20+
drop
21+
drop
22+
call fn_i64_f64_i32_f32
23+
drop
24+
drop
25+
drop
26+
drop
27+
end_function
28+
29+
fn_i32:
30+
.functype fn_i32 () -> (i32)
31+
i32.const 1
32+
end_function
33+
34+
fn_i32_i32:
35+
.functype fn_i32_i32 () -> (i32, i32)
36+
i32.const 1
37+
i32.const 1
38+
end_function
39+
40+
fn_i32_i64:
41+
.functype fn_i32_i64 () -> (i32, i64)
42+
i32.const 1
43+
i64.const 1
44+
end_function
45+
46+
fn_i64_f64_i32_f32:
47+
.functype fn_i64_f64_i32_f32 () -> (i64, f64, i32, f32)
48+
i64.const 1
49+
f64.const 1.0
50+
i32.const 1
51+
f32.const 1.0
52+
end_function
53+
54+
55+
# CHECK: - Type: TYPE
56+
# CHECK-NEXT: Signatures:
57+
# CHECK-NEXT: - Index: 0
58+
# CHECK-NEXT: ParamTypes: []
59+
# CHECK-NEXT: ReturnTypes: []
60+
# CHECK-NEXT: - Index: 1
61+
# CHECK-NEXT: ParamTypes: []
62+
# CHECK-NEXT: ReturnTypes:
63+
# CHECK-NEXT: - I32
64+
# CHECK-NEXT: - Index: 2
65+
# CHECK-NEXT: ParamTypes: []
66+
# CHECK-NEXT: ReturnTypes:
67+
# CHECK-NEXT: - I32
68+
# CHECK-NEXT: - I32
69+
# CHECK-NEXT: - Index: 3
70+
# CHECK-NEXT: ParamTypes: []
71+
# CHECK-NEXT: ReturnTypes:
72+
# CHECK-NEXT: - I32
73+
# CHECK-NEXT: - I64
74+
# CHECK-NEXT: - Index: 4
75+
# CHECK-NEXT: ParamTypes: []
76+
# CHECK-NEXT: ReturnTypes:
77+
# CHECK-NEXT: - I64
78+
# CHECK-NEXT: - F64
79+
# CHECK-NEXT: - I32
80+
# CHECK-NEXT: - F32

lld/wasm/WriterUtils.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ void writeSig(raw_ostream &os, const WasmSignature &sig) {
119119
writeValueType(os, paramType, "param type");
120120
}
121121
writeUleb128(os, sig.Returns.size(), "result Count");
122-
if (sig.Returns.size()) {
123-
writeValueType(os, sig.Returns[0], "result type");
122+
for (ValType returnType : sig.Returns) {
123+
writeValueType(os, returnType, "result type");
124124
}
125125
}
126126

0 commit comments

Comments
 (0)