| 1 |
// RUN: %clang_cc1 -triple wasm32-unknown-unknown -target-feature +gc -O3 -emit-llvm -DSINGLE_VALUE -o - %s | FileCheck %s -check-prefixes WEBASSEMBLY,WEBASSEMBLY-SV |
| 2 |
// RUN: %clang_cc1 -triple wasm64-unknown-unknown -target-feature +gc -O3 -emit-llvm -DSINGLE_VALUE -o - %s | FileCheck %s -check-prefixes WEBASSEMBLY,WEBASSEMBLY-SV |
| 3 |
// RUN: %clang_cc1 -triple wasm64-unknown-unknown -target-feature +gc -target-abi experimental-mv -O3 -emit-llvm -o - %s 2>&1 | FileCheck %s -check-prefixes WEBASSEMBLY |
| 4 |
// RUN: not %clang_cc1 -triple wasm64-unknown-unknown -O3 -emit-llvm -o - %s 2>&1 | FileCheck %s -check-prefixes MISSING-GC |
| 5 |
|
| 6 |
void use(int); |
| 7 |
|
| 8 |
typedef void (*Fvoid)(void); |
| 9 |
void test_function_pointer_signature_void(Fvoid func) { |
| 10 |
// MISSING-GC: error: '__builtin_wasm_test_function_pointer_signature' needs target feature gc |
| 11 |
// WEBASSEMBLY: %0 = tail call i32 (ptr, ...) @llvm.wasm.ref.test.func(ptr %func, token poison) |
| 12 |
use(__builtin_wasm_test_function_pointer_signature(func)); |
| 13 |
} |
| 14 |
|
| 15 |
typedef float (*Ffloats)(float, double, int); |
| 16 |
void test_function_pointer_signature_floats(Ffloats func) { |
| 17 |
// WEBASSEMBLY: %0 = tail call i32 (ptr, ...) @llvm.wasm.ref.test.func(ptr %func, float poison, token poison, float poison, double poison, i32 poison) |
| 18 |
use(__builtin_wasm_test_function_pointer_signature(func)); |
| 19 |
} |
| 20 |
|
| 21 |
typedef void (*Fpointers)(Fvoid, Ffloats, void*, int*, int***, char[5]); |
| 22 |
void test_function_pointer_signature_pointers(Fpointers func) { |
| 23 |
// WEBASSEMBLY: %0 = tail call i32 (ptr, ...) @llvm.wasm.ref.test.func(ptr %func, token poison, ptr poison, ptr poison, ptr poison, ptr poison, ptr poison, ptr poison) |
| 24 |
use(__builtin_wasm_test_function_pointer_signature(func)); |
| 25 |
} |
| 26 |
|
| 27 |
typedef void (*FVarArgs)(int, ...); |
| 28 |
void test_function_pointer_signature_varargs(FVarArgs func) { |
| 29 |
// WEBASSEMBLY: %0 = tail call i32 (ptr, ...) @llvm.wasm.ref.test.func(ptr %func, token poison, i32 poison, ptr poison) |
| 30 |
use(__builtin_wasm_test_function_pointer_signature(func)); |
| 31 |
} |
| 32 |
|
| 33 |
typedef __externref_t (*FExternRef)(__externref_t, __externref_t); |
| 34 |
void test_function_pointer_externref(FExternRef func) { |
| 35 |
// WEBASSEMBLY: %0 = tail call i32 (ptr, ...) @llvm.wasm.ref.test.func(ptr %func, ptr addrspace(10) poison, token poison, ptr addrspace(10) poison, ptr addrspace(10) poison) |
| 36 |
use(__builtin_wasm_test_function_pointer_signature(func)); |
| 37 |
} |
| 38 |
|
| 39 |
typedef __funcref Fpointers (*FFuncRef)(__funcref Fvoid, __funcref Ffloats); |
| 40 |
void test_function_pointer_funcref(FFuncRef func) { |
| 41 |
// WEBASSEMBLY: %0 = tail call i32 (ptr, ...) @llvm.wasm.ref.test.func(ptr %func, ptr addrspace(20) poison, token poison, ptr addrspace(20) poison, ptr addrspace(20) poison) |
| 42 |
use(__builtin_wasm_test_function_pointer_signature(func)); |
| 43 |
} |
| 44 |
|
| 45 |
#ifdef SINGLE_VALUE |
| 46 |
// Some tests that we get struct ABIs correct. There is no special code in |
| 47 |
// __builtin_wasm_test_function_pointer_signature for this, it gets handled by |
| 48 |
// the normal type lowering code. |
| 49 |
// Single element structs are unboxed, multi element structs are passed on |
| 50 |
// stack. |
| 51 |
typedef struct {double x;} (*Fstructs1)(struct {double x;}, struct {float x;}, struct {double x; float y;}); |
| 52 |
void test_function_pointer_structs1(Fstructs1 func) { |
| 53 |
// WEBASSEMBLY-SV: %0 = tail call i32 (ptr, ...) @llvm.wasm.ref.test.func(ptr %func, double poison, token poison, double poison, float poison, ptr poison) |
| 54 |
use(__builtin_wasm_test_function_pointer_signature(func)); |
| 55 |
} |
| 56 |
|
| 57 |
// Two element return struct ==> return ptr on stack |
| 58 |
typedef struct {double x; double y;} (*Fstructs2)(void); |
| 59 |
void test_function_pointer_structs2(Fstructs2 func) { |
| 60 |
// WEBASSEMBLY-SV: %0 = tail call i32 (ptr, ...) @llvm.wasm.ref.test.func(ptr %func, token poison, ptr poison) |
| 61 |
use(__builtin_wasm_test_function_pointer_signature(func)); |
| 62 |
} |
| 63 |
|
| 64 |
// Return union ==> return ptr on stack, one element union => unboxed |
| 65 |
typedef union {double x; float y;} (*FUnions)(union {double x; float y;}, union {double x;}); |
| 66 |
void test_function_pointer_unions(FUnions func) { |
| 67 |
// WEBASSEMBLY-SV: %0 = tail call i32 (ptr, ...) @llvm.wasm.ref.test.func(ptr %func, token poison, ptr poison, ptr poison, double poison) |
| 68 |
use(__builtin_wasm_test_function_pointer_signature(func)); |
| 69 |
} |
| 70 |
#endif |