================
@@ -542,6 +558,29 @@ class TrivialFunctionAnalysisVisitor
     });
   }
 
+  bool HasTrivialDestructor(const VarDecl *VD) {
+    return WithCachedResult(VD, [&]() {
+      auto QT = VD->getType();
+      if (QT.isPODType(VD->getASTContext()))
+        return true;
+      auto *Type = QT.getTypePtrOrNull();
+      if (!Type)
+        return false;
+      if (isa<LValueReferenceType>(Type))
+        return true; // T& does not run its destructor.
+      if (auto *RT = dyn_cast<RValueReferenceType>(Type)) {
+        // For T&&, we evaluate the destructor of T.
+        auto *T = RT->getPointeeType().getTypePtrOrNull();
+        return T && CanTriviallyDestruct(T);
+      }
----------------
rniwa wrote:

I was thinking of a case like this (which in the test):
```
  void [[clang::annotate_type("webkit.nodelete")]] 
swapObj(RefPtr<RefCountable>&& obj) {
    // expected-warning@-1{{A function 'swapObj' has 
[[clang::annotate_type("webkit.nodelete")]] but it contains code that could 
destruct an object}}
    m_obj.swap(obj);
  }
```
where the argument variable gets a new value during the function such that it 
would destruct. Although now that I'm thinking about it more, even in the case 
of swap, we don't really destruct within this function so maybe we should treat 
both references as safe after all.

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

Reply via email to