This is an archive of the discontinued LLVM Phabricator instance.

[libc] Fix float to string conversion in 32-bit systems
ClosedPublic

Authored by mikhail.ramalho on Aug 1 2023, 10:24 AM.

Details

Summary

In 32-bit systems, sizeof(size_t) is 4, so we fail to build an 128-bit
integer in mul_shift_mod_1e9, which ends up ignoring the top bits in the
mantissa.

This patch fixes the issue by calling the Uint constructor directly. If
it's a system that supports 128-bit integers, the constructor that takes
a value will be called, if the system doesn't support 128-bit integers
(like rv32), mantissa is already a UInt.

Diff Detail

Event Timeline

Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptAug 1 2023, 10:24 AM
mikhail.ramalho requested review of this revision.Aug 1 2023, 10:24 AM

Thanks for catching this, I think we've added a new initializer to UInt that can handle uint128, so using that would be a cleaner and safer long term solution

Addressed comment to use UInt constructor.

mikhail.ramalho edited the summary of this revision. (Show Details)Aug 1 2023, 10:47 AM
michaelrj accepted this revision.Aug 1 2023, 11:05 AM
This revision is now accepted and ready to land.Aug 1 2023, 11:05 AM
lntue accepted this revision.Aug 1 2023, 8:38 PM