Skip to content

Commit 31d63a3

Browse files
authored
Merge pull request #30039 from vedantk/master
2 parents 059f1de + 5fe5fcc commit 31d63a3

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

lib/SIL/SILProfiler.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,10 +1076,14 @@ struct CoverageMapping : public ASTWalker {
10761076
pushRegion(E);
10771077
}
10781078

1079-
if (auto *IE = dyn_cast<IfExpr>(E)) {
1080-
CounterExpr &ThenCounter = assignCounter(IE->getThenExpr());
1081-
assignCounter(IE->getElseExpr(),
1082-
CounterExpr::Sub(getCurrentCounter(), ThenCounter));
1079+
// If there isn't an active region, we may be visiting a default
1080+
// initializer for a function argument.
1081+
if (!RegionStack.empty()) {
1082+
if (auto *IE = dyn_cast<IfExpr>(E)) {
1083+
CounterExpr &ThenCounter = assignCounter(IE->getThenExpr());
1084+
assignCounter(IE->getElseExpr(),
1085+
CounterExpr::Sub(getCurrentCounter(), ThenCounter));
1086+
}
10831087
}
10841088

10851089
if (hasCounter(E) && !Parent.isNull())
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: %target-swift-frontend -Xllvm -sil-full-demangle -profile-generate -profile-coverage-mapping -emit-sorted-sil -emit-sil -module-name coverage_arg_ternary %s | %FileCheck %s
2+
3+
var s: String?
4+
5+
// CHECK: sil_coverage_map {{.*}} "$s20coverage_arg_ternary1f0B0ySSSg_tF"
6+
// CHECK-NEXT: [[@LINE+2]]:43 -> [[@LINE+2]]:45 : 0
7+
// CHECK-NEXT: }
8+
func f(arg: String? = s != nil ? s : nil) {}

0 commit comments

Comments
 (0)