[llvm] df182eb - Fix an overflow issue at BackpatchWord

Jianzhou Zhao via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 26 21:47:26 PDT 2020


Author: Jianzhou Zhao
Date: 2020-08-27T04:46:19Z
New Revision: df182eb2d5fcb3ea2407097d5d2092a024c91859

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

LOG: Fix an overflow issue at BackpatchWord

This happens when generating a huge file by LTO, for example, with -gmlt.
When BitNo is > 2^35, ByteNo is overflowed, and an incorrect output offset is overwritten.
This generates ill-formed bitcodes.

Reviewed-by: tejohnson, vitalybuka

Differential Revision: https://reviews.llvm.org/D86645

Added: 
    

Modified: 
    llvm/include/llvm/Bitstream/BitstreamWriter.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Bitstream/BitstreamWriter.h b/llvm/include/llvm/Bitstream/BitstreamWriter.h
index c0ead19dc71d..162a0fea0913 100644
--- a/llvm/include/llvm/Bitstream/BitstreamWriter.h
+++ b/llvm/include/llvm/Bitstream/BitstreamWriter.h
@@ -103,7 +103,7 @@ class BitstreamWriter {
   /// with the specified value.
   void BackpatchWord(uint64_t BitNo, unsigned NewWord) {
     using namespace llvm::support;
-    unsigned ByteNo = BitNo / 8;
+    uint64_t ByteNo = BitNo / 8;
     assert((!endian::readAtBitAlignment<uint32_t, little, unaligned>(
                &Out[ByteNo], BitNo & 7)) &&
            "Expected to be patching over 0-value placeholders");


        


More information about the llvm-commits mailing list