[PATCH] D112297: [LTO] Fix assertion failed when flushing bitcode incrementally for LTO output.

Xu Mingjie via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 22 02:01:25 PDT 2021


Enna1 created this revision.
Enna1 added reviewers: stephan.yichao.zhao, MaskRay, tejohnson, mehdi_amini.
Herald added subscribers: ormris, steven_wu, hiraditya, arichardson, inglorion, emaste.
Enna1 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

In https://reviews.llvm.org/D86905, we introduce an optimization, when lld emits LLVM bitcode, 
we allow bitcode writer flush data to disk early when buffered data size is above some threshold.

But when --plugin-opt=emit-llvm and -o /dev/null are used, 
lld will trigger assertion BytesRead >= 0 && static_cast<size_t>(BytesRead) == BytesFromDisk.
This is because we write output to /dev/null, and BytesRead is zero, but at this program point BytesFromDisk is always non-zero.

This change fix this assertion failed.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D112297

Files:
  lld/ELF/LTO.cpp


Index: lld/ELF/LTO.cpp
===================================================================
--- lld/ELF/LTO.cpp
+++ lld/ELF/LTO.cpp
@@ -62,6 +62,10 @@
 // flush buffered data to reduce memory consumption. If this fails, open a file
 // stream that supports only write.
 static std::unique_ptr<raw_fd_ostream> openLTOOutputFile(StringRef file) {
+  // Don't flush bitcode incrementally if the output is a special file.
+  // This handles things like '-o /dev/null'
+  if (!sys::fs::is_regular_file(file))
+    return openFile(file);
   std::error_code ec;
   std::unique_ptr<raw_fd_ostream> fs =
       std::make_unique<raw_fd_stream>(file, ec);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112297.381485.patch
Type: text/x-patch
Size: 644 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211022/511c5ead/attachment.bin>


More information about the llvm-commits mailing list