BitstreamWriter: Fix integer overflow.
authorPeter Collingbourne <peter@pcc.me.uk>
Mon, 26 Oct 2015 18:23:21 +0000 (18:23 +0000)
committerPeter Collingbourne <peter@pcc.me.uk>
Mon, 26 Oct 2015 18:23:21 +0000 (18:23 +0000)
We were previously overflowing a 32-bit multiply operation when emitting large
(>512MB) bitcode files, resulting in corrupted bitcode. Fix by extending
one of the operands to 64 bits.

There are a few other 32-bit integer types in this code that seem like they
also ought to be extended to 64 bits; this will be done separately.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@251323 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Bitcode/BitstreamWriter.h

index bac6c57470840128c0e4c89f95f25c42406ff3b6..b13b6045987a29a769817749f2dc5be8f87346a0 100644 (file)
@@ -243,7 +243,7 @@ public:
 
     // Compute the size of the block, in words, not counting the size field.
     unsigned SizeInWords = GetWordIndex() - B.StartSizeWord - 1;
-    uint64_t BitNo = B.StartSizeWord * 32;
+    uint64_t BitNo = uint64_t(B.StartSizeWord) * 32;
 
     // Update the block size field in the header of this sub-block.
     BackpatchWord(BitNo, SizeInWords);