This is an archive of the discontinued LLVM Phabricator instance.

[libc] fix shifting exact multiples of 64 in uint
ClosedPublic

Authored by michaelrj on Dec 14 2022, 4:54 PM.

Details

Summary

The internal uint class had a bug introduced recently when optimizing
the shift routines. When calculating the value of a block, it would
shift an adjacent block by 64 - the shift amount. If the shift amount
was 0, this would be a shift of 64, which is undefined for a 64 bit
integer. This patch fixes this by adding a conditional to catch this
case.

Diff Detail

Event Timeline

michaelrj created this revision.Dec 14 2022, 4:54 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptDec 14 2022, 4:54 PM
michaelrj requested review of this revision.Dec 14 2022, 4:54 PM
lntue added inline comments.Dec 15 2022, 6:43 AM
libc/src/__support/UInt.h
378

Can you change it similar to the fix for shift right in https://reviews.llvm.org/D139566? I.e., move the check for shift == 0 or shift > 0 outside of the loop?

434

This is not needed as shift is guaranteed to be positive in line 426. This was actually fixed in https://reviews.llvm.org/D139566

michaelrj marked 2 inline comments as done.

move check for shift of 0 outside of loop for shift_left
remove redundant check in shift right

lntue accepted this revision.Dec 15 2022, 12:00 PM
This revision is now accepted and ready to land.Dec 15 2022, 12:00 PM
This revision was landed with ongoing or failed builds.Dec 15 2022, 1:01 PM
This revision was automatically updated to reflect the committed changes.