diff options
author | Hiroshi Yamauchi <yamauchi@google.com> | 2019-06-21 20:04:29 +0000 |
---|---|---|
committer | Hiroshi Yamauchi <yamauchi@google.com> | 2019-06-21 20:04:29 +0000 |
commit | 405c2b16225fc6eaf5eb8ba3ce584699a3b159ef (patch) | |
tree | 1285035057b3282cce8771b3e6962af91cb2cc7f /clang/lib/CodeGen/CGExprCXX.cpp | |
parent | 22e3dc60a006baaa1bbb32e4e27d708e7c1f5b38 (diff) | |
download | bcm5719-llvm-405c2b16225fc6eaf5eb8ba3ce584699a3b159ef.tar.gz bcm5719-llvm-405c2b16225fc6eaf5eb8ba3ce584699a3b159ef.zip |
Devirtualize destructor of final class.
Summary:
Take advantage of the final keyword to devirtualize destructor calls.
Fix https://bugs.llvm.org/show_bug.cgi?id=21368
Reviewers: rsmith
Reviewed By: rsmith
Subscribers: davidxl, Prazek, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D63161
llvm-svn: 364100
Diffstat (limited to 'clang/lib/CodeGen/CGExprCXX.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGExprCXX.cpp | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp index 25b0abbc030..fdca7699888 100644 --- a/clang/lib/CodeGen/CGExprCXX.cpp +++ b/clang/lib/CodeGen/CGExprCXX.cpp @@ -1865,9 +1865,33 @@ static void EmitObjectDelete(CodeGenFunction &CGF, Dtor = RD->getDestructor(); if (Dtor->isVirtual()) { - CGF.CGM.getCXXABI().emitVirtualObjectDelete(CGF, DE, Ptr, ElementType, - Dtor); - return; + bool UseVirtualCall = true; + const Expr *Base = DE->getArgument(); + if (auto *DevirtualizedDtor = + dyn_cast_or_null<const CXXDestructorDecl>( + Dtor->getDevirtualizedMethod( + Base, CGF.CGM.getLangOpts().AppleKext))) { + UseVirtualCall = false; + const CXXRecordDecl *DevirtualizedClass = + DevirtualizedDtor->getParent(); + if (declaresSameEntity(getCXXRecord(Base), DevirtualizedClass)) { + // Devirtualized to the class of the base type (the type of the + // whole expression). + Dtor = DevirtualizedDtor; + } else { + // Devirtualized to some other type. Would need to cast the this + // pointer to that type but we don't have support for that yet, so + // do a virtual call. FIXME: handle the case where it is + // devirtualized to the derived type (the type of the inner + // expression) as in EmitCXXMemberOrOperatorMemberCallExpr. + UseVirtualCall = true; + } + } + if (UseVirtualCall) { + CGF.CGM.getCXXABI().emitVirtualObjectDelete(CGF, DE, Ptr, ElementType, + Dtor); + return; + } } } } |