[PATCH] D56940: FileOutputBuffer: Treat "-" as the stdout.

Rui Ueyama via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 22 10:44:25 PST 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL351852: FileOutputBuffer: Handle "-" as stdout. (authored by ruiu, committed by ).
Herald added a subscriber: kristina.

Changed prior to commit:
  https://reviews.llvm.org/D56940?vs=182634&id=182943#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56940/new/

https://reviews.llvm.org/D56940

Files:
  lld/trunk/test/ELF/stdout.s
  llvm/trunk/lib/Support/FileOutputBuffer.cpp


Index: lld/trunk/test/ELF/stdout.s
===================================================================
--- lld/trunk/test/ELF/stdout.s
+++ lld/trunk/test/ELF/stdout.s
@@ -0,0 +1,12 @@
+# REQUIRES: x86
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: ld.lld %t.o -o - > %t
+# RUN: llvm-objdump -d %t | FileCheck %s
+
+# CHECK: 0000000000201000 _start:
+# CHECK: 201000: 90 nop
+
+.globl _start
+_start:
+  nop
Index: llvm/trunk/lib/Support/FileOutputBuffer.cpp
===================================================================
--- llvm/trunk/lib/Support/FileOutputBuffer.cpp
+++ llvm/trunk/lib/Support/FileOutputBuffer.cpp
@@ -87,6 +87,12 @@
   size_t getBufferSize() const override { return Buffer.size(); }
 
   Error commit() override {
+    if (FinalPath == "-") {
+      llvm::outs() << StringRef((const char *)Buffer.base(), Buffer.size());
+      llvm::outs().flush();
+      return Error::success();
+    }
+
     using namespace sys::fs;
     int FD;
     std::error_code EC;
@@ -149,6 +155,10 @@
 // Create an instance of FileOutputBuffer.
 Expected<std::unique_ptr<FileOutputBuffer>>
 FileOutputBuffer::create(StringRef Path, size_t Size, unsigned Flags) {
+  // Handle "-" as stdout just like llvm::raw_ostream does.
+  if (Path == "-")
+    return createInMemoryBuffer("-", Size, /*Mode=*/0);
+
   unsigned Mode = fs::all_read | fs::all_write;
   if (Flags & F_executable)
     Mode |= fs::all_exe;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56940.182943.patch
Type: text/x-patch
Size: 1444 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190122/6aa0ba46/attachment.bin>


More information about the llvm-commits mailing list