Skip to content

Commit 6dafa4a

Browse files
committed
Add tests for struct and union abi
1 parent e7b8d8e commit 6dafa4a

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

clang/test/CodeGen/builtins-wasm.c

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -752,41 +752,59 @@ void *tp (void) {
752752
// WEBASSEMBLY: call {{.*}} @llvm.thread.pointer.p0()
753753
}
754754

755-
typedef void (*Fvoid)(void);
756-
typedef float (*Ffloats)(float, double, int);
757-
typedef void (*Fpointers)(Fvoid, Ffloats, void*, int*, int***, char[5]);
758-
typedef void (*FVarArgs)(int, ...);
759-
typedef __externref_t (*FExternRef)(__externref_t, __externref_t);
760-
typedef __funcref Fpointers (*FFuncRef)(__funcref Fvoid, __funcref Ffloats);
761755

762756
void use(int);
763757

758+
typedef void (*Fvoid)(void);
764759
void test_function_pointer_signature_void(Fvoid func) {
765760
// WEBASSEMBLY: %0 = tail call i32 (ptr, ...) @llvm.wasm.ref.test.func(ptr %func, token poison)
766761
use(__builtin_wasm_test_function_pointer_signature(func));
767762
}
768763

764+
typedef float (*Ffloats)(float, double, int);
769765
void test_function_pointer_signature_floats(Ffloats func) {
770766
// WEBASSEMBLY: %0 = tail call i32 (ptr, ...) @llvm.wasm.ref.test.func(ptr %func, float poison, token poison, float poison, double poison, i32 poison)
771767
use(__builtin_wasm_test_function_pointer_signature(func));
772768
}
773769

770+
typedef void (*Fpointers)(Fvoid, Ffloats, void*, int*, int***, char[5]);
774771
void test_function_pointer_signature_pointers(Fpointers func) {
775772
// 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)
776773
use(__builtin_wasm_test_function_pointer_signature(func));
777774
}
778775

776+
typedef void (*FVarArgs)(int, ...);
779777
void test_function_pointer_signature_varargs(FVarArgs func) {
780778
// WEBASSEMBLY: %0 = tail call i32 (ptr, ...) @llvm.wasm.ref.test.func(ptr %func, token poison, i32 poison, ptr poison)
781779
use(__builtin_wasm_test_function_pointer_signature(func));
782780
}
783781

782+
typedef __externref_t (*FExternRef)(__externref_t, __externref_t);
784783
void test_function_pointer_externref(FExternRef func) {
785784
// 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)
786785
use(__builtin_wasm_test_function_pointer_signature(func));
787786
}
788787

788+
typedef __funcref Fpointers (*FFuncRef)(__funcref Fvoid, __funcref Ffloats);
789789
void test_function_pointer_funcref(FFuncRef func) {
790790
// 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)
791791
use(__builtin_wasm_test_function_pointer_signature(func));
792792
}
793+
794+
// Some tests that we get struct ABIs correct. There is no special code in
795+
// __builtin_wasm_test_function_pointer_signature for this, it gets handled by
796+
// the normal type lowering code.
797+
// Single element structs are unboxed, multi element structs are passed on
798+
// stack.
799+
typedef struct {double x;} (*Fstructs1)(struct {double x;}, struct {float x;}, struct {double x; float y;}, union {double x; float y;});
800+
void test_function_pointer_structs1(Fstructs1 func) {
801+
// WEBASSEMBLY: %0 = tail call i32 (ptr, ...) @llvm.wasm.ref.test.func(ptr %func, double poison, token poison, double poison, float poison, ptr poison, ptr poison)
802+
use(__builtin_wasm_test_function_pointer_signature(func));
803+
}
804+
805+
// Two element return struct ==> return ptr on stack
806+
typedef struct {double x; double y;} (*Fstructs2)(void);
807+
void test_function_pointer_structs2(Fstructs2 func) {
808+
// WEBASSEMBLY: %0 = tail call i32 (ptr, ...) @llvm.wasm.ref.test.func(ptr %func, token poison, ptr poison)
809+
use(__builtin_wasm_test_function_pointer_signature(func));
810+
}

0 commit comments

Comments
 (0)