[llvm] Unittests and usability for BitstreamWriter incremental flushing (PR #92983)

Mircea Trofin via llvm-commits llvm-commits at lists.llvm.org
Wed May 29 14:18:59 PDT 2024


================
@@ -5055,13 +5055,13 @@ void llvm::WriteBitcodeToFile(const Module &M, raw_ostream &Out,
   Triple TT(M.getTargetTriple());
   if (TT.isOSDarwin() || TT.isOSBinFormatMachO())
     Buffer.insert(Buffer.begin(), BWH_HeaderSize, 0);
-
-  BitcodeWriter Writer(Buffer, dyn_cast<raw_fd_stream>(&Out));
-  Writer.writeModule(M, ShouldPreserveUseListOrder, Index, GenerateHash,
-                     ModHash);
-  Writer.writeSymtab();
-  Writer.writeStrtab();
-
+  {
----------------
mtrofin wrote:

Revisited the refactoring following our offline discussion. Basically, now, the user can pass any stream and it will just work.

Also fixed here the problem you pointed out (offline) about the nuance in `emitDarwinBCHeaderAndTrailer`, which assumes writing at position 0 in the buffer is correct. Reading more, the assumption is really a requirement: the header is written at the end, actually.

PTAL, and if this looks reasonable, I'll update the patch title and comments too.

https://github.com/llvm/llvm-project/pull/92983


More information about the llvm-commits mailing list