https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/232186
They are function pointers, but getDecl() returns nullptr. >From 8e5623e71ecc8069b4ebfff5656286f359470ada Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]> Date: Thu, 15 Oct 2026 08:01:43 +0200 Subject: [PATCH] [clang][bytecode] Fix `Pointer::getType()` for ObjC blocks They are function pointers, but getDecl() returns nullptr. --- clang/lib/AST/ByteCode/Function.h | 5 +++++ clang/lib/AST/ByteCode/Pointer.h | 2 +- clang/test/AST/ByteCode/blocks.cpp | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/clang/lib/AST/ByteCode/Function.h b/clang/lib/AST/ByteCode/Function.h index 6215e1d6840048..3531c5070b29cf 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 fdd2fa818dea33..926516d4debba4 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 672384fed2c343..bc71ecb2f12a14 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
