[clang] [clang][Sema] Fix crash when applying sentinel to block variable (PR #173866)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 2 06:10:57 PST 2026
https://github.com/nataliakokoromyti updated https://github.com/llvm/llvm-project/pull/173866
>From 2f4aaf3c0082cb40a72750e1779492b5f07afdea Mon Sep 17 00:00:00 2001
From: Natalia Kokoromyti <nataliakokoromyti at gmail.com>
Date: Mon, 29 Dec 2025 04:26:15 -0800
Subject: [PATCH 1/4] add test for issue #173820
---
clang/test/Sema/sentinel-attribute-block.c | 6 ++++++
1 file changed, 6 insertions(+)
create mode 100644 clang/test/Sema/sentinel-attribute-block.c
diff --git a/clang/test/Sema/sentinel-attribute-block.c b/clang/test/Sema/sentinel-attribute-block.c
new file mode 100644
index 0000000000000..65d3870f60e97
--- /dev/null
+++ b/clang/test/Sema/sentinel-attribute-block.c
@@ -0,0 +1,6 @@
+ // RUN: %clang_cc1 -fsyntax-only -fblocks -verify %s
+
+ // Test that sentinel attribute on block variables doesn't crash
+ void foo(void) {
+ void (^a)() __attribute__((__sentinel__)) = {}; // expected-warning {{'sentinel' attribute requires named arguments}}
+ }
>From 15ef1282c823d260bc5a3e46eeda31656ecdf7a7 Mon Sep 17 00:00:00 2001
From: Natalia Kokoromyti <nataliakokoromyti at gmail.com>
Date: Mon, 29 Dec 2025 04:40:03 -0800
Subject: [PATCH 2/4] fix issue #173820
---
clang/lib/Sema/SemaDeclAttr.cpp | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 263ce2118ba86..774d8f56443dc 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -2979,6 +2979,10 @@ static void handleSentinelAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
: Ty->castAs<BlockPointerType>()
->getPointeeType()
->castAs<FunctionType>();
+ if (isa<FunctionNoProtoType>(FT)) {
+ S.Diag(AL.getLoc(), diag::warn_attribute_sentinel_named_arguments);
+ return;
+ }
if (!cast<FunctionProtoType>(FT)->isVariadic()) {
int m = Ty->isFunctionPointerType() ? 0 : 1;
S.Diag(AL.getLoc(), diag::warn_attribute_sentinel_not_variadic) << m;
>From 5cb04ae32c3f67f96e1f451604386b262bde723d Mon Sep 17 00:00:00 2001
From: Natalia Kokoromyti <nataliakokoromyti at gmail.com>
Date: Fri, 2 Jan 2026 06:07:42 -0800
Subject: [PATCH 3/4] add release note for #173820
---
clang/docs/ReleaseNotes.rst | 2 ++
1 file changed, 2 insertions(+)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2319ff13f7864..36135b68ab7f9 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -640,6 +640,8 @@ Miscellaneous Bug Fixes
Miscellaneous Clang Crashes Fixed
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+- Fixed a crash when applying the ``sentinel`` attribute to block variables. (#GH173820)
+
OpenACC Specific Changes
------------------------
>From 25fdfb9d8f769c7d50b444221a8f23eea0a28483 Mon Sep 17 00:00:00 2001
From: nataliakokoromyti <126305457+nataliakokoromyti at users.noreply.github.com>
Date: Fri, 2 Jan 2026 06:10:47 -0800
Subject: [PATCH 4/4] Update ReleaseNotes.rst
---
clang/docs/ReleaseNotes.rst | 1 -
1 file changed, 1 deletion(-)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 36135b68ab7f9..226ef53787809 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -639,7 +639,6 @@ Miscellaneous Bug Fixes
Miscellaneous Clang Crashes Fixed
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
- Fixed a crash when applying the ``sentinel`` attribute to block variables. (#GH173820)
OpenACC Specific Changes
More information about the cfe-commits
mailing list