[llvm] [llc][NPM] Use buffer_ostream support for non-seekable streams (PR #168842)

Prasoon Mishra via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 20 01:56:47 PST 2025


https://github.com/PrasoonMishra created https://github.com/llvm/llvm-project/pull/168842

NPM was missing buffering for non-seekable output streams (stdout, pipes), causing assertion failures when generating object files with `-o -`.

Use buffer_ostream to provide seekable buffering, matching legacy PM behavior.

>From ee4a573fd9ccbdf81848e3c4dd6443e5e8f0cdbe Mon Sep 17 00:00:00 2001
From: vikhegde <vikram.hegde at amd.com>
Date: Fri, 22 Aug 2025 16:27:30 +0530
Subject: [PATCH] [llc][NPM] Add buffer_ostream support for non-seekable
 streams

NPM was missing buffering for non-seekable output streams (stdout, pipes),
causing assertion failures when generating object files with `-o -`.

Use buffer_ostream to provide seekable buffering, matching legacy PM
behavior.
---
 llvm/tools/llc/NewPMDriver.cpp | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/llvm/tools/llc/NewPMDriver.cpp b/llvm/tools/llc/NewPMDriver.cpp
index fa82689ecf9ae..7ba17e5b82095 100644
--- a/llvm/tools/llc/NewPMDriver.cpp
+++ b/llvm/tools/llc/NewPMDriver.cpp
@@ -101,6 +101,13 @@ int llvm::compileModuleWithNewPM(
 
   raw_pwrite_stream *OS = &Out->os();
 
+  std::unique_ptr<buffer_ostream> BOS;
+  if (codegen::getFileType() != CodeGenFileType::AssemblyFile &&
+      !Out->os().supportsSeeking()) {
+    BOS = std::make_unique<buffer_ostream>(Out->os());
+    OS = BOS.get();
+  }
+
   // Fetch options from TargetPassConfig
   CGPassBuilderOption Opt = getCGPassBuilderOption();
   Opt.DisableVerify = VK != VerifierKind::InputOutput;



More information about the llvm-commits mailing list