fork/rust

git clone https://git.julia.blue/fork/rust

borsAuto merge of #103046 - JanBeh:PR_clarify_cmp_terminology, r=workingjubilee3bcad65fbf6

master
1.6 KiB38 linesraw
1   LL|       |#![feature(core_intrinsics)]
2   LL|       |#![feature(coverage_attribute)]
3   LL|       |// compile-flags: --edition=2021
4   LL|       |
5   LL|       |// <https://github.com/rust-lang/rust/issues/116171>
6   LL|       |// If we instrument a function for coverage, but all of its counter-increment
7   LL|       |// statements are removed by MIR optimizations, LLVM will think it isn't
8   LL|       |// instrumented and it will disappear from coverage maps and coverage reports.
9   LL|       |// Most MIR opts won't cause this because they tend not to remove statements
10   LL|       |// from bb0, but `UnreachablePropagation` can do so if it sees that bb0 ends
11   LL|       |// with `TerminatorKind::Unreachable`.
12   LL|       |
13   LL|       |use std::hint::{black_box, unreachable_unchecked};
14   LL|       |
15   LL|      0|static UNREACHABLE_CLOSURE: fn() = || unsafe { unreachable_unchecked() };
16   LL|       |
17   LL|      0|fn unreachable_function() {
18   LL|      0|    unsafe { unreachable_unchecked() }
19   LL|      0|}
20   LL|       |
21   LL|       |// Use an intrinsic to more reliably trigger unreachable-propagation.
22   LL|      0|fn unreachable_intrinsic() {
23   LL|      0|    unsafe { std::intrinsics::unreachable() }
24   LL|      0|}
25   LL|       |
26   LL|       |#[coverage(off)]
27   LL|       |fn main() {
28   LL|       |    if black_box(false) {
29   LL|       |        UNREACHABLE_CLOSURE();
30   LL|       |    }
31   LL|       |    if black_box(false) {
32   LL|       |        unreachable_function();
33   LL|       |    }
34   LL|       |    if black_box(false) {
35   LL|       |        unreachable_intrinsic();
36   LL|       |    }
37   LL|       |}
38