summaryrefslogtreecommitdiff
path: root/llvm/lib/Support/ToolOutputFile.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2020-07-26 19:36:28 +0000
committerDimitry Andric <dim@FreeBSD.org>2020-07-26 19:36:28 +0000
commitcfca06d7963fa0909f90483b42a6d7d194d01e08 (patch)
tree209fb2a2d68f8f277793fc8df46c753d31bc853b /llvm/lib/Support/ToolOutputFile.cpp
parent706b4fc47bbc608932d3b491ae19a3b9cde9497b (diff)
Notes
Diffstat (limited to 'llvm/lib/Support/ToolOutputFile.cpp')
-rw-r--r--llvm/lib/Support/ToolOutputFile.cpp28
1 files changed, 21 insertions, 7 deletions
diff --git a/llvm/lib/Support/ToolOutputFile.cpp b/llvm/lib/Support/ToolOutputFile.cpp
index ed3a247f01155..c2ca97a59c620 100644
--- a/llvm/lib/Support/ToolOutputFile.cpp
+++ b/llvm/lib/Support/ToolOutputFile.cpp
@@ -15,31 +15,45 @@
#include "llvm/Support/Signals.h"
using namespace llvm;
+static bool isStdout(StringRef Filename) { return Filename == "-"; }
+
ToolOutputFile::CleanupInstaller::CleanupInstaller(StringRef Filename)
- : Filename(Filename), Keep(false) {
+ : Filename(std::string(Filename)), Keep(false) {
// Arrange for the file to be deleted if the process is killed.
- if (Filename != "-")
+ if (!isStdout(Filename))
sys::RemoveFileOnSignal(Filename);
}
ToolOutputFile::CleanupInstaller::~CleanupInstaller() {
+ if (isStdout(Filename))
+ return;
+
// Delete the file if the client hasn't told us not to.
- if (!Keep && Filename != "-")
+ if (!Keep)
sys::fs::remove(Filename);
// Ok, the file is successfully written and closed, or deleted. There's no
// further need to clean it up on signals.
- if (Filename != "-")
- sys::DontRemoveFileOnSignal(Filename);
+ sys::DontRemoveFileOnSignal(Filename);
}
ToolOutputFile::ToolOutputFile(StringRef Filename, std::error_code &EC,
sys::fs::OpenFlags Flags)
- : Installer(Filename), OS(Filename, EC, Flags) {
+ : Installer(Filename) {
+ if (isStdout(Filename)) {
+ OS = &outs();
+ EC = std::error_code();
+ return;
+ }
+ OSHolder.emplace(Filename, EC, Flags);
+ OS = OSHolder.getPointer();
// If open fails, no cleanup is needed.
if (EC)
Installer.Keep = true;
}
ToolOutputFile::ToolOutputFile(StringRef Filename, int FD)
- : Installer(Filename), OS(FD, true) {}
+ : Installer(Filename) {
+ OSHolder.emplace(FD, true);
+ OS = OSHolder.getPointer();
+}