llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: None (nataliakokoromyti)

<details>
<summary>Changes</summary>

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. 




---
Full diff: https://github.com/llvm/llvm-project/pull/173866.diff


2 Files Affected:

- (modified) clang/lib/Sema/SemaDeclAttr.cpp (+4) 
- (added) clang/test/Sema/sentinel-attribute-block.c (+6) 


``````````diff
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;
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}}
+  }

``````````

</details>


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

Reply via email to