[PATCH] D63161: Devirtualize destructor of final class.
Hiroshi Yamauchi via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 12 15:08:27 PDT 2019
yamauchi marked 2 inline comments as done.
yamauchi added inline comments.
================
Comment at: lib/CodeGen/CGExprCXX.cpp:1867-1868
- if (Dtor->isVirtual()) {
+ if (Dtor->isVirtual() &&
+ !(Dtor->hasAttr<FinalAttr>() || RD->hasAttr<FinalAttr>())) {
CGF.CGM.getCXXABI().emitVirtualObjectDelete(CGF, DE, Ptr, ElementType,
----------------
rsmith wrote:
> Can we use `getDevirtualizedMethod` here instead? That catches a few other cases that just checking for `final` will miss, and disables this for cases where it will currently do the wrong thing (eg, `-fapple-kext`). See `EmitCXXMemberOrOperatorMemberCallExpr` for where we do this for other virtual calls.
>
> As a particularly terrible example:
>
> ```
> struct A { virtual ~A() final = 0; };
> void evil(A *p) { delete p; }
> ```
>
> is (amazingly) valid, and must not be devirtualized because there is no requirement that the destructor of `A` have a definition in this program. (It would, however, be correct to optimize out the entire `delete` expression in this case, on the basis that `p` must always be `nullptr` whenever it's reached. But that doesn't really seem worthwhile.)
Updated. Hopefully this does the right thing.
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