[llvm] [NFC][WebAssembly] Add Fast-ISel test for load-ext (PR #181480)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Feb 15 00:41:33 PST 2026
https://github.com/ParkHanbum updated https://github.com/llvm/llvm-project/pull/181480
>From 2f1555badaffb78e3d27f886eeaab3b63d2c3175 Mon Sep 17 00:00:00 2001
From: hanbeom <kese111 at gmail.com>
Date: Sun, 15 Feb 2026 17:12:50 +0900
Subject: [PATCH 1/2] [WebAssembly] Fix null Subtarget crash for addrspace(1)
globals
If Subtarget is null during global emission, it is now retrieved
from TargetMachine to prevent crashes caused by empty VTs in
wasmSymbolSetType.
Fixed: #181527
---
.../Target/WebAssembly/WebAssemblyAsmPrinter.cpp | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
index 1cacdb04fa74d..a088b67a5eedc 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
@@ -197,16 +197,22 @@ void WebAssemblyAsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {
if (!Sym->getType()) {
SmallVector<MVT, 1> VTs;
Type *GlobalVT = GV->getValueType();
- if (Subtarget) {
+ if (!Subtarget) {
// Subtarget is only set when a function is defined, because
// each function can declare a different subtarget. For example,
// on ARM a compilation unit might have a function on ARM and
// another on Thumb. Therefore only if Subtarget is non-null we
- // can actually calculate the legal VTs.
- const WebAssemblyTargetLowering &TLI = *Subtarget->getTargetLowering();
- computeLegalValueVTs(TLI, GV->getParent()->getContext(),
- GV->getDataLayout(), GlobalVT, VTs);
+ // can actually calculate the legal VTs. Therefore, if Subtarget
+ // is null, we retrieve the default subtarget from TargetMachine
+ // to calculate the legal VTs.
+ auto &WasmTM = static_cast<const WebAssemblyTargetMachine &>(TM);
+ Subtarget = WasmTM.getSubtargetImpl();
}
+
+ const WebAssemblyTargetLowering &TLI = *Subtarget->getTargetLowering();
+ computeLegalValueVTs(TLI, GV->getParent()->getContext(),
+ GV->getDataLayout(), GlobalVT, VTs);
+
WebAssembly::wasmSymbolSetType(Sym, GlobalVT, VTs);
}
>From 2debc6a01f29b6e57650af6eb0a79d5efa24a4fd Mon Sep 17 00:00:00 2001
From: hanbeom <kese111 at gmail.com>
Date: Sun, 15 Feb 2026 17:35:38 +0900
Subject: [PATCH 2/2] [WebAssembly] Emit initializer values for
globals(addrspace1)
This patch ensures that global variables in WebAssembly-specific
address spaces (addrspace 1) have their initializer values
correctly emitted.
---
llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
index a088b67a5eedc..007835beb0937 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
@@ -218,12 +218,11 @@ void WebAssemblyAsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {
emitVisibility(Sym, GV->getVisibility(), !GV->isDeclaration());
emitSymbolType(Sym);
- if (GV->hasInitializer()) {
+ if (const Constant *Init = GV->getInitializer()) {
assert(getSymbolPreferLocal(*GV) == Sym);
emitLinkage(GV, Sym);
OutStreamer->emitLabel(Sym);
- // TODO: Actually emit the initializer value. Otherwise the global has the
- // default value for its type (0, ref.null, etc).
+ emitGlobalConstant(GV->getDataLayout(), Init);
OutStreamer->addBlankLine();
}
}
More information about the llvm-commits
mailing list