[lld] 304264e - [lld][WebAssembly] Emit all return types of multivalue functions

Thomas Lively via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 12 13:14:28 PDT 2020


Author: Samuel Kostial
Date: 2020-08-12T13:14:15-07:00
New Revision: 304264e73d2956e18083cdcdafecf57b1677a25a

URL: https://github.com/llvm/llvm-project/commit/304264e73d2956e18083cdcdafecf57b1677a25a
DIFF: https://github.com/llvm/llvm-project/commit/304264e73d2956e18083cdcdafecf57b1677a25a.diff

LOG: [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

Added: 
    lld/test/wasm/multivalue-return-func-types.s

Modified: 
    lld/wasm/WriterUtils.cpp

Removed: 
    


################################################################################
diff  --git a/lld/test/wasm/multivalue-return-func-types.s b/lld/test/wasm/multivalue-return-func-types.s
new file mode 100644
index 000000000000..aecfdb483397
--- /dev/null
+++ b/lld/test/wasm/multivalue-return-func-types.s
@@ -0,0 +1,80 @@
+# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.o %s
+# RUN: wasm-ld %t.o -o %t.wasm
+# RUN: obj2yaml %t.wasm | FileCheck %s
+
+.globl _start
+.globl fn_i32
+.globl fn_i32_i32
+.globl fn_i32_i64
+.globl fn_i64_f64_i32_f32
+
+
+_start:
+  .functype _start () -> ()
+  call fn_i32
+  drop
+  call fn_i32_i32
+  drop
+  drop
+  call fn_i32_i64
+  drop
+  drop
+  call fn_i64_f64_i32_f32
+  drop
+  drop
+  drop
+  drop
+  end_function
+
+fn_i32:
+  .functype fn_i32 () -> (i32)
+  i32.const 1
+  end_function
+
+fn_i32_i32:
+  .functype fn_i32_i32 () -> (i32, i32)
+  i32.const 1
+  i32.const 1
+  end_function
+
+fn_i32_i64:
+  .functype fn_i32_i64 () -> (i32, i64)
+  i32.const 1
+  i64.const 1
+  end_function
+
+fn_i64_f64_i32_f32:
+  .functype fn_i64_f64_i32_f32 () -> (i64, f64, i32, f32)
+  i64.const 1
+  f64.const 1.0
+  i32.const 1
+  f32.const 1.0
+  end_function
+
+
+# CHECK:       - Type:            TYPE
+# CHECK-NEXT:    Signatures:
+# CHECK-NEXT:      - Index:           0
+# CHECK-NEXT:        ParamTypes:      []
+# CHECK-NEXT:        ReturnTypes:     []
+# CHECK-NEXT:      - Index:           1
+# CHECK-NEXT:        ParamTypes:      []
+# CHECK-NEXT:        ReturnTypes:
+# CHECK-NEXT:           - I32
+# CHECK-NEXT:      - Index:           2
+# CHECK-NEXT:        ParamTypes:      []
+# CHECK-NEXT:        ReturnTypes:
+# CHECK-NEXT:           - I32
+# CHECK-NEXT:           - I32
+# CHECK-NEXT:      - Index:           3
+# CHECK-NEXT:        ParamTypes:      []
+# CHECK-NEXT:        ReturnTypes:
+# CHECK-NEXT:           - I32
+# CHECK-NEXT:           - I64
+# CHECK-NEXT:      - Index:           4
+# CHECK-NEXT:        ParamTypes:      []
+# CHECK-NEXT:        ReturnTypes:
+# CHECK-NEXT:           - I64
+# CHECK-NEXT:           - F64
+# CHECK-NEXT:           - I32
+# CHECK-NEXT:           - F32

diff  --git a/lld/wasm/WriterUtils.cpp b/lld/wasm/WriterUtils.cpp
index 436d34e3439a..9206d2fa68e9 100644
--- a/lld/wasm/WriterUtils.cpp
+++ b/lld/wasm/WriterUtils.cpp
@@ -119,8 +119,8 @@ void writeSig(raw_ostream &os, const WasmSignature &sig) {
     writeValueType(os, paramType, "param type");
   }
   writeUleb128(os, sig.Returns.size(), "result Count");
-  if (sig.Returns.size()) {
-    writeValueType(os, sig.Returns[0], "result type");
+  for (ValType returnType : sig.Returns) {
+    writeValueType(os, returnType, "result type");
   }
 }
 


        


More information about the llvm-commits mailing list