r327754 - [MS] Fix bug in r327732 with devirtualized complete destructor calls

Reid Kleckner via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 16 15:20:57 PDT 2018


Author: rnk
Date: Fri Mar 16 15:20:57 2018
New Revision: 327754

URL: http://llvm.org/viewvc/llvm-project?rev=327754&view=rev
Log:
[MS] Fix bug in r327732 with devirtualized complete destructor calls

Added:
    cfe/trunk/test/CodeGenCXX/devirtualize-ms-dtor.cpp
Modified:
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=327754&r1=327753&r2=327754&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Fri Mar 16 15:20:57 2018
@@ -2550,6 +2550,16 @@ llvm::Constant *CodeGenModule::GetAddrOf
     Ty = getTypes().ConvertFunctionType(CanonTy, FD);
   }
 
+  // Devirtualized destructor calls may come through here instead of via
+  // getAddrOfCXXStructor. Make sure we use the MS ABI base destructor instead
+  // of the complete destructor when necessary.
+  if (const auto *DD = dyn_cast<CXXDestructorDecl>(GD.getDecl())) {
+    if (getTarget().getCXXABI().isMicrosoft() &&
+        GD.getDtorType() == Dtor_Complete &&
+        DD->getParent()->getNumVBases() == 0)
+      GD = GlobalDecl(DD, Dtor_Base);
+  }
+
   StringRef MangledName = getMangledName(GD);
   return GetOrCreateLLVMFunction(MangledName, Ty, GD, ForVTable, DontDefer,
                                  /*IsThunk=*/false, llvm::AttributeList(),

Added: cfe/trunk/test/CodeGenCXX/devirtualize-ms-dtor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/devirtualize-ms-dtor.cpp?rev=327754&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/devirtualize-ms-dtor.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/devirtualize-ms-dtor.cpp Fri Mar 16 15:20:57 2018
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -std=c++11 -triple x86_64-windows-msvc %s -emit-llvm -o - | FileCheck %s
+
+// If we de-virtualize ~Foo, we still need to call ??1Foo, not ??_DFoo.
+
+struct Base {
+  virtual ~Base();
+};
+struct Foo final : Base {
+};
+void f(Foo *p) {
+  p->~Foo();
+}
+
+// CHECK-LABEL: define{{.*}} void @"?f@@YAXPEAUFoo@@@Z"(%struct.Foo* %p)
+// CHECK: call void @"??1Foo@@UEAA at XZ"
+// CHECK: ret void




More information about the cfe-commits mailing list