Skip to content

Commit 96ae43b

Browse files
committed
[Bitstream] Use alignTo to make code more readable. NFC
I was recently debugging a similar issue to https://reviews.llvm.org/D86500 only with a large metadata section. Only after I finished debugging it did I discover it was fixed very recently. My version of the fix was going to alignTo since that uses uint64_t and improves the readability of the code. So I though I would go ahead and share it. Differential Revision: https://reviews.llvm.org/D86957
1 parent 5ded444 commit 96ae43b

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

llvm/lib/Bitstream/Reader/BitstreamReader.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,7 @@ Expected<unsigned> BitstreamCursor::skipRecord(unsigned AbbrevID) {
187187
SkipToFourByteBoundary(); // 32-bit alignment
188188

189189
// Figure out where the end of this blob will be including tail padding.
190-
const size_t NewEnd =
191-
GetCurrentBitNo() + ((static_cast<uint64_t>(NumElts) + 3) & ~3) * 8;
190+
const size_t NewEnd = GetCurrentBitNo() + alignTo(NumElts, 4) * 8;
192191

193192
// If this would read off the end of the bitcode file, just set the
194193
// record to empty and return.
@@ -316,8 +315,7 @@ Expected<unsigned> BitstreamCursor::readRecord(unsigned AbbrevID,
316315

317316
// Figure out where the end of this blob will be including tail padding.
318317
size_t CurBitPos = GetCurrentBitNo();
319-
const size_t NewEnd =
320-
CurBitPos + ((static_cast<uint64_t>(NumElts) + 3) & ~3) * 8;
318+
const size_t NewEnd = CurBitPos + alignTo(NumElts, 4) * 8;
321319

322320
// If this would read off the end of the bitcode file, just set the
323321
// record to empty and return.

0 commit comments

Comments
 (0)