From: Siva Chandra Reddy Date: Tue, 28 Jul 2020 18:43:04 +0000 (-0700) Subject: [libc][NFC] Zero out padding bits in the uint form of x86 FPBits. X-Git-Tag: llvmorg-13-init~16553 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9cc70e047c2892a318ade3afacab7faffa4f49cc;p=platform%2Fupstream%2Fllvm.git [libc][NFC] Zero out padding bits in the uint form of x86 FPBits. --- diff --git a/libc/utils/FPUtil/LongDoubleBitsX86.h b/libc/utils/FPUtil/LongDoubleBitsX86.h index 5438e0b..4d64490 100644 --- a/libc/utils/FPUtil/LongDoubleBitsX86.h +++ b/libc/utils/FPUtil/LongDoubleBitsX86.h @@ -23,10 +23,10 @@ template <> struct MantissaWidth { template struct Padding; // i386 padding. -template <> struct Padding<4> { static constexpr unsigned Value = 16; }; +template <> struct Padding<4> { static constexpr unsigned value = 16; }; // x86_64 padding. -template <> struct Padding<8> { static constexpr unsigned Value = 48; }; +template <> struct Padding<8> { static constexpr unsigned value = 48; }; template <> struct __attribute__((packed)) FPBits { using UIntType = __uint128_t; @@ -38,7 +38,7 @@ template <> struct __attribute__((packed)) FPBits { uint8_t implicitBit : 1; uint16_t exponent : ExponentWidth::value; uint8_t sign : 1; - uint64_t padding : Padding::Value; + uint64_t padding : Padding::value; template ::Value, int> = 0> @@ -91,7 +91,15 @@ template <> struct __attribute__((packed)) FPBits { // zero in case i386. UIntType result = UIntType(0); *reinterpret_cast *>(&result) = *this; - return result; + + // Even though we zero out |result| before copying the long double value, + // there can be garbage bits in the padding. So, we zero the padding bits + // in |result|. + static constexpr UIntType mask = + (UIntType(1) << (sizeof(long double) - + Padding::value / 8)) - + 1; + return result & mask; } static FPBits zero() { return FPBits(0.0l); }