Author: Timm Baeder
Date: 2026-05-30T05:46:34+02:00
New Revision: 0c94404f2135d3e6f34388d8118ddb64d27f3c02

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

LOG: [clang][bytecode] Reject bitcasts of objc block pointers (#200397)

They are unsupported and will hopefully always be.

Added: 
    clang/test/AST/ByteCode/blocks.cpp

Modified: 
    clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp

Removed: 
    


################################################################################
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

Reply via email to