================
@@ -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
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to