Author: Timm Baeder
Date: 2026-10-28T12:27:23+01:00
New Revision: fafd000acdfee49c76f6b307d6cc41523dc734e2

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

LOG: [clang][bytecode] Fix assertion with string pointers in `DoBitCast` 
(#236337)

Make sure we support bitcasting _from_ string pointers here.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
index 3bec4f3bf1396b..7895c4b62ae895 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
@@ -423,7 +423,7 @@ bool clang::interp::DoBitCast(InterpState &S, CodePtr OpPC, 
const Pointer &Ptr,
                               std::byte *Buff, Bits BitWidth, Bits 
FullBitWidth,
                               bool &HasIndeterminateBits) {
   assert(Ptr.isLive());
-  assert(Ptr.isBlockPointer());
+  assert(Ptr.isReadablePointerType());
   assert(Buff);
   assert(BitWidth <= FullBitWidth);
   assert(FullBitWidth.isFullByte());
@@ -431,7 +431,7 @@ bool clang::interp::DoBitCast(InterpState &S, CodePtr OpPC, 
const Pointer &Ptr,
 
   BitcastBuffer Buffer(FullBitWidth);
   size_t BuffSize = FullBitWidth.roundToBytes();
-  QualType DataType = Ptr.getFieldDesc()->getDataType(S.getASTContext());
+  QualType DataType = Ptr.getType();
   if (!CheckBitcastType(S, OpPC, DataType, /*IsToType=*/false))
     return false;
 

diff  --git a/clang/test/AST/ByteCode/builtin-bit-cast.cpp 
b/clang/test/AST/ByteCode/builtin-bit-cast.cpp
index 368728d00a8121..2aaf84f9130c79 100644
--- a/clang/test/AST/ByteCode/builtin-bit-cast.cpp
+++ b/clang/test/AST/ByteCode/builtin-bit-cast.cpp
@@ -607,3 +607,12 @@ namespace InvalidRecordDecl {
   } b;
   a c = __builtin_bit_cast(a, b);
 }
+
+namespace StringInDoBitCast {
+  template <class C, class I> constexpr bool foo(const I &i) {
+    return __builtin_bit_cast(I, reinterpret_cast<const float &>("")) == i; // 
both-note {{reinterpret_cast is not allowed in a constant expression}}
+  }
+  typedef bool b32 __attribute__((ext_vector_type(32)));
+  static_assert(foo<b32>(0x42), ""); // both-error {{not an integral constant 
expression}} \
+                                     // both-note {{in call to}}
+}


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to