Files
swift-mirror/test/Profiler/coverage_class.swift
Vedant Kumar 6d467fd31f [SILProfiler] Don't crash when coverage info for lazy getters is incomplete (#18744)
ASTWalker visits a lazy_initializer_expr once within its associated
var_decl (by way of the parent nominal type). However, SILGen visits the
lazy_initializer_expr while inside of the var_decl's getter. The result
is that there is no coverage mapping information for the contents of the
lazy init within the getter's SILProfiler.

Fixing this will require reworking how profile counters are assigned to
be more in line with what SILGen needs.

As a stop-gap, this patch prevents SILGen from asserting that coverage
mappings are complete with a defensive check which prevents a crash seen
in SR-8429.

rdar://42792053
2018-08-15 17:48:21 -07:00

50 lines
1.5 KiB
Swift

// RUN: %target-swift-frontend -Xllvm -sil-full-demangle -profile-generate -profile-coverage-mapping -emit-sil -module-name coverage_class %s | %FileCheck %s
class C {
// CHECK-LABEL: sil_coverage_map {{.*}}// coverage_class.C.foo
func foo() {}
// CHECK: sil_coverage_map {{.*}}// __ntd_C_line:[[@LINE-3]]:1
// CHECK-NEXT: [[@LINE+1]]:10 -> [[@LINE+1]]:12
init() {}
// CHECK-LABEL: sil_coverage_map {{.*}}// coverage_class.C.__deallocating_deinit
deinit {}
}
extension C {
// CHECK-LABEL: sil_coverage_map {{.*}}// coverage_class.C.bar
func bar() {}
}
struct S {
// CHECK-LABEL: sil_coverage_map {{.*}}// coverage_class.S.foo
func foo() {}
// CHECK: sil_coverage_map {{.*}}// __ntd_S_line:[[@LINE-3]]:1
init() {}
}
enum E {
case X, Y, Z
// CHECK-LABEL: sil_coverage_map {{.*}}// coverage_class.E.foo
func foo() {}
// CHECK: sil_coverage_map {{.*}}// __ntd_E_line:[[@LINE-4]]:1
// CHECK-NEXT: [[@LINE+1]]:10 -> [[@LINE+1]]:23
init() { self = .Y }
}
var g1: Bool = true
struct S2 {
// CHECK: sil_coverage_map {{.*}}// __ntd_S2_line:[[@LINE-1]]:1
// CHECK-NEXT: [[@LINE+2]]:22 -> [[@LINE+2]]:23 : 0
// CHECK-NEXT: [[@LINE+1]]:26 -> [[@LINE+1]]:27 : (1 - 0)
var m1: Int = g1 ? 0 : 1
}
// Test that the crash from SR-8429 is avoided. Follow-up work is
// needed to generate the correct coverage mapping here. Coverage for
// `offset` should be associated with its getter, not the class
// constructor.
class C2 {
lazy var offset: Int = true ? 30 : 55
}