|
27 | 27 | #include "lldb/Utility/Stream.h"
|
28 | 28 |
|
29 | 29 | #include "llvm/ADT/APInt.h"
|
| 30 | +#include "llvm/ADT/bit.h" |
30 | 31 |
|
31 | 32 | #include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.h"
|
32 | 33 |
|
@@ -749,49 +750,43 @@ bool lldb_private::formatters::NSURLSummaryProvider(
|
749 | 750 | /// distantFuture, except within about 1e-25 second of the reference date.
|
750 | 751 | const int TAGGED_DATE_EXPONENT_BIAS = 0x3ef;
|
751 | 752 |
|
752 |
| -typedef union { |
753 |
| - struct { |
754 |
| - uint64_t fraction:52; // unsigned |
755 |
| - uint64_t exponent:11; // signed |
756 |
| - uint64_t sign:1; |
757 |
| - } repr; |
758 |
| - uint64_t i; |
759 |
| - double d; |
760 |
| -} DoubleBits; |
761 |
| -typedef union { |
762 |
| - struct { |
763 |
| - uint64_t fraction:52; // unsigned |
764 |
| - uint64_t exponent:7; // signed |
765 |
| - uint64_t sign:1; |
766 |
| - uint64_t unused:4; // placeholder for pointer tag bits |
767 |
| - } repr; |
768 |
| - uint64_t i; |
769 |
| -} TaggedDoubleBits; |
| 753 | +struct DoubleBits { |
| 754 | + uint64_t fraction : 52; // unsigned |
| 755 | + uint64_t exponent : 11; // signed |
| 756 | + uint64_t sign : 1; |
| 757 | +}; |
| 758 | + |
| 759 | +struct TaggedDoubleBits { |
| 760 | + uint64_t fraction : 52; // unsigned |
| 761 | + uint64_t exponent : 7; // signed |
| 762 | + uint64_t sign : 1; |
| 763 | + uint64_t unused : 4; // placeholder for pointer tag bits |
| 764 | +}; |
770 | 765 |
|
771 | 766 | static uint64_t decodeExponent(uint64_t exp) {
|
772 | 767 | // Tagged exponent field is 7-bit signed. Sign-extend the value to 64 bits
|
773 | 768 | // before performing arithmetic.
|
774 | 769 | return llvm::SignExtend64<7>(exp) + TAGGED_DATE_EXPONENT_BIAS;
|
775 | 770 | }
|
776 | 771 |
|
777 |
| -static uint64_t decodeTaggedTimeInterval(uint64_t encodedTimeInterval) { |
| 772 | +static double decodeTaggedTimeInterval(uint64_t encodedTimeInterval) { |
778 | 773 | if (encodedTimeInterval == 0)
|
779 | 774 | return 0.0;
|
780 | 775 | if (encodedTimeInterval == std::numeric_limits<uint64_t>::max())
|
781 | 776 | return (uint64_t)-0.0;
|
782 | 777 |
|
783 |
| - TaggedDoubleBits encodedBits = {}; |
784 |
| - encodedBits.i = encodedTimeInterval; |
785 |
| - DoubleBits decodedBits; |
| 778 | + TaggedDoubleBits encodedBits = |
| 779 | + llvm::bit_cast<TaggedDoubleBits>(encodedTimeInterval); |
| 780 | + assert(encodedBits.unused == 0); |
786 | 781 |
|
787 | 782 | // Sign and fraction are represented exactly.
|
788 | 783 | // Exponent is encoded.
|
789 |
| - assert(encodedBits.repr.unused == 0); |
790 |
| - decodedBits.repr.sign = encodedBits.repr.sign; |
791 |
| - decodedBits.repr.fraction = encodedBits.repr.fraction; |
792 |
| - decodedBits.repr.exponent = decodeExponent(encodedBits.repr.exponent); |
| 784 | + DoubleBits decodedBits; |
| 785 | + decodedBits.sign = encodedBits.sign; |
| 786 | + decodedBits.fraction = encodedBits.fraction; |
| 787 | + decodedBits.exponent = decodeExponent(encodedBits.exponent); |
793 | 788 |
|
794 |
| - return decodedBits.d; |
| 789 | + return llvm::bit_cast<double>(decodedBits); |
795 | 790 | }
|
796 | 791 |
|
797 | 792 | bool lldb_private::formatters::NSDateSummaryProvider(
|
@@ -868,7 +863,8 @@ bool lldb_private::formatters::NSDateSummaryProvider(
|
868 | 863 |
|
869 | 864 | // Accomodate for the __NSTaggedDate format introduced in Foundation 1600.
|
870 | 865 | if (class_name == g___NSTaggedDate) {
|
871 |
| - auto *runtime = llvm::dyn_cast_or_null<AppleObjCRuntime>(process_sp->GetObjCLanguageRuntime()); |
| 866 | + auto *runtime = llvm::dyn_cast_or_null<AppleObjCRuntime>( |
| 867 | + process_sp->GetObjCLanguageRuntime()); |
872 | 868 | if (runtime && runtime->GetFoundationVersion() >= 1600)
|
873 | 869 | date_value = decodeTaggedTimeInterval(value_bits << 4);
|
874 | 870 | }
|
|
0 commit comments