Index: lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp =================================================================== --- lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp +++ lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp @@ -339,24 +339,26 @@ } void WebAssemblyAsmPrinter::EmitEndOfAsmFile(Module &M) { - SmallString<128> Str; - raw_svector_ostream OS(Str); + SmallString<128> Str; + raw_svector_ostream OS(Str); for (const Function &F : M) if (F.isDeclarationForLinker()) { assert(F.hasName() && "imported functions must have a name"); if (F.getName().startswith("llvm.")) - continue; + continue; if (Str.empty()) - OS << "\t.imports\n"; + OS << "\t.imports\n"; Type *Rt = F.getReturnType(); - OS << "\t.import " << toSymbol(F.getName()) << " \"\" \"" << F.getName() - << "\""; + OS << "\t.import " << toSymbol(F.getName()) << " \"\" \"" << F.getName() + << "\""; + OS << " (param"; for (const Argument &A : F.args()) - OS << " (param " << toString(A.getType()) << ')'; + OS << ' ' << toString(A.getType()); + OS << ')'; if (!Rt->isVoidTy()) - OS << " (result " << toString(Rt) << ')'; + OS << " (result " << toString(Rt) << ')'; OS << '\n'; - } + } OutStreamer->EmitRawText(OS.str()); } Index: test/CodeGen/WebAssembly/import.ll =================================================================== --- test/CodeGen/WebAssembly/import.ll +++ test/CodeGen/WebAssembly/import.ll @@ -16,6 +16,8 @@ ; CHECK-NEXT: .import $printi "" "printi" (param i32) (result i32) ; CHECK-NEXT: .import $printf "" "printf" (param f32) (result f32) ; CHECK-NEXT: .import $printv "" "printv" +; CHECK-NEXT: .import $add2 "" "add2" (param i32 i32) (result i32) declare i32 @printi(i32) declare float @printf(float) declare void @printv() +declare i32 @add2(i32, i32)