https://github.com/Serosh-commits updated https://github.com/llvm/llvm-project/pull/190377
>From dbc6c6502dda4c0f08897b6c6857817be3b02207 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 | 5 +++++ 4 files changed, 16 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..008ef0e795aa6 --- /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 @_Z1gP1TILU13block_pointerFivE0EE(ptr noundef %p) +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..79f7b312aee83 --- /dev/null +++ b/clang/test/SemaCXX/gh189247.cpp @@ -0,0 +1,5 @@ +// RUN: %clang_cc1 -fblocks -fsyntax-only -verify %s +// expected-no-diagnostics + +template<void (^)(void)> struct T; +T<nullptr> *t; _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
