https://github.com/tbaederr updated https://github.com/llvm/llvm-project/pull/200397
>From 84e2f85c810094bfde7d7b4332fc9e965c8e7151 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]> Date: Fri, 29 May 2026 15:27:09 +0200 Subject: [PATCH] [clang][bytecode] Reject bitcasts of objc block pointers They are unsupported and will hopefully always be. --- clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp | 16 ++++++++++++---- clang/test/AST/ByteCode/blocks.cpp | 9 +++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 clang/test/AST/ByteCode/blocks.cpp diff --git a/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp b/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp index 5f90b419f1bfb..3a565326a046d 100644 --- a/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp +++ b/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp @@ -211,11 +211,18 @@ static bool CheckBitcastType(InterpState &S, CodePtr OpPC, QualType T, << E->getSourceRange(); return false; }; - auto note = [&](int Construct, QualType NoteType, SourceRange NoteRange) { + auto note = [&](int Construct, QualType NoteType, + SourceRange NoteRange) -> bool { S.Note(NoteRange.getBegin(), diag::note_constexpr_bit_cast_invalid_subtype) << NoteType << Construct << T.getUnqualifiedType() << NoteRange; return false; }; + auto unsupported = [&](QualType T) -> bool { + S.FFDiag(S.Current->getSource(OpPC), + diag::note_constexpr_bit_cast_unsupported_type) + << T; + return false; + }; T = T.getCanonicalType(); @@ -271,12 +278,13 @@ static bool CheckBitcastType(InterpState &S, CodePtr OpPC, QualType T, // The layout for x86_fp80 vectors seems to be handled very inconsistently // by both clang and LLVM, so for now we won't allow bit_casts involving // it in a constexpr context. - const Expr *E = S.Current->getExpr(OpPC); - S.FFDiag(E, diag::note_constexpr_bit_cast_unsupported_type) << EltTy; - return false; + return unsupported(EltTy); } } + if (T->isBlockPointerType()) + return unsupported(T); + return true; } diff --git a/clang/test/AST/ByteCode/blocks.cpp b/clang/test/AST/ByteCode/blocks.cpp new file mode 100644 index 0000000000000..672384fed2c34 --- /dev/null +++ b/clang/test/AST/ByteCode/blocks.cpp @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -triple x86_64 -fcxx-exceptions -std=c++20 -fblocks -fexperimental-new-constant-interpreter -verify=expected,both %s +// RUN: %clang_cc1 -triple x86_64 -fcxx-exceptions -std=c++20 -fblocks -verify=ref,both %s + + +struct S { + void (^p)(){}; // expected-note {{invalid type 'void (^)()' is a member of 'S'}} +}; +constexpr long l = __builtin_bit_cast(long, S{}); // both-error {{must be initialized by a constant expression}} \ + // both-note {{constexpr bit cast involving type 'void (^)()' is not yet supported}} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
