Skip to content

Commit 2810325

Browse files
committedMar 16, 2018
[MS] Fix bug in r327732 with devirtualized complete destructor calls
llvm-svn: 327754
1 parent b6073eb commit 2810325

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
 

Diff for: ‎clang/lib/CodeGen/CodeGenModule.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -2550,6 +2550,16 @@ llvm::Constant *CodeGenModule::GetAddrOfFunction(GlobalDecl GD,
25502550
Ty = getTypes().ConvertFunctionType(CanonTy, FD);
25512551
}
25522552

2553+
// Devirtualized destructor calls may come through here instead of via
2554+
// getAddrOfCXXStructor. Make sure we use the MS ABI base destructor instead
2555+
// of the complete destructor when necessary.
2556+
if (const auto *DD = dyn_cast<CXXDestructorDecl>(GD.getDecl())) {
2557+
if (getTarget().getCXXABI().isMicrosoft() &&
2558+
GD.getDtorType() == Dtor_Complete &&
2559+
DD->getParent()->getNumVBases() == 0)
2560+
GD = GlobalDecl(DD, Dtor_Base);
2561+
}
2562+
25532563
StringRef MangledName = getMangledName(GD);
25542564
return GetOrCreateLLVMFunction(MangledName, Ty, GD, ForVTable, DontDefer,
25552565
/*IsThunk=*/false, llvm::AttributeList(),

Diff for: ‎clang/test/CodeGenCXX/devirtualize-ms-dtor.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %clang_cc1 -std=c++11 -triple x86_64-windows-msvc %s -emit-llvm -o - | FileCheck %s
2+
3+
// If we de-virtualize ~Foo, we still need to call ??1Foo, not ??_DFoo.
4+
5+
struct Base {
6+
virtual ~Base();
7+
};
8+
struct Foo final : Base {
9+
};
10+
void f(Foo *p) {
11+
p->~Foo();
12+
}
13+
14+
// CHECK-LABEL: define{{.*}} void @"?f@@YAXPEAUFoo@@@Z"(%struct.Foo* %p)
15+
// CHECK: call void @"??1Foo@@UEAA@XZ"
16+
// CHECK: ret void

0 commit comments

Comments
 (0)
Please sign in to comment.