[clang] [llvm] [WebAssembly] Represent reference types as TargetExtType (PR #203165)
Hood Chatham via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 24 06:08:02 PDT 2026
================
@@ -2839,6 +2840,43 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
return CGF.authPointerToPointerCast(Result, E->getType(), DestTy);
}
case CK_AddressSpaceConversion: {
+ llvm::Type *DestLTy = ConvertType(DestTy);
+ // WebAssembly reference types are opaque target extension types so an
+ // "address space conversion" involving them is not a real pointer cast.
+ auto IsWasmFuncref = [](llvm::Type *T) {
+ auto *TET = dyn_cast<llvm::TargetExtType>(T);
+ return TET && TET->getName() == "wasm.funcref";
+ };
+ bool SrcIsFuncref = IsWasmFuncref(ConvertType(E->getType()));
+ bool DestIsFuncref = IsWasmFuncref(DestLTy);
+ if (SrcIsFuncref && DestIsFuncref) {
+ // funcref -> funcref (e.g. between differently-typed funcrefs) is the
+ // identity on the opaque reference value.
+ return Visit(E);
+ }
+ if (SrcIsFuncref && !DestIsFuncref) {
+ // funcref -> pointer: use wasm_funcref_to_ptr. This will probably crash
----------------
hoodmane wrote:
For now let's not do that. I think for it to work correctly we need a stack of funcrefs, and it's just not worth it.
https://github.com/llvm/llvm-project/pull/203165
More information about the llvm-commits
mailing list