[clang] [WebKit Checkers] Trivial analysis should check destructors of function parameters and local variables (PR #181576)

Balázs Benics via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 16 13:47:24 PST 2026


================
@@ -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);
+      }
+      if (auto *AT = dyn_cast<ConstantArrayType>(Type)) {
+        auto *T = AT->getElementType().getTypePtrOrNull();
+        return T && CanTriviallyDestruct(T);
+      }
----------------
steakhal wrote:

So constant array types are one sort of arrays. There are in total 4 different kinds of [arrays](https://clang.llvm.org/doxygen/classclang_1_1ArrayType.html), so shouldn't we handle them all here by handling the `ArrayType` common base class?

https://github.com/llvm/llvm-project/pull/181576


More information about the cfe-commits mailing list