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

via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 14 23:04:00 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

<details>
<summary>Changes</summary>

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

---
Full diff: https://github.com/llvm/llvm-project/pull/232186.diff


3 Files Affected:

- (modified) clang/lib/AST/ByteCode/Function.h (+5) 
- (modified) clang/lib/AST/ByteCode/Pointer.h (+1-1) 
- (modified) clang/test/AST/ByteCode/blocks.cpp (+4) 


``````````diff
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 = ^{
+};

``````````

</details>


https://github.com/llvm/llvm-project/pull/232186


More information about the cfe-commits mailing list