Skip to content

Commit e7b8d8e

Browse files
committed
Fix handling of varargs function
1 parent 6caa2f7 commit e7b8d8e

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

clang/lib/CodeGen/TargetBuiltins/WebAssembly.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,10 @@ Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
246246
llvm::FunctionType *LLVMFuncTy =
247247
cast<llvm::FunctionType>(ConvertType(QualType(FuncTy, 0)));
248248

249+
bool VarArg = LLVMFuncTy->isVarArg();
249250
unsigned NParams = LLVMFuncTy->getNumParams();
250251
std::vector<Value *> Args;
251-
Args.reserve(NParams + 3);
252+
Args.reserve(NParams + 3 + VarArg);
252253
// The only real argument is the FuncRef
253254
Args.push_back(FuncRef);
254255

@@ -263,6 +264,9 @@ Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
263264
for (unsigned i = 0; i < NParams; i++) {
264265
Args.push_back(PoisonValue::get(LLVMFuncTy->getParamType(i)));
265266
}
267+
if (VarArg) {
268+
Args.push_back(PoisonValue::get(Builder.getPtrTy()));
269+
}
266270
Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_ref_test_func);
267271
return Builder.CreateCall(Callee, Args);
268272
}

clang/test/CodeGen/builtins-wasm.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,7 @@ void *tp (void) {
755755
typedef void (*Fvoid)(void);
756756
typedef float (*Ffloats)(float, double, int);
757757
typedef void (*Fpointers)(Fvoid, Ffloats, void*, int*, int***, char[5]);
758+
typedef void (*FVarArgs)(int, ...);
758759
typedef __externref_t (*FExternRef)(__externref_t, __externref_t);
759760
typedef __funcref Fpointers (*FFuncRef)(__funcref Fvoid, __funcref Ffloats);
760761

@@ -775,6 +776,11 @@ void test_function_pointer_signature_pointers(Fpointers func) {
775776
use(__builtin_wasm_test_function_pointer_signature(func));
776777
}
777778

779+
void test_function_pointer_signature_varargs(FVarArgs func) {
780+
// WEBASSEMBLY: %0 = tail call i32 (ptr, ...) @llvm.wasm.ref.test.func(ptr %func, token poison, i32 poison, ptr poison)
781+
use(__builtin_wasm_test_function_pointer_signature(func));
782+
}
783+
778784
void test_function_pointer_externref(FExternRef func) {
779785
// 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)
780786
use(__builtin_wasm_test_function_pointer_signature(func));

0 commit comments

Comments
 (0)