Skip to content

Commit

Permalink
[Bitstream] Use alignTo to make code more readable. NFC
Browse files Browse the repository at this point in the history
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
  • Loading branch information
topperc committed Sep 1, 2020
1 parent 5ded444 commit 96ae43b
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions llvm/lib/Bitstream/Reader/BitstreamReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,7 @@ Expected<unsigned> BitstreamCursor::skipRecord(unsigned AbbrevID) {
SkipToFourByteBoundary(); // 32-bit alignment

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

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

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

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

0 comments on commit 96ae43b

Please sign in to comment.