https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/243401
Reject bitcasts to non-byte sized `_BitInt` for now. >From 1d1646457489843e883d7c3675e310b0d93c7796 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]> Date: Tue, 17 Nov 2026 10:25:01 +0100 Subject: [PATCH] [clang][bytecode] Fix an assertion failure in `DoBitCast` Reject bitcasts to non-byte sized `_BitInt` for now. --- clang/lib/AST/ByteCode/Interp.h | 6 ++++++ clang/test/AST/ByteCode/builtin-bit-cast.cpp | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h index 18c2421a67231e..4a967192de0b2f 100644 --- a/clang/lib/AST/ByteCode/Interp.h +++ b/clang/lib/AST/ByteCode/Interp.h @@ -4076,6 +4076,12 @@ inline bool BitCastPrim(InterpState &S, CodePtr OpPC, bool TargetIsUCharOrByte, bool HasIndeterminateBits = false; Bits FullBitWidth(ResultBitWidth); + + // FIXME: Since we support bitcasts of bitfields, we should also support + // this. + if (!FullBitWidth.isFullByte()) + return false; + Bits BitWidth = FullBitWidth; if constexpr (std::is_same_v<T, Floating>) { diff --git a/clang/test/AST/ByteCode/builtin-bit-cast.cpp b/clang/test/AST/ByteCode/builtin-bit-cast.cpp index 8588b4217a4d9a..7bf169ae15855f 100644 --- a/clang/test/AST/ByteCode/builtin-bit-cast.cpp +++ b/clang/test/AST/ByteCode/builtin-bit-cast.cpp @@ -624,3 +624,10 @@ namespace nullptrToArray { // both-note {{read of uninitialized object}} \ // both-note {{temporary created here}} } + +namespace BitInt20 { + constexpr _BitInt(32) BI = ~0; + constexpr unsigned int I = __builtin_bit_cast(unsigned int, BI); + constexpr _BitInt(32) IB = __builtin_bit_cast(_BitInt(20), I); // both-error {{must be initialized by a constant expression}} \ + // ref-note {{constexpr bit cast involving type '_BitInt(20)' is not yet supported}} +} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
