https://github.com/Serosh-commits updated 
https://github.com/llvm/llvm-project/pull/190377

>From 6ee8dade934490c35e77c607fcdffa03b42ed286 Mon Sep 17 00:00:00 2001
From: Serosh-commits <[email protected]>
Date: Fri, 3 Apr 2026 23:14:48 +0530
Subject: [PATCH] Fix block pointer NTTP crash

---
 clang/docs/ReleaseNotes.rst                  | 2 ++
 clang/lib/Sema/SemaTemplate.cpp              | 4 +++-
 clang/test/CodeGenCXX/block-pointer-nttp.cpp | 6 ++++++
 clang/test/SemaCXX/gh189247.cpp              | 8 ++++++++
 4 files changed, 19 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGenCXX/block-pointer-nttp.cpp
 create mode 100644 clang/test/SemaCXX/gh189247.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 442ec58adc25a..1f405982ca0fe 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -427,6 +427,8 @@ Bug Fixes to C++ Support
 - Fixed a crash when an immediate-invoked ``consteval`` lambda is used as an 
invalid initializer. (#GH185270)
 - Fixed an assertion failure when using a global destructor with a target with 
a non-default program address space. (#GH186484)
 
+- Fixed a crash when passing ``nullptr`` as a template argument for a non-type 
template parameter of block pointer type. (#GH189247)
+
 - Inherited constructors in ``dllexport`` classes are now exported for 
ABI-compatible cases, matching 
   MSVC behavior. Constructors with variadic arguments or callee-cleanup 
parameters are not yet supported 
   and produce a warning. (#GH162640)
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index aa72cb8fa2895..d03ca7ae7b071 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -1472,6 +1472,8 @@ QualType Sema::CheckNonTypeTemplateParameterType(QualType 
T,
       T->isLValueReferenceType() ||
       //   -- pointer to member,
       T->isMemberPointerType() ||
+      //   -- block pointer,
+      T->isBlockPointerType() ||
       //   -- std::nullptr_t, or
       T->isNullPtrType() ||
       //   -- a type that contains a placeholder type.
@@ -7355,7 +7357,7 @@ ExprResult Sema::CheckTemplateArgument(NamedDecl *Param, 
QualType ParamType,
       //   For a non-type template-parameter of pointer or reference type,
       //   the value of the constant expression shall not refer to
       assert(ParamType->isPointerOrReferenceType() ||
-             ParamType->isNullPtrType());
+             ParamType->isNullPtrType() || ParamType->isBlockPointerType());
       // -- a temporary object
       // -- a string literal
       // -- the result of a typeid expression, or
diff --git a/clang/test/CodeGenCXX/block-pointer-nttp.cpp 
b/clang/test/CodeGenCXX/block-pointer-nttp.cpp
new file mode 100644
index 0000000000000..10de5a69af9e2
--- /dev/null
+++ b/clang/test/CodeGenCXX/block-pointer-nttp.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fblocks -triple x86_64-apple-darwin -emit-llvm -o - %s | 
FileCheck %s
+
+template<int (^F)(void)> struct T;
+
+// CHECK: define void @_Z1g1TILYU13block_pointerFiEvE0EE
+void g(T<nullptr> *p) {}
diff --git a/clang/test/SemaCXX/gh189247.cpp b/clang/test/SemaCXX/gh189247.cpp
new file mode 100644
index 0000000000000..376117cb280da
--- /dev/null
+++ b/clang/test/SemaCXX/gh189247.cpp
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -fblocks -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+template<void (^)(void)> struct T;
+T<nullptr> *t;
+
+template<int (^F)(void)> struct T2 { static const int value = F(); };
+static_assert(T2<^(){ return 42; }>::value == 42);

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

Reply via email to