|
| 1 | +// RUN: %empty-directory(%t) |
| 2 | + |
| 3 | +// rdar://77217762 – The increment_profiler_counter in $foo gets optimized out by |
| 4 | +// LLVM function optimization, but make sure we still emit the name data which |
| 5 | +// is required by the coverage record. |
| 6 | + |
| 7 | +// Make sure both the legacy and new pass manager work. |
| 8 | +// We need to disable SIL optimizations to ensure LLVM optimizes out the |
| 9 | +// profiler increment. |
| 10 | +// RUN: %target-build-swift %s -profile-generate -profile-coverage-mapping -O -Xfrontend -disable-sil-perf-optzns -Xfrontend -disable-new-llvm-pass-manager -o %t/main1 |
| 11 | +// RUN: %target-build-swift %s -profile-generate -profile-coverage-mapping -O -Xfrontend -disable-sil-perf-optzns -Xfrontend -enable-new-llvm-pass-manager -o %t/main2 |
| 12 | + |
| 13 | +// This unusual use of 'sh' allows the path of the profraw file to be |
| 14 | +// substituted by %target-run. |
| 15 | +// RUN: %target-codesign %t/main1 |
| 16 | +// RUN: %target-codesign %t/main2 |
| 17 | +// RUN: %target-run sh -c 'env LLVM_PROFILE_FILE=$1 $2' -- %t/default1.profraw %t/main1 |
| 18 | +// RUN: %target-run sh -c 'env LLVM_PROFILE_FILE=$1 $2' -- %t/default2.profraw %t/main2 |
| 19 | + |
| 20 | +// RUN: %llvm-profdata merge %t/default1.profraw -o %t/default1.profdata |
| 21 | +// RUN: %llvm-profdata merge %t/default2.profraw -o %t/default2.profdata |
| 22 | + |
| 23 | +// RUN: %llvm-cov report %t/main1 -instr-profile=%t/default1.profdata |
| 24 | +// RUN: %llvm-cov report %t/main2 -instr-profile=%t/default2.profdata |
| 25 | + |
| 26 | +// REQUIRES: profile_runtime |
| 27 | +// REQUIRES: executable_test |
| 28 | +// REQUIRES: OS=macosx |
| 29 | + |
| 30 | +sil_stage canonical |
| 31 | + |
| 32 | +import Swift |
| 33 | +import Builtin |
| 34 | + |
| 35 | +sil [ossa] @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 { |
| 36 | +bb0(%0 : $Int32, %1 : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>): |
| 37 | + increment_profiler_counter 0, "__tlcd_line:12:1", num_counters 1, hash 0 |
| 38 | + %3 = function_ref @$foo : $@convention(thin) () -> () |
| 39 | + %4 = apply %3() : $@convention(thin) () -> () |
| 40 | + %5 = integer_literal $Builtin.Int32, 0 |
| 41 | + %6 = struct $Int32 (%5 : $Builtin.Int32) |
| 42 | + return %6 : $Int32 |
| 43 | +} |
| 44 | + |
| 45 | +sil [ossa] @$foo : $@convention(thin) () -> () { |
| 46 | +bb0: |
| 47 | + %1 = integer_literal $Builtin.Int1, 0 |
| 48 | + cond_br %1, bb1, bb2 |
| 49 | + |
| 50 | +bb1: |
| 51 | + increment_profiler_counter 0, "$foo", num_counters 1, hash 0 |
| 52 | + br bb3 |
| 53 | + |
| 54 | +bb2: |
| 55 | + br bb3 |
| 56 | + |
| 57 | +bb3: |
| 58 | + %10 = tuple () |
| 59 | + return %10 : $() |
| 60 | +} |
| 61 | + |
| 62 | +sil_coverage_map "main.swift" "$foo" "$foo" 0 { |
| 63 | + 10:6 -> 10:11 : 0 |
| 64 | +} |
0 commit comments