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 ]