From 7eae8c6e62b2a91e71aade19324b9d2242bcb4ab Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Fri, 8 Oct 2021 19:06:22 -0700 Subject: Don't update the vptr at the start of the destructor of a final class. In this case, we know statically that we're destroying the most-derived class, so the vptr must already point to the current class and never needs to be updated. --- clang/lib/CodeGen/CGClass.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'clang/lib/CodeGen/CGClass.cpp') diff --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp index 828dd71..0df64d4 100644 --- a/clang/lib/CodeGen/CGClass.cpp +++ b/clang/lib/CodeGen/CGClass.cpp @@ -1424,6 +1424,11 @@ static bool CanSkipVTablePointerInitialization(CodeGenFunction &CGF, if (!ClassDecl->isDynamicClass()) return true; + // For a final class, the vtable pointer is known to already point to the + // class's vtable. + if (ClassDecl->isEffectivelyFinal()) + return true; + if (!Dtor->hasTrivialBody()) return false; -- cgit v1.1