diff --git a/tests/coverage/branch.cov-map b/tests/coverage/branch.cov-map new file mode 100644 index 0000000000000..57ce9c8783a02 --- /dev/null +++ b/tests/coverage/branch.cov-map @@ -0,0 +1,127 @@ +Function name: branch::if_and +Raw bytes (77): 0x[01, 01, 0b, 01, 05, 05, 02, 2b, 09, 05, 02, 0d, 26, 2b, 09, 05, 02, 11, 23, 0d, 26, 2b, 09, 05, 02, 09, 20, 05, 02, 06, 10, 00, 14, 01, 10, 01, 01, 23, 2b, 04, 09, 00, 0a, 20, 09, 26, 00, 09, 00, 0a, 09, 02, 09, 00, 0a, 20, 11, 0d, 00, 09, 00, 0a, 11, 01, 05, 02, 06, 23, 02, 0c, 02, 06, 1f, 03, 01, 00, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 11 +- expression 0 operands: lhs = Counter(0), rhs = Counter(1) +- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub) +- expression 2 operands: lhs = Expression(10, Add), rhs = Counter(2) +- expression 3 operands: lhs = Counter(1), rhs = Expression(0, Sub) +- expression 4 operands: lhs = Counter(3), rhs = Expression(9, Sub) +- expression 5 operands: lhs = Expression(10, Add), rhs = Counter(2) +- expression 6 operands: lhs = Counter(1), rhs = Expression(0, Sub) +- expression 7 operands: lhs = Counter(4), rhs = Expression(8, Add) +- expression 8 operands: lhs = Counter(3), rhs = Expression(9, Sub) +- expression 9 operands: lhs = Expression(10, Add), rhs = Counter(2) +- expression 10 operands: lhs = Counter(1), rhs = Expression(0, Sub) +Number of file 0 mappings: 9 +- Branch { true: Counter(1), false: Expression(0, Sub) } at (prev + 6, 16) to (start + 0, 20) + true = c1 + false = (c0 - c1) +- Code(Counter(0)) at (prev + 16, 1) to (start + 1, 35) +- Code(Expression(10, Add)) at (prev + 4, 9) to (start + 0, 10) + = (c1 + (c0 - c1)) +- Branch { true: Counter(2), false: Expression(9, Sub) } at (prev + 0, 9) to (start + 0, 10) + true = c2 + false = ((c1 + (c0 - c1)) - c2) +- Code(Counter(2)) at (prev + 2, 9) to (start + 0, 10) +- Branch { true: Counter(4), false: Counter(3) } at (prev + 0, 9) to (start + 0, 10) + true = c4 + false = c3 +- Code(Counter(4)) at (prev + 1, 5) to (start + 2, 6) +- Code(Expression(8, Add)) at (prev + 2, 12) to (start + 2, 6) + = (c3 + ((c1 + (c0 - c1)) - c2)) +- Code(Expression(7, Add)) at (prev + 3, 1) to (start + 0, 2) + = (c4 + (c3 + ((c1 + (c0 - c1)) - c2))) + +Function name: branch::if_let +Raw bytes (50): 0x[01, 01, 07, 01, 05, 05, 02, 1b, 09, 05, 02, 09, 16, 1b, 09, 05, 02, 06, 20, 05, 02, 06, 10, 00, 14, 01, 2c, 01, 01, 23, 1b, 07, 09, 00, 0d, 09, 01, 05, 02, 06, 16, 02, 0c, 02, 06, 13, 03, 01, 00, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 7 +- expression 0 operands: lhs = Counter(0), rhs = Counter(1) +- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub) +- expression 2 operands: lhs = Expression(6, Add), rhs = Counter(2) +- expression 3 operands: lhs = Counter(1), rhs = Expression(0, Sub) +- expression 4 operands: lhs = Counter(2), rhs = Expression(5, Sub) +- expression 5 operands: lhs = Expression(6, Add), rhs = Counter(2) +- expression 6 operands: lhs = Counter(1), rhs = Expression(0, Sub) +Number of file 0 mappings: 6 +- Branch { true: Counter(1), false: Expression(0, Sub) } at (prev + 6, 16) to (start + 0, 20) + true = c1 + false = (c0 - c1) +- Code(Counter(0)) at (prev + 44, 1) to (start + 1, 35) +- Code(Expression(6, Add)) at (prev + 7, 9) to (start + 0, 13) + = (c1 + (c0 - c1)) +- Code(Counter(2)) at (prev + 1, 5) to (start + 2, 6) +- Code(Expression(5, Sub)) at (prev + 2, 12) to (start + 2, 6) + = ((c1 + (c0 - c1)) - c2) +- Code(Expression(4, Add)) at (prev + 3, 1) to (start + 0, 2) + = (c2 + ((c1 + (c0 - c1)) - c2)) + +Function name: branch::if_not +Raw bytes (61): 0x[01, 01, 09, 01, 05, 05, 02, 23, 09, 05, 02, 23, 09, 05, 02, 09, 1e, 23, 09, 05, 02, 07, 20, 05, 02, 06, 10, 00, 14, 01, 03, 01, 01, 23, 23, 05, 09, 00, 0d, 20, 09, 1e, 00, 09, 00, 0d, 1e, 01, 05, 02, 06, 09, 02, 0c, 02, 06, 1b, 03, 01, 00, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 9 +- expression 0 operands: lhs = Counter(0), rhs = Counter(1) +- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub) +- expression 2 operands: lhs = Expression(8, Add), rhs = Counter(2) +- expression 3 operands: lhs = Counter(1), rhs = Expression(0, Sub) +- expression 4 operands: lhs = Expression(8, Add), rhs = Counter(2) +- expression 5 operands: lhs = Counter(1), rhs = Expression(0, Sub) +- expression 6 operands: lhs = Counter(2), rhs = Expression(7, Sub) +- expression 7 operands: lhs = Expression(8, Add), rhs = Counter(2) +- expression 8 operands: lhs = Counter(1), rhs = Expression(0, Sub) +Number of file 0 mappings: 7 +- Branch { true: Counter(1), false: Expression(0, Sub) } at (prev + 6, 16) to (start + 0, 20) + true = c1 + false = (c0 - c1) +- Code(Counter(0)) at (prev + 3, 1) to (start + 1, 35) +- Code(Expression(8, Add)) at (prev + 5, 9) to (start + 0, 13) + = (c1 + (c0 - c1)) +- Branch { true: Counter(2), false: Expression(7, Sub) } at (prev + 0, 9) to (start + 0, 13) + true = c2 + false = ((c1 + (c0 - c1)) - c2) +- Code(Expression(7, Sub)) at (prev + 1, 5) to (start + 2, 6) + = ((c1 + (c0 - c1)) - c2) +- Code(Counter(2)) at (prev + 2, 12) to (start + 2, 6) +- Code(Expression(6, Add)) at (prev + 3, 1) to (start + 0, 2) + = (c2 + ((c1 + (c0 - c1)) - c2)) + +Function name: branch::if_or +Raw bytes (75): 0x[01, 01, 0a, 01, 05, 05, 02, 17, 09, 05, 02, 17, 09, 05, 02, 09, 0d, 09, 0d, 27, 11, 09, 0d, 09, 20, 05, 02, 06, 10, 00, 14, 01, 1e, 01, 01, 23, 17, 04, 09, 00, 0a, 20, 09, 12, 00, 09, 00, 0a, 12, 02, 09, 00, 0a, 20, 27, 11, 00, 09, 00, 0a, 27, 01, 05, 02, 06, 11, 02, 0c, 02, 06, 23, 03, 01, 00, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 10 +- expression 0 operands: lhs = Counter(0), rhs = Counter(1) +- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub) +- expression 2 operands: lhs = Expression(5, Add), rhs = Counter(2) +- expression 3 operands: lhs = Counter(1), rhs = Expression(0, Sub) +- expression 4 operands: lhs = Expression(5, Add), rhs = Counter(2) +- expression 5 operands: lhs = Counter(1), rhs = Expression(0, Sub) +- expression 6 operands: lhs = Counter(2), rhs = Counter(3) +- expression 7 operands: lhs = Counter(2), rhs = Counter(3) +- expression 8 operands: lhs = Expression(9, Add), rhs = Counter(4) +- expression 9 operands: lhs = Counter(2), rhs = Counter(3) +Number of file 0 mappings: 9 +- Branch { true: Counter(1), false: Expression(0, Sub) } at (prev + 6, 16) to (start + 0, 20) + true = c1 + false = (c0 - c1) +- Code(Counter(0)) at (prev + 30, 1) to (start + 1, 35) +- Code(Expression(5, Add)) at (prev + 4, 9) to (start + 0, 10) + = (c1 + (c0 - c1)) +- Branch { true: Counter(2), false: Expression(4, Sub) } at (prev + 0, 9) to (start + 0, 10) + true = c2 + false = ((c1 + (c0 - c1)) - c2) +- Code(Expression(4, Sub)) at (prev + 2, 9) to (start + 0, 10) + = ((c1 + (c0 - c1)) - c2) +- Branch { true: Expression(9, Add), false: Counter(4) } at (prev + 0, 9) to (start + 0, 10) + true = (c2 + c3) + false = c4 +- Code(Expression(9, Add)) at (prev + 1, 5) to (start + 2, 6) + = (c2 + c3) +- Code(Counter(4)) at (prev + 2, 12) to (start + 2, 6) +- Code(Expression(8, Add)) at (prev + 3, 1) to (start + 0, 2) + = ((c2 + c3) + c4) + diff --git a/tests/coverage/branch.coverage b/tests/coverage/branch.coverage new file mode 100644 index 0000000000000..7fb9d8025face --- /dev/null +++ b/tests/coverage/branch.coverage @@ -0,0 +1,120 @@ + LL| |#![feature(coverage_attribute)] + LL| |// edition: 2021 + LL| |// compile-flags: -Zunstable-options -Cinstrument-coverage=branch + LL| | + LL| |macro_rules! do_not_merge_with_signature { + LL| | () => { if true {} else {} }; + ------------------ + | Branch (LL:16): [True: 15, False: 0] + ------------------ + | Branch (LL:16): [True: 15, False: 0] + ------------------ + | Branch (LL:16): [True: 15, False: 0] + ------------------ + | Branch (LL:16): [True: 15, False: 0] + ------------------ + LL| |} + LL| | + LL| 15|fn if_not(cond: bool) { + LL| 15| do_not_merge_with_signature!(); + LL| | + LL| | if + LL| | ! + LL| 15| cond + ------------------ + | Branch (LL:9): [True: 10, False: 5] + ------------------ + LL| 5| { + LL| 5| println!("cond was false"); + LL| 10| } else { + LL| 10| println!("cond was true"); + LL| 10| } + LL| 15|} + LL| | + LL| 15|fn if_and(a: bool, b: bool) { + LL| 15| do_not_merge_with_signature!(); + LL| | + LL| | if + LL| 15| a + ------------------ + | Branch (LL:9): [True: 12, False: 3] + ------------------ + LL| | && + LL| 12| b + ------------------ + | Branch (LL:9): [True: 8, False: 4] + ------------------ + LL| 8| { + LL| 8| println!("both"); + LL| 8| } else { + LL| 7| println!("not both"); + LL| 7| } + LL| 15|} + LL| | + LL| 15|fn if_or(a: bool, b: bool) { + LL| 15| do_not_merge_with_signature!(); + LL| | + LL| | if + LL| 15| a + ------------------ + | Branch (LL:9): [True: 12, False: 3] + ------------------ + LL| | || + LL| 3| b + ------------------ + | Branch (LL:9): [True: 14, False: 1] + ------------------ + LL| 14| { + LL| 14| println!("either"); + LL| 14| } else { + LL| 1| println!("neither"); + LL| 1| } + LL| 15|} + LL| | + LL| 15|fn if_let(cond: bool) { + LL| 15| do_not_merge_with_signature!(); + LL| | + LL| | if + LL| | let + LL| | true + LL| | = + LL| 15| cond + LL| 10| { + LL| 10| println!("true"); + LL| 10| } else { + LL| 5| println!("false"); + LL| 5| } + LL| 15|} + LL| | + LL| |#[coverage(off)] + LL| |fn main() { + LL| | let truthy = std::hint::black_box(true); + LL| | let falsy = std::hint::black_box(false); + LL| | + LL| | for _ in 0..10 { + LL| | if_not(truthy); + LL| | if_let(truthy); + LL| | } + LL| | for _ in 0..5 { + LL| | if_not(falsy); + LL| | if_let(falsy); + LL| | } + LL| | + LL| | for _ in 0..8 { + LL| | if_and(truthy, truthy); + LL| | if_or(truthy, truthy); + LL| | } + LL| | for _ in 0..4 { + LL| | if_and(truthy, falsy); + LL| | if_or(truthy, falsy); + LL| | } + LL| | for _ in 0..2 { + LL| | if_and(falsy, truthy); + LL| | if_or(falsy, truthy); + LL| | } + LL| | for _ in 0..1 { + LL| | if_and(falsy, falsy); + LL| | if_or(falsy, falsy); + LL| | } + LL| |} + diff --git a/tests/coverage/branch.rs b/tests/coverage/branch.rs new file mode 100644 index 0000000000000..e45bbd581835c --- /dev/null +++ b/tests/coverage/branch.rs @@ -0,0 +1,95 @@ +#![feature(coverage_attribute)] +// edition: 2021 +// compile-flags: -Zunstable-options -Cinstrument-coverage=branch + +macro_rules! do_not_merge_with_signature { + () => { if true {} else {} }; +} + +fn if_not(cond: bool) { + do_not_merge_with_signature!(); + + if + ! + cond + { + println!("cond was false"); + } else { + println!("cond was true"); + } +} + +fn if_and(a: bool, b: bool) { + do_not_merge_with_signature!(); + + if + a + && + b + { + println!("both"); + } else { + println!("not both"); + } +} + +fn if_or(a: bool, b: bool) { + do_not_merge_with_signature!(); + + if + a + || + b + { + println!("either"); + } else { + println!("neither"); + } +} + +fn if_let(cond: bool) { + do_not_merge_with_signature!(); + + if + let + true + = + cond + { + println!("true"); + } else { + println!("false"); + } +} + +#[coverage(off)] +fn main() { + let truthy = std::hint::black_box(true); + let falsy = std::hint::black_box(false); + + for _ in 0..10 { + if_not(truthy); + if_let(truthy); + } + for _ in 0..5 { + if_not(falsy); + if_let(falsy); + } + + for _ in 0..8 { + if_and(truthy, truthy); + if_or(truthy, truthy); + } + for _ in 0..4 { + if_and(truthy, falsy); + if_or(truthy, falsy); + } + for _ in 0..2 { + if_and(falsy, truthy); + if_or(falsy, truthy); + } + for _ in 0..1 { + if_and(falsy, falsy); + if_or(falsy, falsy); + } +}