Skip to content

Commit 985dbdf

Browse files
committed
Handle pointer types, improve test
1 parent d137fb7 commit 985dbdf

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

clang/lib/CodeGen/TargetBuiltins/WebAssembly.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,13 +253,15 @@ Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
253253
Args.push_back(FuncRef);
254254

255255
// Add the type information
256-
auto addType = [&Args](llvm::Type *T) {
256+
auto addType = [this, &Args](llvm::Type *T) {
257257
if (T->isVoidTy()) {
258258
// Do nothing
259259
} else if (T->isFloatingPointTy()) {
260260
Args.push_back(ConstantFP::get(T, 0));
261261
} else if (T->isIntegerTy()) {
262262
Args.push_back(ConstantInt::get(T, 0));
263+
} else if (T->isPointerTy()) {
264+
Args.push_back(ConstantPointerNull::get(llvm::PointerType::get(getLLVMContext(), T->getPointerAddressSpace())));
263265
} else {
264266
// TODO: Handle reference types. For now, we reject them in Sema.
265267
llvm_unreachable("Unhandled type");

clang/test/CodeGen/builtins-wasm.c

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

755-
756-
typedef void (*funcref_t)();
757-
typedef int (*funcref_int_t)(int);
758-
typedef float (*F1)(float, double, int);
759-
typedef int (*F2)(float, double, int);
760-
typedef int (*F3)(int, int, int);
761-
typedef void (*F4)(int, int, int);
762-
typedef void (*F5)(void);
755+
typedef void (*Fvoid)(void);
756+
typedef float (*Ffloats)(float, double, int);
757+
typedef void (*Fpointers)(Fvoid, Ffloats, void*, int*, int***, char[5]);
763758

764759
void use(int);
765760

766-
void test_function_pointer_signature_void(F1 func) {
767-
// WEBASSEMBLY: %0 = tail call i32 (ptr, ...) @llvm.wasm.ref.test.func(ptr %func, float 0.000000e+00, token poison, float 0.000000e+00, double 0.000000e+00, i32 0)
761+
void test_function_pointer_signature_void(Fvoid func) {
762+
// WEBASSEMBLY: %0 = tail call i32 (ptr, ...) @llvm.wasm.ref.test.func(ptr %func, token poison)
763+
use(__builtin_wasm_test_function_pointer_signature(func));
764+
}
765+
766+
void test_function_pointer_signature_floats(Ffloats func) {
767+
// WEBASSEMBLY: tail call i32 (ptr, ...) @llvm.wasm.ref.test.func(ptr %func, float 0.000000e+00, token poison, float 0.000000e+00, double 0.000000e+00, i32 0)
768+
use(__builtin_wasm_test_function_pointer_signature(func));
769+
}
770+
771+
void test_function_pointer_signature_pointers(Fpointers func) {
772+
// WEBASSEMBLY: %0 = tail call i32 (ptr, ...) @llvm.wasm.ref.test.func(ptr %func, token poison, ptr null, ptr null, ptr null, ptr null, ptr null, ptr null)
768773
use(__builtin_wasm_test_function_pointer_signature(func));
769-
// WEBASSEMBLY: %1 = tail call i32 (ptr, ...) @llvm.wasm.ref.test.func(ptr %func, i32 0, token poison, float 0.000000e+00, double 0.000000e+00, i32 0)
770-
use(__builtin_wasm_test_function_pointer_signature((F2)func));
771-
// WEBASSEMBLY: %2 = tail call i32 (ptr, ...) @llvm.wasm.ref.test.func(ptr %func, i32 0, token poison, i32 0, i32 0, i32 0)
772-
use(__builtin_wasm_test_function_pointer_signature((F3)func));
773-
// WEBASSEMBLY: %3 = tail call i32 (ptr, ...) @llvm.wasm.ref.test.func(ptr %func, token poison, i32 0, i32 0, i32 0)
774-
use(__builtin_wasm_test_function_pointer_signature((F4)func));
775-
// WEBASSEMBLY: %4 = tail call i32 (ptr, ...) @llvm.wasm.ref.test.func(ptr %func, token poison)
776-
use(__builtin_wasm_test_function_pointer_signature((F5)func));
777774
}

0 commit comments

Comments
 (0)