Skip to content

Commit 4393552

Browse files
authored
[Profiler] Increment closure body count prior to the prolog (#33946)
This fixes a 'SILBuilder has no valid insertion point' assertion failure seen when compiling various projects from the source compat suite. rdar://68759819
1 parent 581f611 commit 4393552

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/SILGen/SILGenFunction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,10 +524,10 @@ void SILGenFunction::emitClosure(AbstractClosureExpr *ace) {
524524
auto resultIfaceTy = ace->getResultType()->mapTypeOutOfContext();
525525
auto captureInfo = SGM.M.Types.getLoweredLocalCaptures(
526526
SILDeclRef(ace));
527+
emitProfilerIncrement(ace);
527528
emitProlog(captureInfo, ace->getParameters(), /*selfParam=*/nullptr,
528529
ace, resultIfaceTy, ace->isBodyThrowing(), ace->getLoc());
529530
prepareEpilog(true, ace->isBodyThrowing(), CleanupLocation(ace));
530-
emitProfilerIncrement(ace);
531531
if (auto *ce = dyn_cast<ClosureExpr>(ace)) {
532532
emitStmt(ce->getBody());
533533
} else {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %target-swift-frontend -Xllvm -sil-full-demangle -profile-generate -profile-coverage-mapping -emit-sil -module-name coverage_closure_returns_never %s | %FileCheck %s
2+
3+
// CHECK-LABEL: closure #1 (Swift.Never) -> Swift.Never in coverage_closure_returns_never.closure_with_fatal_error(Swift.Array<Swift.Never>) -> ()
4+
// CHECK: builtin "int_instrprof_increment"
5+
// CHECK-NEXT: debug_value {{.*}} : $Never
6+
// CHECK-NEXT: unreachable
7+
8+
func closure_with_fatal_error(_ arr: [Never]) {
9+
// CHECK-LABEL: sil_coverage_map {{.*}}// closure #1 (Swift.Never) -> Swift.Never
10+
// CHECK-NEXT: [[@LINE+1]]:11 -> [[@LINE+3]]:4
11+
arr.map {
12+
_ in fatalError()
13+
}
14+
}

0 commit comments

Comments
 (0)