From: Peter Collingbourne <peter@pcc.me.uk>
Date: Mon, 26 Oct 2015 18:23:21 +0000 (+0000)
Subject: BitstreamWriter: Fix integer overflow.
X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=6aeb31b5f0cb1063b74b062bf453b111477ff808;p=oota-llvm.git

BitstreamWriter: Fix integer overflow.

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
---

diff --git a/include/llvm/Bitcode/BitstreamWriter.h b/include/llvm/Bitcode/BitstreamWriter.h
index bac6c574708..b13b6045987 100644
--- a/include/llvm/Bitcode/BitstreamWriter.h
+++ b/include/llvm/Bitcode/BitstreamWriter.h
@@ -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);