From ee4a573fd9ccbdf81848e3c4dd6443e5e8f0cdbe Mon Sep 17 00:00:00 2001 From: vikhegde 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 BOS; + if (codegen::getFileType() != CodeGenFileType::AssemblyFile && + !Out->os().supportsSeeking()) { + BOS = std::make_unique(Out->os()); + OS = BOS.get(); + } + // Fetch options from TargetPassConfig CGPassBuilderOption Opt = getCGPassBuilderOption(); Opt.DisableVerify = VK != VerifierKind::InputOutput;