Skip to content

Commit a24adaf

Browse files
authored
Merge pull request #22798 from bob-wilson/sr-9654-5.0
[SILProfiler] Skip source regions with invalid locations
2 parents 62b8fa3 + 5f571c2 commit a24adaf

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

lib/SIL/SILProfiler.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ static bool doesClosureHaveBody(AbstractClosureExpr *ACE) {
4242

4343
/// Check whether a root AST node is unmapped, i.e not profiled.
4444
static bool isUnmapped(ASTNode N) {
45+
// Do not map AST nodes with invalid source locations.
46+
if (N.getStartLoc().isInvalid() || N.getEndLoc().isInvalid())
47+
return true;
48+
4549
if (auto *E = N.dyn_cast<Expr *>()) {
4650
auto *CE = dyn_cast<AbstractClosureExpr>(E);
4751

@@ -396,7 +400,12 @@ class SourceMappingRegion {
396400
public:
397401
SourceMappingRegion(ASTNode Node, CounterExpr &Count,
398402
Optional<SourceLoc> StartLoc, Optional<SourceLoc> EndLoc)
399-
: Node(Node), Count(&Count), StartLoc(StartLoc), EndLoc(EndLoc) {}
403+
: Node(Node), Count(&Count), StartLoc(StartLoc), EndLoc(EndLoc) {
404+
assert((!StartLoc || StartLoc->isValid()) &&
405+
"Expected start location to be valid");
406+
assert((!EndLoc || EndLoc->isValid()) &&
407+
"Expected start location to be valid");
408+
}
400409

401410
SourceMappingRegion(SourceMappingRegion &&Region) = default;
402411
SourceMappingRegion &operator=(SourceMappingRegion &&RHS) = default;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %target-swift-frontend -Xllvm -sil-full-demangle -enable-testing -profile-generate -profile-coverage-mapping -emit-sil -module-name coverage_subscript_autoclosure %s | %FileCheck %s
2+
3+
struct S {
4+
subscript(i: Int, autoclosure: @autoclosure () -> Int) -> Int {
5+
// CHECK-LABEL: sil_coverage_map {{.*}}S.subscript.getter
6+
get { // CHECK-NEXT: [[@LINE]]:9 -> [[@LINE+2]]:6 : 0
7+
return 0
8+
}
9+
10+
// CHECK-LABEL: sil_coverage_map {{.*}}S.subscript.setter
11+
set { // CHECK-NEXT: [[@LINE]]:9 -> [[@LINE+2]]:6 : 0
12+
13+
}
14+
}
15+
}

0 commit comments

Comments
 (0)