https://github.com/nataliakokoromyti created https://github.com/llvm/llvm-project/pull/173866
This PR avoids the crash in Clang Sema when the sentinel attribute is applied to a block variable (see [issue](https://github.com/llvm/llvm-project/issues/173820)) basically, handleSentinelAttr always treated the type as a function with a prototype which is not true for block variables like void (^a)() and it caused Clang to crash. Now Clang will print a warning instead of crashing. >From 2f4aaf3c0082cb40a72750e1779492b5f07afdea Mon Sep 17 00:00:00 2001 From: Natalia Kokoromyti <[email protected]> Date: Mon, 29 Dec 2025 04:26:15 -0800 Subject: [PATCH 1/2] 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 <[email protected]> Date: Mon, 29 Dec 2025 04:40:03 -0800 Subject: [PATCH 2/2] 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; _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
