[PATCH] D43885: [WebAssembly] Test types only used by call_indirect are GC'd correctly

Nicholas Wilson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 28 10:43:14 PST 2018


ncw created this revision.
ncw added a reviewer: sbc100.
Herald added subscribers: llvm-commits, sunfish, aheejin, jgravelle-google, dschuff, jfb.

I don't think it's covered by any existing tests?

Here we have a type which is called with call_indirect but not used anywhere else in the file.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D43885

Files:
  test/wasm/gc-types.ll


Index: test/wasm/gc-types.ll
===================================================================
--- /dev/null
+++ test/wasm/gc-types.ll
@@ -0,0 +1,56 @@
+; RUN: llc -filetype=obj %s -o %t.o
+; RUN: wasm-ld --check-signatures -o %t.wasm %t.o
+; RUN: obj2yaml %t.wasm | FileCheck %s
+
+target triple = "wasm32-unknown-unknown-wasm"
+
+; Check that types are GC'd if they are not used by any functions - but are
+; retained if they are used by any call_indirect instructions, even if no
+; function has that type!
+
+define hidden i64 @use_sig1(i64 %arg) {
+  ret i64 0
+}
+
+define hidden void @call_sig1(i64 (i64)* %fn) {
+  %call = call i64 %fn(i64 1)
+  ret void
+}
+
+define hidden void @call_sig2(i64 (i64, i64)* %fn) {
+  %call = call i64 %fn(i64 1, i64 2)
+  ret void
+}
+
+define hidden i64 @unused_sig3(i64 %arg1, i64 %arg2, i64 %arg3) {
+  ret i64 0
+}
+
+define hidden void @_start() {
+entry:
+  call i64 @use_sig1(i64 0)
+  call void @call_sig1(i64 (i64)* null)
+  call void @call_sig2(i64 (i64, i64)* null)
+  ret void
+}
+
+; CHECK:        - Type:            TYPE
+; CHECK-NEXT:     Signatures:
+; CHECK-NEXT:       - Index:           0
+; CHECK-NEXT:         ReturnType:      I64
+; CHECK-NEXT:         ParamTypes:
+; CHECK-NEXT:           - I64
+; CHECK-NEXT:       - Index:           1
+; CHECK-NEXT:         ReturnType:      I64
+; CHECK-NEXT:         ParamTypes:
+; CHECK-NEXT:           - I64
+; CHECK-NEXT:           - I64
+; CHECK-NEXT:       - Index:           2
+; CHECK-NEXT:         ReturnType:      NORESULT
+; CHECK-NEXT:         ParamTypes:
+; CHECK-NEXT:           - I32
+; CHECK-NEXT:       - Index:           3
+; CHECK-NEXT:         ReturnType:      NORESULT
+; CHECK-NEXT:         ParamTypes:
+; CHECK-NEXT:   - Type:            FUNCTION
+; CHECK-NEXT:     FunctionTypes:   [ 0, 2, 2, 3, 3 ]


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43885.136337.patch
Type: text/x-patch
Size: 1826 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180228/a94335ed/attachment.bin>


More information about the llvm-commits mailing list