Author: Timm Baeder
Date: 2026-11-17T12:56:22+01:00
New Revision: a73a04501883ad390e057637a7c5739c53112692

URL: 
https://github.com/llvm/llvm-project/commit/a73a04501883ad390e057637a7c5739c53112692
DIFF: 
https://github.com/llvm/llvm-project/commit/a73a04501883ad390e057637a7c5739c53112692.diff

LOG: [clang][bytecode] Fix an assertion failure in `DoBitCast` (#243401)

Reject bitcasts to non-byte sized `_BitInt` for now.

Added: 
    

Modified: 
    clang/lib/AST/ByteCode/Interp.h
    clang/test/AST/ByteCode/builtin-bit-cast.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index 80927ecc77c0a..7509ced04de41 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -4079,6 +4079,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 8588b4217a4d9..7bf169ae15855 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

Reply via email to