diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp --- a/clang/lib/CodeGen/CodeGenAction.cpp +++ b/clang/lib/CodeGen/CodeGenAction.cpp @@ -1113,7 +1113,7 @@ auto &CodeGenOpts = CI.getCodeGenOpts(); auto &Diagnostics = CI.getDiagnostics(); std::unique_ptr OS = - GetOutputStream(CI, getCurrentFile(), BA); + GetOutputStream(CI, getCurrentFileOrBufferName(), BA); if (BA != Backend_EmitNothing && !OS) return; diff --git a/clang/unittests/Frontend/CodeGenActionTest.cpp b/clang/unittests/Frontend/CodeGenActionTest.cpp --- a/clang/unittests/Frontend/CodeGenActionTest.cpp +++ b/clang/unittests/Frontend/CodeGenActionTest.cpp @@ -59,4 +59,21 @@ EXPECT_TRUE(Success); } +TEST(CodeGenTest, CodeGenFromIRMemBuffer) { + auto Invocation = std::make_shared(); + std::unique_ptr MemBuffer = + MemoryBuffer::getMemBuffer("", "test.ll"); + Invocation->getFrontendOpts().Inputs.push_back( + FrontendInputFile(*MemBuffer, Language::LLVM_IR)); + Invocation->getFrontendOpts().ProgramAction = frontend::EmitLLVMOnly; + Invocation->getTargetOpts().Triple = "i386-unknown-linux-gnu"; + CompilerInstance Compiler; + Compiler.setInvocation(std::move(Invocation)); + Compiler.createDiagnostics(); + EXPECT_TRUE(Compiler.hasDiagnostics()); + + EmitLLVMOnlyAction Action; + bool Success = Compiler.ExecuteAction(Action); + EXPECT_TRUE(Success); +} }