Author: Timm Baeder
Date: 2026-10-15T11:29:25+02:00
New Revision: f869d0ba403123753502f993c3153d363ca30dbd

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

LOG: [clang][bytecode] Fix `Pointer::getType()` for ObjC blocks (#232186)

They are function pointers, but getDecl() returns nullptr.

Added: 
    

Modified: 
    clang/lib/AST/ByteCode/Function.h
    clang/lib/AST/ByteCode/Pointer.h
    clang/test/AST/ByteCode/blocks.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ByteCode/Function.h 
b/clang/lib/AST/ByteCode/Function.h
index 6215e1d684004..3531c5070b29c 100644
--- a/clang/lib/AST/ByteCode/Function.h
+++ b/clang/lib/AST/ByteCode/Function.h
@@ -136,6 +136,11 @@ class Function final {
   const BlockExpr *getExpr() const {
     return dyn_cast<const BlockExpr *>(Source);
   }
+  QualType getType() const {
+    if (const FunctionDecl *FD = getDecl())
+      return FD->getType();
+    return getExpr()->getType();
+  }
 
   /// Returns the name of the function decl this code
   /// was generated for.

diff  --git a/clang/lib/AST/ByteCode/Pointer.h 
b/clang/lib/AST/ByteCode/Pointer.h
index fdd2fa818dea3..926516d4debba 100644
--- a/clang/lib/AST/ByteCode/Pointer.h
+++ b/clang/lib/AST/ByteCode/Pointer.h
@@ -730,7 +730,7 @@ class Pointer {
     case Storage::Block:
       return view().getType();
     case Storage::Fn:
-      return Fn.Func->getDecl()->getType();
+      return Fn.Func->getType();
     case Storage::Typeid:
       return QualType(Typeid.TypeInfoType, 0);
     case Storage::String:

diff  --git a/clang/test/AST/ByteCode/blocks.cpp 
b/clang/test/AST/ByteCode/blocks.cpp
index 672384fed2c34..bc71ecb2f12a1 100644
--- a/clang/test/AST/ByteCode/blocks.cpp
+++ b/clang/test/AST/ByteCode/blocks.cpp
@@ -7,3 +7,7 @@ struct 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}}
+
+typedef void (^foo)();
+const foo &bar = ^{
+};


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

Reply via email to