This is an archive of the discontinued LLVM Phabricator instance.

[libc] Fix undefined behavior in UInt<>::shift_right.
ClosedPublic

Authored by lntue on Dec 7 2022, 11:27 AM.

Details

Summary

Fix undefined behavior of left-shifting uint64_t by 64 in
UInt<>::shift_right implementation.

Diff Detail

Event Timeline

lntue created this revision.Dec 7 2022, 11:27 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptDec 7 2022, 11:27 AM
lntue requested review of this revision.Dec 7 2022, 11:27 AM
michaelrj added inline comments.Dec 7 2022, 1:00 PM
libc/test/src/__support/uint_test.cpp
516

is there a reason that these tests are changed?

lntue added inline comments.Dec 7 2022, 1:09 PM
libc/test/src/__support/uint_test.cpp
516

Those were the correct bounds of the tests. Previously these tests failed with the correct bounds, and it turns out because of the undefined behavior in the shift function that is fixed in this patch.

michaelrj accepted this revision.Dec 7 2022, 1:13 PM
michaelrj added inline comments.
libc/test/src/__support/uint_test.cpp
516

SGTM

This revision is now accepted and ready to land.Dec 7 2022, 1:13 PM
sivachandra accepted this revision.Dec 7 2022, 3:03 PM
This revision was automatically updated to reflect the committed changes.