Author: Timm Baeder Date: 2024-11-01T09:15:05+01:00 New Revision: 1e19f0f9d92b5e9c43d53893e387341835d3d96b
URL: https://github.com/llvm/llvm-project/commit/1e19f0f9d92b5e9c43d53893e387341835d3d96b DIFF: https://github.com/llvm/llvm-project/commit/1e19f0f9d92b5e9c43d53893e387341835d3d96b.diff LOG: [clang][bytecode] Implement IntegralAP bitcasting (#114471) Only for full-byte bitwidths for now. Added: Modified: clang/lib/AST/ByteCode/IntegralAP.h clang/test/AST/ByteCode/builtin-bit-cast.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/ByteCode/IntegralAP.h b/clang/lib/AST/ByteCode/IntegralAP.h index 6a37d0a3ba4a51..8ee08dfb5cfe74 100644 --- a/clang/lib/AST/ByteCode/IntegralAP.h +++ b/clang/lib/AST/ByteCode/IntegralAP.h @@ -171,10 +171,14 @@ template <bool Signed> class IntegralAP final { return IntegralAP<false>(Copy); } - void bitcastToMemory(std::byte *Dest) const { assert(false); } + void bitcastToMemory(std::byte *Dest) const { + llvm::StoreIntToMemory(V, (uint8_t *)Dest, bitWidth() / 8); + } static IntegralAP bitcastFromMemory(const std::byte *Src, unsigned BitWidth) { - return IntegralAP(); + APInt V(BitWidth, static_cast<uint64_t>(0), Signed); + llvm::LoadIntFromMemory(V, (const uint8_t *)Src, BitWidth / 8); + return IntegralAP(V); } ComparisonCategoryResult compare(const IntegralAP &RHS) const { diff --git a/clang/test/AST/ByteCode/builtin-bit-cast.cpp b/clang/test/AST/ByteCode/builtin-bit-cast.cpp index 58cf486833412f..0e86da9133b33d 100644 --- a/clang/test/AST/ByteCode/builtin-bit-cast.cpp +++ b/clang/test/AST/ByteCode/builtin-bit-cast.cpp @@ -71,6 +71,11 @@ constexpr bool operator==(const struct bits<N, T, P>& lhs, const struct bits<N, return lhs.bits == rhs.bits; } +#ifdef __SIZEOF_INT128__ +static_assert(check_round_trip<__int128_t>((__int128_t)34)); +static_assert(check_round_trip<__int128_t>((__int128_t)-34)); +#endif + namespace simple { constexpr int A = __builtin_bit_cast(int, 10); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits