Skip to content

Commit 2c17dff

Browse files
authored
Merge pull request #8584 from vedantk/swift-3.1-branch
[Coverage] Audit uses of getCurrentCounter() (SR-4453)
2 parents 8245156 + 2c41a06 commit 2c17dff

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

lib/SILGen/SILGenProfiling.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ struct CoverageMapping : public ASTWalker {
661661
assignCounter(E);
662662
} else if (auto *IE = dyn_cast<IfExpr>(E)) {
663663
CounterExpr &ThenCounter = assignCounter(IE->getThenExpr());
664-
if (Parent.isNull())
664+
if (RegionStack.empty())
665665
assignCounter(IE->getElseExpr());
666666
else
667667
assignCounter(IE->getElseExpr(),

test/SILGen/coverage_toplevel.swift

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,40 @@ var i : Int32 = 0
1414
while (i < 10) {
1515
i += 1
1616
}
17+
18+
// CHECK: sil_coverage_map{{.*}}__tlcd_line:[[@LINE+3]]:1
19+
// CHECK-NEXT: [[@LINE+2]]:17 -> [[@LINE+2]]:18 : 1
20+
// CHECK-NEXT: [[@LINE+1]]:21 -> [[@LINE+1]]:22 : 0
21+
var i2 = true ? 1 : 0;
22+
23+
// CHECK: sil_coverage_map{{.*}}__tlcd_line:[[@LINE+4]]:1
24+
// CHECK-NEXT: [[@LINE+3]]:11 -> [[@LINE+5]]:2 : 1
25+
// CHECK-NEXT: [[@LINE+2]]:1 -> [[@LINE+4]]:2 : 0
26+
// CHECK-NEXT: [[@LINE+3]]:2 -> [[@LINE+3]]:2 : 0
27+
if (true) {
28+
i2 = 2
29+
}
30+
31+
// Crash tests:
32+
33+
if (true) {
34+
i2 = 3
35+
} else {
36+
i2 = 4
37+
}
38+
39+
while (i2 > 0) {
40+
if (true) {
41+
i2 -= 1
42+
continue
43+
} else {
44+
i2 -= 1
45+
break
46+
}
47+
}
48+
49+
switch (1) {
50+
case 0: fallthrough
51+
case 1: break
52+
default: break
53+
}

0 commit comments

Comments
 (0)