diff --git a/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp b/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp index 2569cac018b3..feac97d4b1a6 100644 --- a/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp +++ b/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp @@ -335,7 +335,8 @@ bool clang::interp::DoBitCast(InterpState &S, CodePtr OpPC, const Pointer &Ptr, BitcastBuffer Buffer(FullBitWidth); size_t BuffSize = FullBitWidth.roundToBytes(); - if (!CheckBitcastType(S, OpPC, Ptr.getType(), /*IsToType=*/false)) + QualType DataType = Ptr.getFieldDesc()->getDataType(S.getASTContext()); + if (!CheckBitcastType(S, OpPC, DataType, /*IsToType=*/false)) return false; bool Success = readPointerToBuffer(S.getContext(), Ptr, Buffer, @@ -370,8 +371,8 @@ bool clang::interp::DoBitCastPtr(InterpState &S, CodePtr OpPC, assert(FromPtr.isBlockPointer()); assert(ToPtr.isBlockPointer()); - QualType FromType = FromPtr.getType(); - QualType ToType = ToPtr.getType(); + QualType FromType = FromPtr.getFieldDesc()->getDataType(S.getASTContext()); + QualType ToType = ToPtr.getFieldDesc()->getDataType(S.getASTContext()); if (!CheckBitcastType(S, OpPC, ToType, /*IsToType=*/true)) return false; diff --git a/clang/test/AST/ByteCode/placement-new.cpp b/clang/test/AST/ByteCode/placement-new.cpp index f23d71510602..670def2d5870 100644 --- a/clang/test/AST/ByteCode/placement-new.cpp +++ b/clang/test/AST/ByteCode/placement-new.cpp @@ -1,6 +1,7 @@ // RUN: %clang_cc1 -std=c++2c -fcxx-exceptions -fexperimental-new-constant-interpreter -verify=expected,both %s -DBYTECODE // RUN: %clang_cc1 -std=c++2c -fcxx-exceptions -verify=ref,both %s +typedef __INT64_TYPE__ int64_t; namespace std { using size_t = decltype(sizeof(0)); template struct allocator { @@ -465,3 +466,23 @@ namespace ArrayRoot { static_assert(foo() == 0); } + +namespace bitcast { + template + constexpr T bit_cast(const F &f) { + return __builtin_bit_cast(T, f); + } + constexpr int foo() { + double *d = std::allocator{}.allocate(2); + std::construct_at(d, 0); + + double &dd = *d; + + int64_t i = bit_cast(*d); + + + std::allocator{}.deallocate(d); + return i; + } + static_assert(foo() == 0); +}