diff --git a/llvm/tools/llvm-exegesis/lib/SnippetFile.cpp b/llvm/tools/llvm-exegesis/lib/SnippetFile.cpp --- a/llvm/tools/llvm-exegesis/lib/SnippetFile.cpp +++ b/llvm/tools/llvm-exegesis/lib/SnippetFile.cpp @@ -135,6 +135,20 @@ ObjectFileInfo.InitMCObjectFileInfo(TM.getTargetTriple(), /*PIC*/ false, Context); BenchmarkCodeStreamer Streamer(&Context, TM.getMCRegisterInfo(), &Result); + + std::string Error; + raw_string_ostream ErrorStream(Error); + formatted_raw_ostream InstPrinterOStream(ErrorStream); + MCInstPrinter *const InstPrinter = TM.getTarget().createMCInstPrinter( + TM.getTargetTriple(), TM.getMCAsmInfo()->getAssemblerDialect(), + *TM.getMCAsmInfo(), *TM.getMCInstrInfo(), *TM.getMCRegisterInfo()); + // The following call will take care of calling Streamer.setTargetStreamer. + TM.getTarget().createAsmTargetStreamer(Streamer, InstPrinterOStream, + InstPrinter, + TM.Options.MCOptions.AsmVerbose); + if (!Streamer.getTargetStreamer()) + return make_error("cannot create target asm streamer"); + const std::unique_ptr AsmParser( createMCAsmParser(SM, Context, Streamer, *TM.getMCAsmInfo())); if (!AsmParser) diff --git a/llvm/unittests/tools/llvm-exegesis/X86/SnippetFileTest.cpp b/llvm/unittests/tools/llvm-exegesis/X86/SnippetFileTest.cpp --- a/llvm/unittests/tools/llvm-exegesis/X86/SnippetFileTest.cpp +++ b/llvm/unittests/tools/llvm-exegesis/X86/SnippetFileTest.cpp @@ -115,6 +115,13 @@ consumeError(std::move(Error)); } +TEST_F(X86SnippetFileTest, NoAsmStreamer) { + auto Snippets = TestCommon(R"( + .cv_fpo_proc foo 4 + )"); + EXPECT_FALSE((bool)Snippets.takeError()); +} + } // namespace } // namespace exegesis } // namespace llvm