[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 19:14:01 PDT 2021


Enna1 updated this revision to Diff 381696.
Enna1 added a comment.

Add a test.


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

https://reviews.llvm.org/D112297

Files:
  lld/ELF/LTO.cpp
  lld/test/ELF/lto/emit-llvm_assertion_failure.ll


Index: lld/test/ELF/lto/emit-llvm_assertion_failure.ll
===================================================================
--- /dev/null
+++ lld/test/ELF/lto/emit-llvm_assertion_failure.ll
@@ -0,0 +1,14 @@
+; Make sure that if --plugin-opt=emit-llvm is enabled and the output
+; is /dev/null, it should not cause a assertion failure in bitcode writer.
+
+; REQUIRES: x86
+
+; RUN: opt -module-hash -module-summary %s -o %t.o
+; RUN: ld.lld --plugin-opt=emit-llvm -mllvm -bitcode-flush-threshold=0 -o /dev/null %t.o
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define void @main() {
+  ret void
+}
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.381696.patch
Type: text/x-patch
Size: 1339 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211023/3991358a/attachment-0001.bin>


More information about the llvm-commits mailing list