[clang] [Clang] Mark this pointer in destructors dead_on_return (PR #166276)

Antonio Frighetto via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 2 12:38:53 PST 2025


================
@@ -2800,6 +2802,19 @@ void CodeGenModule::ConstructAttributeList(StringRef Name,
             .getAsAlign();
     Attrs.addAlignmentAttr(Alignment);
 
+    const auto *DD = dyn_cast_if_present<CXXDestructorDecl>(
+        CalleeInfo.getCalleeDecl().getDecl());
+    if (DD && CodeGenOpts.MarkObjectsDeadAfterDestructors) {
+      const CXXRecordDecl *ClassDecl =
+          dyn_cast<CXXRecordDecl>(DD->getDeclContext());
+      // TODO(boomanaiden154): We are being intentionally conservative here
+      // as we gain experience with this optimization. These checks should be
+      // removed once we have done further integration testing.
+      if (ClassDecl->getNumBases() == 0 && ClassDecl->getNumVBases() == 0) {
----------------
antoniofrighetto wrote:

Braces not needed.

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


More information about the cfe-commits mailing list