Index: lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp =================================================================== --- lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp +++ lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp @@ -81,10 +81,12 @@ for (auto &It : OutContext.getSymbols()) { // Emit a .globaltype and .eventtype declaration. auto Sym = cast(It.getValue()); - if (Sym->getType() == wasm::WASM_SYMBOL_TYPE_GLOBAL) - getTargetStreamer()->emitGlobalType(Sym); - else if (Sym->getType() == wasm::WASM_SYMBOL_TYPE_EVENT) - getTargetStreamer()->emitEventType(Sym); + if (WebAssemblyTargetStreamer *TS = getTargetStreamer()) { + if (Sym->getType() == wasm::WASM_SYMBOL_TYPE_GLOBAL) + TS->emitGlobalType(Sym); + else if (Sym->getType() == wasm::WASM_SYMBOL_TYPE_EVENT) + TS->emitEventType(Sym); + } } for (const auto &F : M) { @@ -99,18 +101,20 @@ Sym->setSignature(Signature.get()); addSignature(std::move(Signature)); } - // FIXME: this was originally intended for post-linking and was only used - // for imports that were only called indirectly (i.e. s2wasm could not - // infer the type from a call). With object files it applies to all - // imports. so fix the names and the tests, or rethink how import - // delcarations work in asm files. - getTargetStreamer()->emitIndirectFunctionType(Sym); - - if (TM.getTargetTriple().isOSBinFormatWasm() && - F.hasFnAttribute("wasm-import-module")) { - StringRef Name = - F.getFnAttribute("wasm-import-module").getValueAsString(); - getTargetStreamer()->emitImportModule(Sym, Name); + if (WebAssemblyTargetStreamer *TS = getTargetStreamer()) { + // FIXME: this was originally intended for post-linking and was only + // used for imports that were only called indirectly (i.e. s2wasm + // could not infer the type from a call). With object files it applies + // to all imports. so fix the names and the tests, or rethink how + // import declarations work in asm files. + TS->emitIndirectFunctionType(Sym); + + if (TM.getTargetTriple().isOSBinFormatWasm() && + F.hasFnAttribute("wasm-import-module")) { + StringRef Name = + F.getFnAttribute("wasm-import-module").getValueAsString(); + TS->emitImportModule(Sym, Name); + } } } } @@ -165,19 +169,21 @@ WasmSym->setSignature(Signature.get()); addSignature(std::move(Signature)); - // FIXME: clean up how params and results are emitted (use signatures) - getTargetStreamer()->emitParam(CurrentFnSym, ParamVTs); + if (WebAssemblyTargetStreamer *TS = getTargetStreamer()) { + // FIXME: clean up how params and results are emitted (use signatures) + TS->emitParam(CurrentFnSym, ParamVTs); - // Emit the function index. - if (MDNode *Idx = F.getMetadata("wasm.index")) { - assert(Idx->getNumOperands() == 1); + // Emit the function index. + if (MDNode *Idx = F.getMetadata("wasm.index")) { + assert(Idx->getNumOperands() == 1); - getTargetStreamer()->emitIndIdx(AsmPrinter::lowerConstant( - cast(Idx->getOperand(0))->getValue())); - } + TS->emitIndIdx(AsmPrinter::lowerConstant( + cast(Idx->getOperand(0))->getValue())); + } - getTargetStreamer()->emitResult(CurrentFnSym, ResultVTs); - getTargetStreamer()->emitLocal(MFI->getLocals()); + TS->emitResult(CurrentFnSym, ResultVTs); + TS->emitLocal(MFI->getLocals()); + } AsmPrinter::EmitFunctionBodyStart(); } Index: test/CodeGen/WebAssembly/null-streamer.ll =================================================================== --- /dev/null +++ test/CodeGen/WebAssembly/null-streamer.ll @@ -0,0 +1,14 @@ +; RUN: llc -O0 -filetype=null -exception-model=wasm -mattr=+exception-handling < %s + +target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" +target triple = "wasm32-unknown-unknown" + +declare void @llvm.wasm.throw(i32, i8*) + +declare void @g() + +define i32 @f(i8* %p) { + call void @llvm.wasm.throw(i32 0, i8* %p) + call void @g() + ret i32 0 +}