diff options
author | Reid Kleckner <rnk@google.com> | 2018-03-16 22:20:57 +0000 |
---|---|---|
committer | Reid Kleckner <rnk@google.com> | 2018-03-16 22:20:57 +0000 |
commit | 281032584d3ca52a97cee0344c0218dd25727d55 (patch) | |
tree | 65eba5f62772c3f387eba95d20038d704bff0675 | |
parent | b6073eb6e1f781a61d6d3af17dfc845d4c8b6ac5 (diff) | |
download | bcm5719-llvm-281032584d3ca52a97cee0344c0218dd25727d55.tar.gz bcm5719-llvm-281032584d3ca52a97cee0344c0218dd25727d55.zip |
[MS] Fix bug in r327732 with devirtualized complete destructor calls
llvm-svn: 327754
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 10 | ||||
-rw-r--r-- | clang/test/CodeGenCXX/devirtualize-ms-dtor.cpp | 16 |
2 files changed, 26 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index e221b64d2ec..a47c1c649da 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/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<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(), diff --git a/clang/test/CodeGenCXX/devirtualize-ms-dtor.cpp b/clang/test/CodeGenCXX/devirtualize-ms-dtor.cpp new file mode 100644 index 00000000000..d999b0c2dc4 --- /dev/null +++ b/clang/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 |