// possible.
if (!(Flags & sys::fs::F_Text))
sys::ChangeStdoutToBinary();
- return STDOUT_FILENO;
+ return dup(STDOUT_FILENO);
}
int FD;
--- /dev/null
+; REQUIRES: default_triple
+
+; Often LLVM tools use "-" to indicate that output should be written to stdout
+; instead of a file. This behaviour is implemented by the raw_fd_ostream class.
+; This test verifies that when doing so multiple times we don't try to access a
+; closed STDOUT_FILENO. The exact options used in this test are unimportant, as
+; long as they write to stdout using raw_fd_ostream.
+; RUN: llc %s -o=- -pass-remarks-output=- -filetype=asm | FileCheck %s
+; foobar should appear as a function somewhere in the assembly file.
+; CHECK: foobar
+; !Analysis appears at the start of pass-remarks-output.
+; CHECK: !Analysis
+
+define void @foobar() {
+ ret void
+}
#include "gtest/gtest.h"
#include "llvm/ADT/SmallString.h"
+#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/raw_ostream.h"
"0007: 68 69 6a 6b 6c |hijkl|",
format_bytes_with_ascii_str(B.take_front(12), 0, 7, 1));
}
+
+TEST(raw_fd_ostreamTest, multiple_raw_fd_ostream_to_stdout) {
+ std::error_code EC;
+
+ { raw_fd_ostream("-", EC, sys::fs::OpenFlags::F_None); }
+ { raw_fd_ostream("-", EC, sys::fs::OpenFlags::F_None); }
+}
}