[llvm] c49bc1a - BitcodeWriter: ensure `Buffer` is heap allocated

Mircea Trofin via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 3 12:48:37 PDT 2024


Author: Mircea Trofin
Date: 2024-06-03T12:48:23-07:00
New Revision: c49bc1a3b782e38e4ffb5b274f1e7775af6c2315

URL: https://github.com/llvm/llvm-project/commit/c49bc1a3b782e38e4ffb5b274f1e7775af6c2315
DIFF: https://github.com/llvm/llvm-project/commit/c49bc1a3b782e38e4ffb5b274f1e7775af6c2315.diff

LOG: BitcodeWriter: ensure `Buffer` is heap allocated

PR #92983 accidentally changed the buffer allocation in
`llvm::WriteBitcodeToFile` to be allocated on the stack, which is
problematic given it's a large-ish buffer (256K)

Added: 
    

Modified: 
    llvm/lib/Bitcode/Writer/BitcodeWriter.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index 7d39c0db79fb1..9016af7d6e05d 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -5095,7 +5095,8 @@ void llvm::WriteBitcodeToFile(const Module &M, raw_ostream &Out,
     // header. Note that the header is computed *after* the output is known, so
     // we currently explicitly use a buffer, write to it, and then subsequently
     // flush to Out.
-    SmallVector<char, 256 * 1024> Buffer;
+    SmallVector<char, 0> Buffer;
+    Buffer.reserve(256 * 1024);
     Buffer.insert(Buffer.begin(), BWH_HeaderSize, 0);
     BitcodeWriter Writer(Buffer);
     Write(Writer);


        


More information about the llvm-commits mailing list