[clang] b3dae59 - [clang] Fix CodeGenAction for LLVM IR MemBuffers
Daniele Castagna via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 8 16:40:03 PST 2022
Author: Ryan Senanayake
Date: 2022-03-09T00:39:48Z
New Revision: b3dae59b9dfb579d396bd97ca1b5a16529daac75
URL: https://github.com/llvm/llvm-project/commit/b3dae59b9dfb579d396bd97ca1b5a16529daac75
DIFF: https://github.com/llvm/llvm-project/commit/b3dae59b9dfb579d396bd97ca1b5a16529daac75.diff
LOG: [clang] Fix CodeGenAction for LLVM IR MemBuffers
Replaces use of getCurrentFile with getCurrentFileOrBufferName
in CodeGenAction. This avoids an assertion error or an incorrect
name chosen for the output file when assertions are disabled.
This error previously occurred when the FrontendInputFile was a
MemoryBuffer instead of a file.
Reviewed By: jlebar
Differential Revision: https://reviews.llvm.org/D121259
Added:
Modified:
clang/lib/CodeGen/CodeGenAction.cpp
clang/unittests/Frontend/CodeGenActionTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp
index c2c508dedb097..807880fd4fd7a 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -1113,7 +1113,7 @@ void CodeGenAction::ExecuteAction() {
auto &CodeGenOpts = CI.getCodeGenOpts();
auto &Diagnostics = CI.getDiagnostics();
std::unique_ptr<raw_pwrite_stream> 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
index 455ec705f884d..f932be639191a 100644
--- a/clang/unittests/Frontend/CodeGenActionTest.cpp
+++ b/clang/unittests/Frontend/CodeGenActionTest.cpp
@@ -59,4 +59,21 @@ TEST(CodeGenTest, TestNullCodeGen) {
EXPECT_TRUE(Success);
}
+TEST(CodeGenTest, CodeGenFromIRMemBuffer) {
+ auto Invocation = std::make_shared<CompilerInvocation>();
+ std::unique_ptr<MemoryBuffer> 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);
+}
}
More information about the cfe-commits
mailing list