From 6241e31869d5f61514c578ec9665cdf281244a96 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Fri, 16 Mar 2018 22:20:57 +0000 Subject: [PATCH] [MS] Fix bug in r327732 with devirtualized complete destructor calls git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@327754 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenModule.cpp | 10 ++++++++++ test/CodeGenCXX/devirtualize-ms-dtor.cpp | 16 ++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 test/CodeGenCXX/devirtualize-ms-dtor.cpp diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index e221b64d2e..a47c1c649d 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -2550,6 +2550,16 @@ llvm::Constant *CodeGenModule::GetAddrOfFunction(GlobalDecl GD, 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(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(), diff --git a/test/CodeGenCXX/devirtualize-ms-dtor.cpp b/test/CodeGenCXX/devirtualize-ms-dtor.cpp new file mode 100644 index 0000000000..d999b0c2dc --- /dev/null +++ b/test/CodeGenCXX/devirtualize-ms-dtor.cpp @@ -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@XZ" +// CHECK: ret void -- 2.40.0