mirror of
https://github.com/allankoechke/rust.git
synced 2026-12-01 09:32:15 +00:00
Instead of trying to heuristically recover source-code spans from MIR soup, we can now take advantage of the `CoverageKind::Point` statements injected for specific HIR expressions. This is a transitional implementation that lets us remove the old MIR-soup code, but still relies heavily on the existing span-refinement heuristics, and does not take advantage of the full possibilities of HIR-aware coverage instrumentation. In order to avoid annoying never-executed spans in code that contains assertions, a heuristic has been added that ignores any expression within the arguments of a macro-expanded function call that returns `!`. Some coverage tests now require `//@ min-llvm-version: 23`, due to changes in how LLVM sorts the coverage mapping entries.
114 lines
3.2 KiB
Plaintext
114 lines
3.2 KiB
Plaintext
LL| |#![feature(coverage_attribute)]
|
|
LL| |//@ edition: 2021
|
|
LL| |//@ compile-flags: -Zcoverage-options=branch
|
|
LL| |//@ llvm-cov-flags: --show-branches=count
|
|
LL| |
|
|
LL| |macro_rules! no_merge {
|
|
LL| | () => {
|
|
LL| | for _ in 0..1 {}
|
|
LL| | };
|
|
LL| |}
|
|
LL| |
|
|
LL| 3|fn branch_not(a: bool) {
|
|
LL| 3| no_merge!();
|
|
LL| |
|
|
LL| 3| if a {
|
|
------------------
|
|
| Branch (LL:8): [True: 2, False: 1]
|
|
------------------
|
|
LL| 2| say("a")
|
|
LL| 1| }
|
|
LL| 3| if !a {
|
|
------------------
|
|
| Branch (LL:8): [True: 1, False: 2]
|
|
------------------
|
|
LL| 1| say("not a");
|
|
LL| 2| }
|
|
LL| 3| if !!a {
|
|
------------------
|
|
| Branch (LL:8): [True: 2, False: 1]
|
|
------------------
|
|
LL| 2| say("not not a");
|
|
LL| 1| }
|
|
LL| 3| if !!!a {
|
|
------------------
|
|
| Branch (LL:8): [True: 1, False: 2]
|
|
------------------
|
|
LL| 1| say("not not not a");
|
|
LL| 2| }
|
|
LL| 3|}
|
|
LL| |
|
|
LL| 3|fn branch_not_as(a: bool) {
|
|
LL| 3| no_merge!();
|
|
LL| |
|
|
LL| 3| if !(a as bool) {
|
|
------------------
|
|
| Branch (LL:8): [True: 1, False: 2]
|
|
------------------
|
|
LL| 1| say("not (a as bool)");
|
|
LL| 2| }
|
|
LL| 3| if !!(a as bool) {
|
|
------------------
|
|
| Branch (LL:8): [True: 2, False: 1]
|
|
------------------
|
|
LL| 2| say("not not (a as bool)");
|
|
LL| 1| }
|
|
LL| 3| if !!!(a as bool) {
|
|
------------------
|
|
| Branch (LL:8): [True: 1, False: 2]
|
|
------------------
|
|
LL| 1| say("not not (a as bool)");
|
|
LL| 2| }
|
|
LL| 3|}
|
|
LL| |
|
|
LL| 15|fn branch_and(a: bool, b: bool) {
|
|
LL| 15| no_merge!();
|
|
LL| |
|
|
LL| 15| if a && b {
|
|
^12
|
|
------------------
|
|
| Branch (LL:8): [True: 12, False: 3]
|
|
| Branch (LL:13): [True: 8, False: 4]
|
|
------------------
|
|
LL| 8| say("both");
|
|
LL| | } else {
|
|
LL| 7| say("not both");
|
|
LL| | }
|
|
LL| 15|}
|
|
LL| |
|
|
LL| 15|fn branch_or(a: bool, b: bool) {
|
|
LL| 15| no_merge!();
|
|
LL| |
|
|
LL| 15| if a || b {
|
|
^3
|
|
------------------
|
|
| Branch (LL:8): [True: 12, False: 3]
|
|
| Branch (LL:13): [True: 2, False: 1]
|
|
------------------
|
|
LL| 14| say("either");
|
|
LL| | } else {
|
|
LL| 1| say("neither");
|
|
LL| | }
|
|
LL| 15|}
|
|
LL| |
|
|
LL| |#[coverage(off)]
|
|
LL| |fn say(message: &str) {
|
|
LL| | core::hint::black_box(message);
|
|
LL| |}
|
|
LL| |
|
|
LL| |#[coverage(off)]
|
|
LL| |fn main() {
|
|
LL| | for a in [false, true, true] {
|
|
LL| | branch_not(a);
|
|
LL| | branch_not_as(a);
|
|
LL| | }
|
|
LL| |
|
|
LL| | for a in [false, true, true, true, true] {
|
|
LL| | for b in [false, true, true] {
|
|
LL| | branch_and(a, b);
|
|
LL| | branch_or(a, b);
|
|
LL| | }
|
|
LL| | }
|
|
LL| |}
|
|
|