[clang] [lld] [llvm] [WebAssembly] Emit constant initializers for addrspace(1) globals (PR #212007)
Yuta Saito via cfe-commits
cfe-commits at lists.llvm.org
Sun Oct 11 22:29:23 PDT 2026
================
@@ -236,6 +274,27 @@ void WebAssemblyAsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {
}
emitVisibility(Sym, GV->getVisibility(), !GV->isDeclaration());
+
+ if (GV->hasInitializer() && Sym->isGlobal()) {
+ const Constant *Init = GV->getInitializer();
+ auto Type = static_cast<wasm::ValType>(Sym->getGlobalType().Type);
+ // The object writer gives reference types ref.null and rejects v128.
+ // undef, poison and zero take the type's default.
+ if (WebAssembly::isNumType(Type) && !isa<UndefValue>(Init) &&
----------------
kateinoigakukun wrote:
What happens when this condition is false? As far as I can tell, `isNumType` false means reftype or v128, and nothing is diagnosed here. For reftypes that's fine since only undef/null are representable, but for v128 with a non-zero initializer, `-filetype=asm` would seem to silently drop the initializer (the only diagnostic is in `WasmObjectWriter`, and `global-unsupported-type.ll` only tests `-filetype=obj`).
Also `isNumType` is used as a proxy for "this type can have a const init expr", conflated with "initializer is trivially the default". I think a `switch` on `Type` that diagnoses unsupported cases right here would be clearer and keep asm/obj consistent.
https://github.com/llvm/llvm-project/pull/212007
More information about the cfe-commits
mailing list