[llvm] [WebAssembly] Prevent FastISel from trying to select funcref calls (PR #178742)

Demetrius Kanios via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 29 11:48:05 PST 2026


https://github.com/QuantumSegfault created https://github.com/llvm/llvm-project/pull/178742

Before, WASM FastISel treated all indirect calls the same, causing miscompilations at O0 when trying to call a funcref (`call ptr addrspace(20)`), as it would treat the funcref as a normal `ptr`

This adds a check so it falls back to ISelDAG when encountering calls outside addrspace 0 (which covers direct calls and indirect calls through normal function pointers).

Related: #140933

>From b18a90cd605a591950596fff84a259a77ee10b08 Mon Sep 17 00:00:00 2001
From: Demetrius Kanios <demetrius at kanios.net>
Date: Thu, 29 Jan 2026 11:28:37 -0800
Subject: [PATCH] Prevent FastISel from trying to select funcref calls

---
 llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp | 6 ++++++
 llvm/test/CodeGen/WebAssembly/funcref-call.ll       | 3 ++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
index 9d8e09c09e9ea..8618f47c0f5a0 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
@@ -16,6 +16,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "MCTargetDesc/WebAssemblyMCTargetDesc.h"
+#include "Utils/WasmAddressSpaces.h"
 #include "Utils/WebAssemblyTypeUtilities.h"
 #include "WebAssemblyMachineFunctionInfo.h"
 #include "WebAssemblySubtarget.h"
@@ -770,6 +771,11 @@ bool WebAssemblyFastISel::fastLowerArguments() {
 bool WebAssemblyFastISel::selectCall(const Instruction *I) {
   const auto *Call = cast<CallInst>(I);
 
+  // FastISel does not support calls through funcref
+  if (Call->getCalledOperand()->getType()->getPointerAddressSpace() !=
+      WebAssembly::WasmAddressSpace::WASM_ADDRESS_SPACE_DEFAULT)
+    return false;
+
   // TODO: Support tail calls in FastISel
   if (Call->isMustTailCall() || Call->isInlineAsm() ||
       Call->getFunctionType()->isVarArg())
diff --git a/llvm/test/CodeGen/WebAssembly/funcref-call.ll b/llvm/test/CodeGen/WebAssembly/funcref-call.ll
index c4eb425244450..9904df2280e81 100644
--- a/llvm/test/CodeGen/WebAssembly/funcref-call.ll
+++ b/llvm/test/CodeGen/WebAssembly/funcref-call.ll
@@ -1,5 +1,6 @@
 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
-; RUN: llc < %s --mtriple=wasm32-unknown-unknown -mattr=+reference-types | FileCheck %s
+; RUN: llc < %s --mtriple=wasm32-unknown-unknown -fast-isel=0 -mattr=+reference-types | FileCheck %s
+; RUN: llc < %s --mtriple=wasm32-unknown-unknown -fast-isel=1 -mattr=+reference-types | FileCheck %s
 
 %funcref = type ptr addrspace(20) ;; addrspace 20 is nonintegral
 



More information about the llvm-commits mailing list