llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Ryosuke Niwa (rniwa)

<details>
<summary>Changes</summary>

This PR adds the support for specifying 
[[clang::annotate_type("webkit.nodelete")]] on a function return type, in which 
case, the whole function is considered "trivial" or more precisely that it does 
not trigger any destruction of an object.

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


2 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
(+11) 
- (modified) clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp (+6) 


``````````diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index e056c35d6cf45..92fd612c11bc3 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -508,6 +508,17 @@ class TrivialFunctionAnalysisVisitor
     if (auto *FnDecl = dyn_cast<FunctionDecl>(D)) {
       if (FnDecl->isVirtualAsWritten())
         return false;
+      auto ReturnType = FnDecl->getReturnType();
+      if (auto *Type = ReturnType.getTypePtrOrNull()) {
+        if (auto *AttrType = dyn_cast<AttributedType>(Type)) {
+          if (auto *Attr = AttrType->getAttr()) {
+            if (auto *AnnotateType = dyn_cast<AnnotateTypeAttr>(Attr)) {
+              if (AnnotateType->getAnnotation() == "webkit.nodelete")
+                return true;
+            }
+          }
+        }
+      }
     }
     return WithCachedResult(D, [&]() {
       if (auto *CtorDecl = dyn_cast<CXXConstructorDecl>(D)) {
diff --git a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp 
b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
index b83eaedf264e4..14a81aba1adc1 100644
--- a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
@@ -389,6 +389,9 @@ class RefCounted {
   unsigned trivial71() { return std::bit_cast<unsigned>(nullptr); }
   unsigned trivial72() { Number n { 5 }; return WTF::move(n).value(); }
 
+  unsigned [[clang::annotate_type("webkit.nodelete")]] nodelete1();
+  void [[clang::annotate_type("webkit.nodelete")]] nodelete2();
+
   static RefCounted& singleton() {
     static RefCounted s_RefCounted;
     s_RefCounted.ref();
@@ -581,6 +584,9 @@ class UnrelatedClass {
     getFieldTrivial().trivial70(); // no-warning
     getFieldTrivial().trivial71(); // no-warning
 
+    getFieldTrivial().nodelete1(); // no-warning
+    getFieldTrivial().nodelete2(); // no-warning
+
     RefCounted::singleton().trivial18(); // no-warning
     RefCounted::singleton().someFunction(); // no-warning
     RefCounted::otherSingleton().trivial18(); // no-warning

``````````

</details>


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

Reply via email to