Files
swift-mirror/test/Profiler/coverage_pound_if_exec.swift
Hamish Knight 5aab237468 [Profiler] Emit skipped regions for inactive #if branches
For any `#if` blocks in the function we're emitting,
emit skipped ranges for the inactive clauses, including
the syntax for the `#if` itself, since that should
not be considered executable code.

rdar://116860865
2023-11-14 20:41:35 +00:00

130 lines
4.5 KiB
Swift

// RUN: %empty-directory(%t)
// RUN: %target-build-swift %s -profile-generate -profile-coverage-mapping -o %t/main
// This unusual use of 'sh' allows the path of the profraw file to be
// substituted by %target-run.
// RUN: %target-codesign %t/main
// RUN: %target-run sh -c 'env LLVM_PROFILE_FILE=$1 $2' -- %t/default.profraw %t/main
// RUN: %llvm-profdata merge %t/default.profraw -o %t/default.profdata
// RUN: %llvm-cov export -summary-only %t/main -instr-profile=%t/default.profdata | %FileCheck --check-prefix SUMMARY %s
// RUN: %llvm-cov show %t/main -instr-profile=%t/default.profdata | %FileCheck --implicit-check-not "{{[ ]*\|[ ]*[0-9]+}}" %s
// REQUIRES: profile_runtime
// REQUIRES: executable_test
// REQUIRES: OS=macosx
// The line count here excludes the inactive regions.
// SUMMARY: "lines":{"count":41,"covered":0
// This test works by marking active lines with the pattern. The implicit
// CHECK-NOT in the FileCheck invocation ensures everything else is a skipped
// region (or doesn't have any coverage mapping such as these comments).
func poundIfDecl() -> Int { // CHECK: [[@LINE]]{{[ ]*\|[ ]*[0-9]+}}
#if true
#if true
return 1 // CHECK: [[@LINE]]{{[ ]*\|[ ]*[0-9]+}}
#else
return 2
#endif
#else
#if true
return 3
#else
return 4
#endif
#endif
} // CHECK: [[@LINE]]{{[ ]*\|[ ]*[0-9]+}}
func poundIfMember(
_ x: [Int]
) -> [Int] { // CHECK: [[@LINE]]{{[ ]*\|[ ]*[0-9]+}}
return x // CHECK: [[@LINE]]{{[ ]*\|[ ]*[0-9]+}}
#if false
.map { $0 + 1 }
#endif
} // CHECK: [[@LINE]]{{[ ]*\|[ ]*[0-9]+}}
func poundIfAttr() -> Any { // CHECK: [[@LINE]]{{[ ]*\|[ ]*[0-9]+}}
#if false
@objc
#endif
class C {} // CHECK: [[@LINE]]{{[ ]*\|[ ]*[0-9]+}}
return C() // CHECK: [[@LINE]]{{[ ]*\|[ ]*[0-9]+}}
} // CHECK: [[@LINE]]{{[ ]*\|[ ]*[0-9]+}}
func poundIfSwitch(
_ x: Bool
) -> Int { // CHECK: [[@LINE]]{{[ ]*\|[ ]*[0-9]+}}
switch x { // CHECK: [[@LINE]]{{[ ]*\|[ ]*[0-9]+}}
#if true
case true: // CHECK: [[@LINE]]{{[ ]*\|[ ]*[0-9]+}}
return 0 // CHECK: [[@LINE]]{{[ ]*\|[ ]*[0-9]+}}
#else
case false:
return 0
#endif
#if false
case false:
return 1
#endif
case false: // CHECK: [[@LINE]]{{[ ]*\|[ ]*[0-9]+}}
return 0 // CHECK: [[@LINE]]{{[ ]*\|[ ]*[0-9]+}}
} // CHECK: [[@LINE]]{{[ ]*\|[ ]*[0-9]+}}
} // CHECK: [[@LINE]]{{[ ]*\|[ ]*[0-9]+}}
func poundIfMember() { // CHECK: [[@LINE]]{{[ ]*\|[ ]*[0-9]+}}
struct S { // CHECK: [[@LINE]]{{[ ]*\|[ ]*[0-9]+}}
#if false
var foo: Int
#else
var foo: Int // CHECK: [[@LINE]]{{[ ]*\|[ ]*[0-9]+}}
#endif
} // CHECK: [[@LINE]]{{[ ]*\|[ ]*[0-9]+}}
} // CHECK: [[@LINE]]{{[ ]*\|[ ]*[0-9]+}}
func poundIfDecl2() -> Int { // CHECK: [[@LINE]]{{[ ]*\|[ ]*[0-9]+}}
#if true
struct S { // CHECK: [[@LINE]]{{[ ]*\|[ ]*[0-9]+}}
var foo: Int // CHECK: [[@LINE]]{{[ ]*\|[ ]*[0-9]+}}
} // CHECK: [[@LINE]]{{[ ]*\|[ ]*[0-9]+}}
#else
struct S {
var foo: Int
}
#endif
return S(foo: 0).foo // CHECK: [[@LINE]]{{[ ]*\|[ ]*[0-9]+}}
} // CHECK: [[@LINE]]{{[ ]*\|[ ]*[0-9]+}}
func emptyPoundIf1(
) -> Int { // CHECK: [[@LINE]]{{[ ]*\|[ ]*[0-9]+}}
#if false
#endif
return 0 // CHECK: [[@LINE]]{{[ ]*\|[ ]*[0-9]+}}
} // CHECK: [[@LINE]]{{[ ]*\|[ ]*[0-9]+}}
func emptyPoundIf2(
) -> Int { // CHECK: [[@LINE]]{{[ ]*\|[ ]*[0-9]+}}
#if true
#endif
return 0 // CHECK: [[@LINE]]{{[ ]*\|[ ]*[0-9]+}}
} // CHECK: [[@LINE]]{{[ ]*\|[ ]*[0-9]+}}
func emptyPoundIf3(
) -> Int { // CHECK: [[@LINE]]{{[ ]*\|[ ]*[0-9]+}}
#if true
#else
#endif
return 0 // CHECK: [[@LINE]]{{[ ]*\|[ ]*[0-9]+}}
} // CHECK: [[@LINE]]{{[ ]*\|[ ]*[0-9]+}}
func poundEndIfSameLine(
) -> Int { // CHECK: [[@LINE]]{{[ ]*\|[ ]*[0-9]+}}
#if true
return 0 // CHECK: [[@LINE]]{{[ ]*\|[ ]*[0-9]+}}
#else
return 1#endif
} // CHECK: [[@LINE]]{{[ ]*\|[ ]*[0-9]+}}