[PATCH] D63161: Devirtualize destructor of final class.

Hiroshi Yamauchi via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 14 14:52:40 PDT 2019


yamauchi marked an inline comment as done.
yamauchi added inline comments.


================
Comment at: lib/CodeGen/CGExprCXX.cpp:1871
+                                             CGF.CGM.getLangOpts().AppleKext)))
+          Dtor = DevirtualizedDtor;
+        else {
----------------
rsmith wrote:
> `Dtor` could be the destructor for a type derived from `ElementPtr`. We'll either need to somehow emit a cast to the correct derived type here, or just abort the devirtualization and emit a virtual call in that case. (The latter is what `EmitCXXMemberOrOperatorMemberCallExpr` does -- see its checks on `getCXXRecord(Base)` and `getCXXRecord(Inner)`.)
> 
> Eg, for:
> 
> ```
> struct SomethingElse { virtual void f(); };
> struct A {
>   virtual ~A();
> };
> struct B : SomethingElse, A {
>   ~B() final;
> };
> void f(B *p) {
>   delete (A*)p;
> }
> ```
> 
> ... `Ptr` will be a pointer to an `A` subobject of a `B` object, but `getDevirtualizedMethod` will still be able to work out that `B::~B` is the right thing to call here (by looking through the cast and finding that the pointer must actually point to a `B` object whose destructor is `final`). We need to either convert `Ptr` back from an `A*` to a `B*` or just not devirtualize this call.
Should be good now.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63161/new/

https://reviews.llvm.org/D63161





More information about the cfe-commits mailing list