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

Teresa Johnson via llvm-commits llvm-commits at lists.llvm.org
Fri May 24 16:49:48 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();
-
+  {
----------------
teresajohnson wrote:

I'm missing something...

With the BitcodeWriter now in its own scope, I believe what now happens is that when it is destructed on line 5064 it will write the contents of Buffer to Out, then clear Buffer. Then since Buffer will be empty, line 5070 won't trigger.

With the old code, we would instead see that Buffer wasn't empty on line 5069 and trigger the same write on line 5070. But without clearing Buffer afterwards. But that is the end of Buffer's lifetime, so why does it need to be cleared?

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


More information about the llvm-commits mailing list