Skip to content

Commit f9ef9f8

Browse files
committedFeb 26, 2019
[MS] Don't emit coverage for deleting dtors
Summary: The MS C++ ABI has no constructor variants, but it has destructor variants, so we should move the deleting destructor variant check outside the check for "does the ABI have constructor variants". Fixes PR37561, so basic code coverage works on Windows with C++. Reviewers: vsk Subscribers: jdoerfert, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D58691 llvm-svn: 354924
1 parent 721eaef commit f9ef9f8

File tree

2 files changed

+86
-3
lines changed

2 files changed

+86
-3
lines changed
 

‎clang/lib/CodeGen/CodeGenPGO.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -771,14 +771,14 @@ void CodeGenPGO::assignRegionCounters(GlobalDecl GD, llvm::Function *Fn) {
771771
// If so, instrument only base variant, others are implemented by delegation
772772
// to the base one, it would be counted twice otherwise.
773773
if (CGM.getTarget().getCXXABI().hasConstructorVariants()) {
774-
if (isa<CXXDestructorDecl>(D) && GD.getDtorType() != Dtor_Base)
775-
return;
776-
777774
if (const auto *CCD = dyn_cast<CXXConstructorDecl>(D))
778775
if (GD.getCtorType() != Ctor_Base &&
779776
CodeGenFunction::IsConstructorDelegationValid(CCD))
780777
return;
781778
}
779+
if (isa<CXXDestructorDecl>(D) && GD.getDtorType() != Dtor_Base)
780+
return;
781+
782782
CGM.ClearUnusedCoverageMapping(D);
783783
setFuncName(Fn);
784784

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// RUN: %clang_cc1 -emit-llvm %s -std=c++11 -o - -fno-rtti \
2+
// RUN: -fprofile-instrument=clang -fcoverage-mapping -disable-llvm-passes \
3+
// RUN: -triple=x86_64-windows-msvc | FileCheck %s --check-prefix=MSVC
4+
// RUN: %clang_cc1 -emit-llvm %s -std=c++11 -o - -fno-rtti \
5+
// RUN: -fprofile-instrument=clang -fcoverage-mapping -disable-llvm-passes \
6+
// RUN: -triple=x86_64-linux-gnu | FileCheck %s --check-prefix=LINUX
7+
8+
// Check that clang doesn't emit counters or __profn_ variables for deleting
9+
// destructor variants in both C++ ABIs.
10+
11+
struct ABC {
12+
virtual ~ABC() = default;
13+
virtual void pure() = 0;
14+
};
15+
struct DerivedABC : ABC {
16+
~DerivedABC() override = default;
17+
void pure() override {}
18+
};
19+
DerivedABC *useABCVTable() { return new DerivedABC(); }
20+
21+
// MSVC-NOT: @"__profn_??_G{{.*}}" =
22+
// MSVC: @"__profn_??1DerivedABC@@{{.*}}" =
23+
// MSVC-NOT: @"__profn_??_G{{.*}}" =
24+
// MSVC: @"__profn_??1ABC@@{{.*}}" =
25+
// MSVC-NOT: @"__profn_??_G{{.*}}" =
26+
27+
// MSVC-LABEL: define linkonce_odr dso_local i8* @"??_GDerivedABC@@UEAAPEAXI@Z"(%struct.DerivedABC* %this, {{.*}})
28+
// MSVC-NOT: call void @llvm.instrprof.increment({{.*}})
29+
// MSVC: call void @"??1DerivedABC@@UEAA@XZ"({{.*}})
30+
// MSVC: ret void
31+
32+
// MSVC-LABEL: define linkonce_odr dso_local i8* @"??_GABC@@UEAAPEAXI@Z"(%struct.ABC* %this, {{.*}})
33+
// MSVC-NOT: call void @llvm.instrprof.increment({{.*}})
34+
// MSVC: call void @llvm.trap()
35+
// MSVC-NEXT: unreachable
36+
37+
// MSVC-LABEL: define linkonce_odr dso_local void @"??1DerivedABC@@UEAA@XZ"({{.*}})
38+
// MSVC: call void @llvm.instrprof.increment({{.*}})
39+
// MSVC: call void @"??1ABC@@UEAA@XZ"({{.*}})
40+
// MSVC: ret void
41+
42+
// MSVC-LABEL: define linkonce_odr dso_local void @"??1ABC@@UEAA@XZ"({{.*}})
43+
// MSVC: call void @llvm.instrprof.increment({{.*}})
44+
// MSVC: ret void
45+
46+
47+
// D2 is the base, D1 and D0 are deleting and complete dtors.
48+
49+
// LINUX-NOT: @__profn_{{.*D[01]Ev}} =
50+
// LINUX: @__profn__ZN10DerivedABCD2Ev =
51+
// LINUX-NOT: @__profn_{{.*D[01]Ev}} =
52+
// LINUX: @__profn__ZN3ABCD2Ev =
53+
// LINUX-NOT: @__profn_{{.*D[01]Ev}} =
54+
55+
// LINUX-LABEL: define linkonce_odr void @_ZN10DerivedABCD1Ev(%struct.DerivedABC* %this)
56+
// LINUX-NOT: call void @llvm.instrprof.increment({{.*}})
57+
// LINUX: call void @_ZN10DerivedABCD2Ev({{.*}})
58+
// LINUX: ret void
59+
60+
// LINUX-LABEL: define linkonce_odr void @_ZN10DerivedABCD0Ev(%struct.DerivedABC* %this)
61+
// LINUX-NOT: call void @llvm.instrprof.increment({{.*}})
62+
// LINUX: call void @_ZN10DerivedABCD1Ev({{.*}})
63+
// LINUX: call void @_ZdlPv({{.*}})
64+
// LINUX: ret void
65+
66+
// LINUX-LABEL: define linkonce_odr void @_ZN3ABCD1Ev(%struct.ABC* %this)
67+
// LINUX-NOT: call void @llvm.instrprof.increment({{.*}})
68+
// LINUX: call void @llvm.trap()
69+
// LINUX-NEXT: unreachable
70+
71+
// LINUX-LABEL: define linkonce_odr void @_ZN3ABCD0Ev(%struct.ABC* %this)
72+
// LINUX-NOT: call void @llvm.instrprof.increment({{.*}})
73+
// LINUX: call void @llvm.trap()
74+
// LINUX-NEXT: unreachable
75+
76+
// LINUX-LABEL: define linkonce_odr void @_ZN10DerivedABCD2Ev(%struct.DerivedABC* %this)
77+
// LINUX: call void @llvm.instrprof.increment({{.*}})
78+
// LINUX: call void @_ZN3ABCD2Ev({{.*}})
79+
// LINUX: ret void
80+
81+
// LINUX-LABEL: define linkonce_odr void @_ZN3ABCD2Ev(%struct.ABC* %this)
82+
// LINUX: call void @llvm.instrprof.increment({{.*}})
83+
// LINUX: ret void

0 commit comments

Comments
 (0)
Please sign in to comment.