[PATCH] D12366: Avoid unnecessarily storing vtable pointers in more destructor cases

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 26 17:11:12 PDT 2015


rsmith added a subscriber: rsmith.

================
Comment at: lib/CodeGen/CGClass.cpp:1369-1382
@@ +1368,16 @@
+
+    void VisitCallExpr(const Expr *E) {
+      Sensitive = true;
+    }
+    void VisitCXXTypeidExpr(const Expr *E) {
+      Sensitive = true;
+    }
+    void VisitExpr(const Expr *E) {
+      if (E->getStmtClass() == Stmt::CXXTypeidExprClass ||
+          E->getStmtClass() == Stmt::CXXDynamicCastExprClass) {
+        Sensitive = true;
+      }
+      if (!Sensitive)
+        Inherited::VisitExpr(E);
+    }
+  };
----------------
This is not complete; you'll also need to at least consider atomic stores (that might store the `this` pointer and be picked up by another thread), the implicit call to `operator new` in a `CXXNewExpr` (which is not modeled as a `CallExpr`), implicit destructor calls (which aren't modeled in the AST at all), and probably a lot of other cases.

Maybe it would be simpler to store `undef` to the vptr immediately before calling the base class destructor, and let the LLVM optimization passes remove this vptr store as dead if it can prove the vptr is unused?


http://reviews.llvm.org/D12366





More information about the cfe-commits mailing list