https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/114471
Only for full-byte bitwidths for now. >From 6543ec71a9e5692c1142a1a4c3da5843accee756 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbae...@redhat.com> Date: Thu, 31 Oct 2024 23:14:41 +0100 Subject: [PATCH] [clang][bytecode] Implement IntegralAP bitcasting Only for full-byte bitwidths for now. --- clang/lib/AST/ByteCode/IntegralAP.h | 8 ++++++-- clang/test/AST/ByteCode/builtin-bit-cast.cpp | 5 +++++ 2 files changed, 11 insertions(+), 2 deletions(-) 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