https://github.com/QuantumSegfault created https://github.com/llvm/llvm-project/pull/178720
Allows __funcref pointers to be used as the element type for WASM tables in Clang (static, global, zero-length arrays of a reference type). Modifies `QualType::isWebAssemblyFuncrefType` to accept function pointer types with the `__funcptr`, in addition to pointers in address space 20. Related: #140933 >From a81b640f7a648b3d82409ba38eea09271714d8f1 Mon Sep 17 00:00:00 2001 From: Demetrius Kanios <[email protected]> Date: Thu, 29 Jan 2026 00:54:20 -0800 Subject: [PATCH] Change `QualType::isWebAssemblyFuncrefType` to accept types attributed with `WebAssemblyFuncref` --- clang/lib/AST/Type.cpp | 3 ++- clang/test/CodeGen/WebAssembly/builtins-table.c | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp index 53082bcf78f6a..8cbe49a23c13d 100644 --- a/clang/lib/AST/Type.cpp +++ b/clang/lib/AST/Type.cpp @@ -2947,7 +2947,8 @@ bool QualType::isWebAssemblyExternrefType() const { bool QualType::isWebAssemblyFuncrefType() const { return getTypePtr()->isFunctionPointerType() && - getAddressSpace() == LangAS::wasm_funcref; + (getAddressSpace() == LangAS::wasm_funcref || + getTypePtr()->hasAttr(attr::WebAssemblyFuncref)); } QualType::PrimitiveDefaultInitializeKind diff --git a/clang/test/CodeGen/WebAssembly/builtins-table.c b/clang/test/CodeGen/WebAssembly/builtins-table.c index 74bb2442fe552..4069da2c4c225 100644 --- a/clang/test/CodeGen/WebAssembly/builtins-table.c +++ b/clang/test/CodeGen/WebAssembly/builtins-table.c @@ -65,3 +65,20 @@ static __externref_t other_table[0]; void test_table_copy(int dst_idx, int src_idx, int nelem) { __builtin_wasm_table_copy(table, other_table, dst_idx, src_idx, nelem); } + + +typedef void (*__funcref funcref_t)(); +static funcref_t funcref_table[0]; + +// CHECK-LABEL: define {{[^@]+}}@test_funcref_table +// CHECK-SAME: (ptr addrspace(20) noundef [[FUNCREF:%.*]], i32 noundef [[INDEX:%.*]]) #[[ATTR0]] { +// CHECK-NEXT: entry: +// CHECK-NEXT: call void @llvm.wasm.table.set.funcref(ptr addrspace(1) @funcref_table, i32 [[INDEX]], ptr addrspace(20) [[FUNCREF]]) +// CHECK-NEXT: [[TMP0:%.*]] = call ptr addrspace(20) @llvm.wasm.table.get.funcref(ptr addrspace(1) @funcref_table, i32 [[INDEX]]) +// CHECK-NEXT: ret ptr addrspace(20) [[TMP0]] +// +funcref_t test_funcref_table(funcref_t funcref, int index) { + __builtin_wasm_table_set(funcref_table, index, funcref); + + return __builtin_wasm_table_get(funcref_table, index); +} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
