================
@@ -542,6 +546,49 @@ 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;
+      const CXXRecordDecl *R = Type->getAsCXXRecordDecl();
+      if (!R) {
+        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.
+          QT = RT->getPointeeType();
+          Type = QT.getTypePtrOrNull();
+          if (!Type)
+            return false;
+          R = Type->getAsCXXRecordDecl();
+        }
+      }
+      if (!R) {
+        if (auto *AT = dyn_cast<ConstantArrayType>(Type)) {
+          QT = AT->getElementType();
+          Type = QT.getTypePtrOrNull();
----------------
steakhal wrote:

There is too much mutation in this function, across different branches.
This makes it hard to reason about.
Please refactor this to avoid mutating any variable.

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