diff --git a/compiler/rustc_mir_build/src/build/coverageinfo.rs b/compiler/rustc_mir_build/src/build/coverageinfo.rs index 95d72c02682fc..89ca1fb6fa323 100644 --- a/compiler/rustc_mir_build/src/build/coverageinfo.rs +++ b/compiler/rustc_mir_build/src/build/coverageinfo.rs @@ -38,6 +38,12 @@ struct NotInfo { is_flipped: bool, } +pub(crate) struct MatchArm { + pub(crate) source_info: SourceInfo, + pub(crate) pre_binding_block: Option, + pub(crate) arm_block: BasicBlock, +} + impl BranchInfoBuilder { /// Creates a new branch info builder, but only if branch coverage instrumentation /// is enabled and `def_id` represents a function that is eligible for coverage. @@ -152,6 +158,31 @@ impl BranchInfoBuilder { self.branch_arm_lists.push(vec![arm(true_marker), arm(false_marker)]); } + pub(crate) fn add_match_arms(&mut self, cfg: &mut CFG<'_>, arms: &[MatchArm]) { + // Match expressions with 0-1 arms don't have any branches for their arms. + if arms.len() < 2 { + return; + } + + // FIXME(#124118) The current implementation of branch coverage for + // match arms can't handle or-patterns. + if arms.iter().any(|arm| arm.pre_binding_block.is_none()) { + return; + } + + let branch_arms = arms + .iter() + .map(|&MatchArm { source_info, pre_binding_block, arm_block }| { + let pre_guard_marker = + self.inject_block_marker(cfg, source_info, pre_binding_block.unwrap()); + let arm_taken_marker = self.inject_block_marker(cfg, source_info, arm_block); + BranchArm { span: source_info.span, pre_guard_marker, arm_taken_marker } + }) + .collect::>(); + + self.branch_arm_lists.push(branch_arms); + } + fn next_block_marker_id(&mut self) -> BlockMarkerId { let id = BlockMarkerId::from_usize(self.num_block_markers); self.num_block_markers += 1; diff --git a/compiler/rustc_mir_build/src/build/matches/mod.rs b/compiler/rustc_mir_build/src/build/matches/mod.rs index f46dceeeedf58..a43b6b8f12aa6 100644 --- a/compiler/rustc_mir_build/src/build/matches/mod.rs +++ b/compiler/rustc_mir_build/src/build/matches/mod.rs @@ -5,6 +5,7 @@ //! This also includes code for pattern bindings in `let` statements and //! function parameters. +use crate::build::coverageinfo; use crate::build::expr::as_place::PlaceBuilder; use crate::build::scope::DropKind; use crate::build::ForGuard::{self, OutsideGuard, RefWithinGuard}; @@ -461,6 +462,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { outer_source_info: SourceInfo, fake_borrow_temps: Vec<(Place<'tcx>, Local)>, ) -> BlockAnd<()> { + let mut coverage_match_arms = self.coverage_branch_info.is_some().then_some(vec![]); + let arm_end_blocks: Vec<_> = arm_candidates .into_iter() .map(|(arm, candidate)| { @@ -495,6 +498,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { opt_scrutinee_place, ); + let pre_binding_block = candidate.pre_binding_block; + let arm_block = this.bind_pattern( outer_source_info, candidate, @@ -504,6 +509,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { false, ); + if let Some(coverage_match_arms) = coverage_match_arms.as_mut() { + coverage_match_arms.push(coverageinfo::MatchArm { + source_info: this.source_info(arm.pattern.span), + pre_binding_block, + arm_block, + }) + } + this.fixed_temps_scope = old_dedup_scope; if let Some(source_scope) = scope { @@ -515,6 +528,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { }) .collect(); + if let Some(coverage_match_arms) = coverage_match_arms { + self.coverage_branch_info + .as_mut() + .expect("checked when creating `coverage_match_arms`") + .add_match_arms(&mut self.cfg, &coverage_match_arms); + } + // all the arm blocks will rejoin here let end_block = self.cfg.start_new_block(); diff --git a/tests/coverage/branch/guard-simple.cov-map b/tests/coverage/branch/guard-simple.cov-map index 8eb9c54ff4bca..50654ae661afb 100644 --- a/tests/coverage/branch/guard-simple.cov-map +++ b/tests/coverage/branch/guard-simple.cov-map @@ -1,24 +1,35 @@ Function name: guard_simple::never_taken -Raw bytes (56): 0x[01, 01, 04, 01, 05, 11, 09, 0f, 0d, 05, 09, 08, 01, 08, 01, 02, 1e, 20, 05, 02, 02, 0e, 00, 1e, 05, 00, 22, 00, 24, 11, 01, 0e, 00, 1e, 20, 09, 06, 00, 0e, 00, 1e, 09, 00, 22, 00, 24, 0d, 01, 0e, 00, 10, 0b, 02, 01, 00, 02] +Raw bytes (80): 0x[01, 01, 09, 07, 01, 17, 05, 0d, 09, 01, 05, 17, 11, 0d, 09, 11, 09, 23, 0d, 05, 09, 0a, 01, 08, 01, 02, 1e, 20, 01, 02, 02, 09, 00, 0a, 20, 05, 0e, 00, 0e, 00, 1e, 05, 00, 22, 00, 24, 20, 11, 12, 01, 09, 00, 0a, 11, 00, 0e, 00, 1e, 20, 09, 1a, 00, 0e, 00, 1e, 09, 00, 22, 00, 24, 0d, 01, 0e, 00, 10, 1f, 02, 01, 00, 02] Number of files: 1 - file 0 => global file 1 -Number of expressions: 4 -- expression 0 operands: lhs = Counter(0), rhs = Counter(1) -- expression 1 operands: lhs = Counter(4), rhs = Counter(2) -- expression 2 operands: lhs = Expression(3, Add), rhs = Counter(3) -- expression 3 operands: lhs = Counter(1), rhs = Counter(2) -Number of file 0 mappings: 8 +Number of expressions: 9 +- expression 0 operands: lhs = Expression(1, Add), rhs = Counter(0) +- expression 1 operands: lhs = Expression(5, Add), rhs = Counter(1) +- expression 2 operands: lhs = Counter(3), rhs = Counter(2) +- expression 3 operands: lhs = Counter(0), rhs = Counter(1) +- expression 4 operands: lhs = Expression(5, Add), rhs = Counter(4) +- expression 5 operands: lhs = Counter(3), rhs = Counter(2) +- expression 6 operands: lhs = Counter(4), rhs = Counter(2) +- expression 7 operands: lhs = Expression(8, Add), rhs = Counter(3) +- expression 8 operands: lhs = Counter(1), rhs = Counter(2) +Number of file 0 mappings: 10 - Code(Counter(0)) at (prev + 8, 1) to (start + 2, 30) -- Branch { true: Counter(1), false: Expression(0, Sub) } at (prev + 2, 14) to (start + 0, 30) +- Branch { true: Counter(0), false: Expression(0, Sub) } at (prev + 2, 9) to (start + 0, 10) + true = c0 + false = (((c3 + c2) + c1) - c0) +- Branch { true: Counter(1), false: Expression(3, Sub) } at (prev + 0, 14) to (start + 0, 30) true = c1 false = (c0 - c1) - Code(Counter(1)) at (prev + 0, 34) to (start + 0, 36) -- Code(Counter(4)) at (prev + 1, 14) to (start + 0, 30) -- Branch { true: Counter(2), false: Expression(1, Sub) } at (prev + 0, 14) to (start + 0, 30) +- Branch { true: Counter(4), false: Expression(4, Sub) } at (prev + 1, 9) to (start + 0, 10) + true = c4 + false = ((c3 + c2) - c4) +- Code(Counter(4)) at (prev + 0, 14) to (start + 0, 30) +- Branch { true: Counter(2), false: Expression(6, Sub) } at (prev + 0, 14) to (start + 0, 30) true = c2 false = (c4 - c2) - Code(Counter(2)) at (prev + 0, 34) to (start + 0, 36) - Code(Counter(3)) at (prev + 1, 14) to (start + 0, 16) -- Code(Expression(2, Add)) at (prev + 2, 1) to (start + 0, 2) +- Code(Expression(7, Add)) at (prev + 2, 1) to (start + 0, 2) = ((c1 + c2) + c3) diff --git a/tests/coverage/branch/guard-simple.coverage b/tests/coverage/branch/guard-simple.coverage index ac90c48c44342..06ad332a927da 100644 --- a/tests/coverage/branch/guard-simple.coverage +++ b/tests/coverage/branch/guard-simple.coverage @@ -10,11 +10,13 @@ LL| 1| _ if black_box(false) => {} ^0 ------------------ + | Branch (LL:9): [True: 1, False: 0] | Branch (LL:14): [True: 0, False: 1] ------------------ LL| 1| _ if black_box(false) => {} ^0 ------------------ + | Branch (LL:9): [True: 1, False: 0] | Branch (LL:14): [True: 0, False: 1] ------------------ LL| 1| _ => {} diff --git a/tests/coverage/branch/guard.cov-map b/tests/coverage/branch/guard.cov-map index d67c3d349a14e..18dd0c302cbfa 100644 --- a/tests/coverage/branch/guard.cov-map +++ b/tests/coverage/branch/guard.cov-map @@ -1,32 +1,48 @@ Function name: guard::branch_match_guard -Raw bytes (85): 0x[01, 01, 06, 19, 0d, 05, 09, 0f, 15, 13, 11, 17, 0d, 05, 09, 0d, 01, 0c, 01, 01, 10, 1d, 03, 0b, 00, 0c, 15, 01, 14, 02, 0a, 0d, 03, 0e, 00, 0f, 19, 00, 14, 00, 19, 20, 0d, 02, 00, 14, 00, 1e, 0d, 00, 1d, 02, 0a, 11, 03, 0e, 00, 0f, 1d, 00, 14, 00, 19, 20, 11, 09, 00, 14, 00, 1e, 11, 00, 1d, 02, 0a, 17, 03, 0e, 02, 0a, 0b, 04, 01, 00, 02] +Raw bytes (120): 0x[01, 01, 0d, 1b, 0d, 33, 11, 05, 09, 03, 19, 19, 0d, 1b, 1d, 33, 11, 05, 09, 05, 09, 2b, 15, 2f, 11, 33, 0d, 05, 09, 10, 01, 0c, 01, 01, 10, 1d, 03, 0b, 00, 0c, 20, 15, 03, 01, 09, 00, 10, 15, 00, 14, 02, 0a, 20, 19, 0e, 03, 09, 00, 10, 0d, 00, 0e, 00, 0f, 19, 00, 14, 00, 19, 20, 0d, 12, 00, 14, 00, 1e, 0d, 00, 1d, 02, 0a, 20, 1d, 16, 03, 09, 00, 10, 11, 00, 0e, 00, 0f, 1d, 00, 14, 00, 19, 20, 11, 09, 00, 14, 00, 1e, 11, 00, 1d, 02, 0a, 33, 03, 0e, 02, 0a, 27, 04, 01, 00, 02] Number of files: 1 - file 0 => global file 1 -Number of expressions: 6 -- expression 0 operands: lhs = Counter(6), rhs = Counter(3) -- expression 1 operands: lhs = Counter(1), rhs = Counter(2) -- expression 2 operands: lhs = Expression(3, Add), rhs = Counter(5) -- expression 3 operands: lhs = Expression(4, Add), rhs = Counter(4) -- expression 4 operands: lhs = Expression(5, Add), rhs = Counter(3) -- expression 5 operands: lhs = Counter(1), rhs = Counter(2) -Number of file 0 mappings: 13 +Number of expressions: 13 +- expression 0 operands: lhs = Expression(6, Add), rhs = Counter(3) +- expression 1 operands: lhs = Expression(12, Add), rhs = Counter(4) +- expression 2 operands: lhs = Counter(1), rhs = Counter(2) +- expression 3 operands: lhs = Expression(0, Add), rhs = Counter(6) +- expression 4 operands: lhs = Counter(6), rhs = Counter(3) +- expression 5 operands: lhs = Expression(6, Add), rhs = Counter(7) +- expression 6 operands: lhs = Expression(12, Add), rhs = Counter(4) +- expression 7 operands: lhs = Counter(1), rhs = Counter(2) +- expression 8 operands: lhs = Counter(1), rhs = Counter(2) +- expression 9 operands: lhs = Expression(10, Add), rhs = Counter(5) +- expression 10 operands: lhs = Expression(11, Add), rhs = Counter(4) +- expression 11 operands: lhs = Expression(12, Add), rhs = Counter(3) +- expression 12 operands: lhs = Counter(1), rhs = Counter(2) +Number of file 0 mappings: 16 - Code(Counter(0)) at (prev + 12, 1) to (start + 1, 16) - Code(Counter(7)) at (prev + 3, 11) to (start + 0, 12) -- Code(Counter(5)) at (prev + 1, 20) to (start + 2, 10) -- Code(Counter(3)) at (prev + 3, 14) to (start + 0, 15) +- Branch { true: Counter(5), false: Expression(0, Add) } at (prev + 1, 9) to (start + 0, 16) + true = c5 + false = (((c1 + c2) + c4) + c3) +- Code(Counter(5)) at (prev + 0, 20) to (start + 2, 10) +- Branch { true: Counter(6), false: Expression(3, Sub) } at (prev + 3, 9) to (start + 0, 16) + true = c6 + false = ((((c1 + c2) + c4) + c3) - c6) +- Code(Counter(3)) at (prev + 0, 14) to (start + 0, 15) - Code(Counter(6)) at (prev + 0, 20) to (start + 0, 25) -- Branch { true: Counter(3), false: Expression(0, Sub) } at (prev + 0, 20) to (start + 0, 30) +- Branch { true: Counter(3), false: Expression(4, Sub) } at (prev + 0, 20) to (start + 0, 30) true = c3 false = (c6 - c3) - Code(Counter(3)) at (prev + 0, 29) to (start + 2, 10) -- Code(Counter(4)) at (prev + 3, 14) to (start + 0, 15) +- Branch { true: Counter(7), false: Expression(5, Sub) } at (prev + 3, 9) to (start + 0, 16) + true = c7 + false = (((c1 + c2) + c4) - c7) +- Code(Counter(4)) at (prev + 0, 14) to (start + 0, 15) - Code(Counter(7)) at (prev + 0, 20) to (start + 0, 25) - Branch { true: Counter(4), false: Counter(2) } at (prev + 0, 20) to (start + 0, 30) true = c4 false = c2 - Code(Counter(4)) at (prev + 0, 29) to (start + 2, 10) -- Code(Expression(5, Add)) at (prev + 3, 14) to (start + 2, 10) +- Code(Expression(12, Add)) at (prev + 3, 14) to (start + 2, 10) = (c1 + c2) -- Code(Expression(2, Add)) at (prev + 4, 1) to (start + 0, 2) +- Code(Expression(9, Add)) at (prev + 4, 1) to (start + 0, 2) = ((((c1 + c2) + c3) + c4) + c5) diff --git a/tests/coverage/branch/guard.coverage b/tests/coverage/branch/guard.coverage index f89b965b5d0f7..6b1b650d4703c 100644 --- a/tests/coverage/branch/guard.coverage +++ b/tests/coverage/branch/guard.coverage @@ -14,17 +14,22 @@ LL| | LL| 1| match x { LL| 1| Some(0) => { + ------------------ + | Branch (LL:9): [True: 1, False: 3] + ------------------ LL| 1| println!("zero"); LL| 1| } LL| 3| Some(x) if x % 2 == 0 => { ^2 ------------------ + | Branch (LL:9): [True: 3, False: 0] | Branch (LL:20): [True: 2, False: 1] ------------------ LL| 2| println!("is nonzero and even"); LL| 2| } LL| 1| Some(x) if x % 3 == 0 => { ------------------ + | Branch (LL:9): [True: 1, False: 0] | Branch (LL:20): [True: 1, False: 0] ------------------ LL| 1| println!("is nonzero and odd, but divisible by 3"); diff --git a/tests/coverage/branch/match-arms.cov-map b/tests/coverage/branch/match-arms.cov-map index 1f17f11baaa07..04c39db4c5c31 100644 --- a/tests/coverage/branch/match-arms.cov-map +++ b/tests/coverage/branch/match-arms.cov-map @@ -1,60 +1,130 @@ Function name: match_arms::guards -Raw bytes (88): 0x[01, 01, 08, 07, 15, 0b, 11, 0f, 0d, 00, 09, 17, 25, 1b, 21, 1f, 1d, 03, 19, 0c, 01, 30, 01, 01, 10, 29, 03, 0b, 00, 10, 19, 01, 11, 00, 29, 20, 19, 09, 00, 17, 00, 1b, 1d, 01, 11, 00, 29, 20, 1d, 0d, 00, 17, 00, 1b, 21, 01, 11, 00, 29, 20, 21, 11, 00, 17, 00, 1b, 25, 01, 11, 00, 29, 20, 25, 15, 00, 17, 00, 1b, 03, 01, 0e, 00, 18, 13, 03, 05, 01, 02] +Raw bytes (212): 0x[01, 01, 2a, 07, 35, 2b, 19, 4b, 1d, 67, 21, 9b, 01, 25, 9f, 01, 15, a3, 01, 11, a7, 01, 0d, 00, 09, 2b, 31, 4b, 1d, 67, 21, 9b, 01, 25, 9f, 01, 15, a3, 01, 11, a7, 01, 0d, 00, 09, 4b, 2d, 67, 21, 9b, 01, 25, 9f, 01, 15, a3, 01, 11, a7, 01, 0d, 00, 09, 67, 29, 9b, 01, 25, 9f, 01, 15, a3, 01, 11, a7, 01, 0d, 00, 09, 9f, 01, 15, a3, 01, 11, a7, 01, 0d, 00, 09, 8f, 01, 25, 93, 01, 21, 97, 01, 1d, 9b, 01, 19, 9f, 01, 15, a3, 01, 11, a7, 01, 0d, 00, 09, 10, 01, 30, 01, 01, 10, 29, 03, 0b, 00, 10, 20, 35, 02, 01, 09, 00, 13, 19, 00, 11, 00, 29, 20, 19, 09, 00, 17, 00, 1b, 20, 31, 26, 01, 09, 00, 13, 1d, 00, 11, 00, 29, 20, 1d, 0d, 00, 17, 00, 1b, 20, 2d, 46, 01, 09, 00, 13, 21, 00, 11, 00, 29, 20, 21, 11, 00, 17, 00, 1b, 20, 29, 62, 01, 09, 00, 13, 25, 00, 11, 00, 29, 20, 25, 15, 00, 17, 00, 1b, 9b, 01, 01, 0e, 00, 18, 8b, 01, 03, 05, 01, 02] Number of files: 1 - file 0 => global file 1 -Number of expressions: 8 -- expression 0 operands: lhs = Expression(1, Add), rhs = Counter(5) -- expression 1 operands: lhs = Expression(2, Add), rhs = Counter(4) -- expression 2 operands: lhs = Expression(3, Add), rhs = Counter(3) -- expression 3 operands: lhs = Zero, rhs = Counter(2) -- expression 4 operands: lhs = Expression(5, Add), rhs = Counter(9) -- expression 5 operands: lhs = Expression(6, Add), rhs = Counter(8) -- expression 6 operands: lhs = Expression(7, Add), rhs = Counter(7) -- expression 7 operands: lhs = Expression(0, Add), rhs = Counter(6) -Number of file 0 mappings: 12 +Number of expressions: 42 +- expression 0 operands: lhs = Expression(1, Add), rhs = Counter(13) +- expression 1 operands: lhs = Expression(10, Add), rhs = Counter(6) +- expression 2 operands: lhs = Expression(18, Add), rhs = Counter(7) +- expression 3 operands: lhs = Expression(25, Add), rhs = Counter(8) +- expression 4 operands: lhs = Expression(38, Add), rhs = Counter(9) +- expression 5 operands: lhs = Expression(39, Add), rhs = Counter(5) +- expression 6 operands: lhs = Expression(40, Add), rhs = Counter(4) +- expression 7 operands: lhs = Expression(41, Add), rhs = Counter(3) +- expression 8 operands: lhs = Zero, rhs = Counter(2) +- expression 9 operands: lhs = Expression(10, Add), rhs = Counter(12) +- expression 10 operands: lhs = Expression(18, Add), rhs = Counter(7) +- expression 11 operands: lhs = Expression(25, Add), rhs = Counter(8) +- expression 12 operands: lhs = Expression(38, Add), rhs = Counter(9) +- expression 13 operands: lhs = Expression(39, Add), rhs = Counter(5) +- expression 14 operands: lhs = Expression(40, Add), rhs = Counter(4) +- expression 15 operands: lhs = Expression(41, Add), rhs = Counter(3) +- expression 16 operands: lhs = Zero, rhs = Counter(2) +- expression 17 operands: lhs = Expression(18, Add), rhs = Counter(11) +- expression 18 operands: lhs = Expression(25, Add), rhs = Counter(8) +- expression 19 operands: lhs = Expression(38, Add), rhs = Counter(9) +- expression 20 operands: lhs = Expression(39, Add), rhs = Counter(5) +- expression 21 operands: lhs = Expression(40, Add), rhs = Counter(4) +- expression 22 operands: lhs = Expression(41, Add), rhs = Counter(3) +- expression 23 operands: lhs = Zero, rhs = Counter(2) +- expression 24 operands: lhs = Expression(25, Add), rhs = Counter(10) +- expression 25 operands: lhs = Expression(38, Add), rhs = Counter(9) +- expression 26 operands: lhs = Expression(39, Add), rhs = Counter(5) +- expression 27 operands: lhs = Expression(40, Add), rhs = Counter(4) +- expression 28 operands: lhs = Expression(41, Add), rhs = Counter(3) +- expression 29 operands: lhs = Zero, rhs = Counter(2) +- expression 30 operands: lhs = Expression(39, Add), rhs = Counter(5) +- expression 31 operands: lhs = Expression(40, Add), rhs = Counter(4) +- expression 32 operands: lhs = Expression(41, Add), rhs = Counter(3) +- expression 33 operands: lhs = Zero, rhs = Counter(2) +- expression 34 operands: lhs = Expression(35, Add), rhs = Counter(9) +- expression 35 operands: lhs = Expression(36, Add), rhs = Counter(8) +- expression 36 operands: lhs = Expression(37, Add), rhs = Counter(7) +- expression 37 operands: lhs = Expression(38, Add), rhs = Counter(6) +- expression 38 operands: lhs = Expression(39, Add), rhs = Counter(5) +- expression 39 operands: lhs = Expression(40, Add), rhs = Counter(4) +- expression 40 operands: lhs = Expression(41, Add), rhs = Counter(3) +- expression 41 operands: lhs = Zero, rhs = Counter(2) +Number of file 0 mappings: 16 - Code(Counter(0)) at (prev + 48, 1) to (start + 1, 16) - Code(Counter(10)) at (prev + 3, 11) to (start + 0, 16) -- Code(Counter(6)) at (prev + 1, 17) to (start + 0, 41) +- Branch { true: Counter(13), false: Expression(0, Sub) } at (prev + 1, 9) to (start + 0, 19) + true = c13 + false = (((((((((Zero + c2) + c3) + c4) + c5) + c9) + c8) + c7) + c6) - c13) +- Code(Counter(6)) at (prev + 0, 17) to (start + 0, 41) - Branch { true: Counter(6), false: Counter(2) } at (prev + 0, 23) to (start + 0, 27) true = c6 false = c2 -- Code(Counter(7)) at (prev + 1, 17) to (start + 0, 41) +- Branch { true: Counter(12), false: Expression(9, Sub) } at (prev + 1, 9) to (start + 0, 19) + true = c12 + false = ((((((((Zero + c2) + c3) + c4) + c5) + c9) + c8) + c7) - c12) +- Code(Counter(7)) at (prev + 0, 17) to (start + 0, 41) - Branch { true: Counter(7), false: Counter(3) } at (prev + 0, 23) to (start + 0, 27) true = c7 false = c3 -- Code(Counter(8)) at (prev + 1, 17) to (start + 0, 41) +- Branch { true: Counter(11), false: Expression(17, Sub) } at (prev + 1, 9) to (start + 0, 19) + true = c11 + false = (((((((Zero + c2) + c3) + c4) + c5) + c9) + c8) - c11) +- Code(Counter(8)) at (prev + 0, 17) to (start + 0, 41) - Branch { true: Counter(8), false: Counter(4) } at (prev + 0, 23) to (start + 0, 27) true = c8 false = c4 -- Code(Counter(9)) at (prev + 1, 17) to (start + 0, 41) +- Branch { true: Counter(10), false: Expression(24, Sub) } at (prev + 1, 9) to (start + 0, 19) + true = c10 + false = ((((((Zero + c2) + c3) + c4) + c5) + c9) - c10) +- Code(Counter(9)) at (prev + 0, 17) to (start + 0, 41) - Branch { true: Counter(9), false: Counter(5) } at (prev + 0, 23) to (start + 0, 27) true = c9 false = c5 -- Code(Expression(0, Add)) at (prev + 1, 14) to (start + 0, 24) +- Code(Expression(38, Add)) at (prev + 1, 14) to (start + 0, 24) = ((((Zero + c2) + c3) + c4) + c5) -- Code(Expression(4, Add)) at (prev + 3, 5) to (start + 1, 2) +- Code(Expression(34, Add)) at (prev + 3, 5) to (start + 1, 2) = ((((((((Zero + c2) + c3) + c4) + c5) + c6) + c7) + c8) + c9) Function name: match_arms::match_arms -Raw bytes (51): 0x[01, 01, 06, 05, 07, 0b, 11, 09, 0d, 13, 02, 17, 09, 11, 0d, 07, 01, 18, 01, 01, 10, 05, 03, 0b, 00, 10, 11, 01, 11, 00, 21, 0d, 01, 11, 00, 21, 09, 01, 11, 00, 21, 02, 01, 11, 00, 21, 0f, 03, 05, 01, 02] +Raw bytes (102): 0x[01, 01, 15, 17, 0d, 4a, 09, 05, 4f, 53, 11, 09, 0d, 4a, 09, 05, 4f, 53, 11, 09, 0d, 05, 4f, 53, 11, 09, 0d, 05, 4f, 53, 11, 09, 0d, 43, 4a, 47, 09, 11, 0d, 05, 4f, 53, 11, 09, 0d, 0a, 01, 18, 01, 01, 10, 05, 03, 0b, 00, 10, 20, 11, 03, 01, 09, 00, 13, 11, 00, 11, 00, 21, 20, 0d, 17, 01, 09, 00, 13, 0d, 00, 11, 00, 21, 20, 09, 4a, 01, 09, 00, 13, 09, 00, 11, 00, 21, 4a, 01, 11, 00, 21, 3f, 03, 05, 01, 02] Number of files: 1 - file 0 => global file 1 -Number of expressions: 6 -- expression 0 operands: lhs = Counter(1), rhs = Expression(1, Add) -- expression 1 operands: lhs = Expression(2, Add), rhs = Counter(4) -- expression 2 operands: lhs = Counter(2), rhs = Counter(3) -- expression 3 operands: lhs = Expression(4, Add), rhs = Expression(0, Sub) -- expression 4 operands: lhs = Expression(5, Add), rhs = Counter(2) -- expression 5 operands: lhs = Counter(4), rhs = Counter(3) -Number of file 0 mappings: 7 +Number of expressions: 21 +- expression 0 operands: lhs = Expression(5, Add), rhs = Counter(3) +- expression 1 operands: lhs = Expression(18, Sub), rhs = Counter(2) +- expression 2 operands: lhs = Counter(1), rhs = Expression(19, Add) +- expression 3 operands: lhs = Expression(20, Add), rhs = Counter(4) +- expression 4 operands: lhs = Counter(2), rhs = Counter(3) +- expression 5 operands: lhs = Expression(18, Sub), rhs = Counter(2) +- expression 6 operands: lhs = Counter(1), rhs = Expression(19, Add) +- expression 7 operands: lhs = Expression(20, Add), rhs = Counter(4) +- expression 8 operands: lhs = Counter(2), rhs = Counter(3) +- expression 9 operands: lhs = Counter(1), rhs = Expression(19, Add) +- expression 10 operands: lhs = Expression(20, Add), rhs = Counter(4) +- expression 11 operands: lhs = Counter(2), rhs = Counter(3) +- expression 12 operands: lhs = Counter(1), rhs = Expression(19, Add) +- expression 13 operands: lhs = Expression(20, Add), rhs = Counter(4) +- expression 14 operands: lhs = Counter(2), rhs = Counter(3) +- expression 15 operands: lhs = Expression(16, Add), rhs = Expression(18, Sub) +- expression 16 operands: lhs = Expression(17, Add), rhs = Counter(2) +- expression 17 operands: lhs = Counter(4), rhs = Counter(3) +- expression 18 operands: lhs = Counter(1), rhs = Expression(19, Add) +- expression 19 operands: lhs = Expression(20, Add), rhs = Counter(4) +- expression 20 operands: lhs = Counter(2), rhs = Counter(3) +Number of file 0 mappings: 10 - Code(Counter(0)) at (prev + 24, 1) to (start + 1, 16) - Code(Counter(1)) at (prev + 3, 11) to (start + 0, 16) -- Code(Counter(4)) at (prev + 1, 17) to (start + 0, 33) -- Code(Counter(3)) at (prev + 1, 17) to (start + 0, 33) -- Code(Counter(2)) at (prev + 1, 17) to (start + 0, 33) -- Code(Expression(0, Sub)) at (prev + 1, 17) to (start + 0, 33) +- Branch { true: Counter(4), false: Expression(0, Add) } at (prev + 1, 9) to (start + 0, 19) + true = c4 + false = (((c1 - ((c2 + c3) + c4)) + c2) + c3) +- Code(Counter(4)) at (prev + 0, 17) to (start + 0, 33) +- Branch { true: Counter(3), false: Expression(5, Add) } at (prev + 1, 9) to (start + 0, 19) + true = c3 + false = ((c1 - ((c2 + c3) + c4)) + c2) +- Code(Counter(3)) at (prev + 0, 17) to (start + 0, 33) +- Branch { true: Counter(2), false: Expression(18, Sub) } at (prev + 1, 9) to (start + 0, 19) + true = c2 + false = (c1 - ((c2 + c3) + c4)) +- Code(Counter(2)) at (prev + 0, 17) to (start + 0, 33) +- Code(Expression(18, Sub)) at (prev + 1, 17) to (start + 0, 33) = (c1 - ((c2 + c3) + c4)) -- Code(Expression(3, Add)) at (prev + 3, 5) to (start + 1, 2) +- Code(Expression(15, Add)) at (prev + 3, 5) to (start + 1, 2) = (((c4 + c3) + c2) + (c1 - ((c2 + c3) + c4))) Function name: match_arms::or_patterns diff --git a/tests/coverage/branch/match-arms.coverage b/tests/coverage/branch/match-arms.coverage index ea8a6f97ab154..23d0fadb3b24c 100644 --- a/tests/coverage/branch/match-arms.coverage +++ b/tests/coverage/branch/match-arms.coverage @@ -26,8 +26,17 @@ LL| | LL| 15| match value { LL| 8| Enum::D(d) => consume(d), + ------------------ + | Branch (LL:9): [True: 8, False: 7] + ------------------ LL| 4| Enum::C(c) => consume(c), + ------------------ + | Branch (LL:9): [True: 4, False: 3] + ------------------ LL| 2| Enum::B(b) => consume(b), + ------------------ + | Branch (LL:9): [True: 2, False: 1] + ------------------ LL| 1| Enum::A(a) => consume(a), LL| | } LL| | @@ -53,18 +62,22 @@ LL| 3| match value { LL| 8| Enum::D(d) if cond => consume(d), ------------------ + | Branch (LL:9): [True: 24, False: 21] | Branch (LL:23): [True: 8, False: 16] ------------------ LL| 4| Enum::C(c) if cond => consume(c), ------------------ + | Branch (LL:9): [True: 12, False: 25] | Branch (LL:23): [True: 4, False: 8] ------------------ LL| 2| Enum::B(b) if cond => consume(b), ------------------ + | Branch (LL:9): [True: 6, False: 27] | Branch (LL:23): [True: 2, False: 4] ------------------ LL| 1| Enum::A(a) if cond => consume(a), ------------------ + | Branch (LL:9): [True: 3, False: 28] | Branch (LL:23): [True: 1, False: 2] ------------------ LL| 30| _ => consume(0), @@ -101,5 +114,5 @@ LL| | } LL| |} LL| | - LL| |// FIXME(#124118) Actually instrument match arms for branch coverage. + LL| |// FIXME(#124118) Support match expressions with guards or or-patterns. diff --git a/tests/coverage/branch/match-arms.rs b/tests/coverage/branch/match-arms.rs index 63151f59ffe9b..8b4d3ae87a25f 100644 --- a/tests/coverage/branch/match-arms.rs +++ b/tests/coverage/branch/match-arms.rs @@ -87,4 +87,4 @@ fn main() { } } -// FIXME(#124118) Actually instrument match arms for branch coverage. +// FIXME(#124118) Support match expressions with guards or or-patterns. diff --git a/tests/mir-opt/coverage/branch_match_arms.main.InstrumentCoverage.diff b/tests/mir-opt/coverage/branch_match_arms.main.InstrumentCoverage.diff index e60f71f47b1ed..12d993298bb5a 100644 --- a/tests/mir-opt/coverage/branch_match_arms.main.InstrumentCoverage.diff +++ b/tests/mir-opt/coverage/branch_match_arms.main.InstrumentCoverage.diff @@ -26,18 +26,31 @@ debug a => _9; } + coverage branches { + BlockMarkerId(0), BlockMarkerId(1) => $DIR/branch_match_arms.rs:16:9: 16:19 (#0) + BlockMarkerId(2), BlockMarkerId(3) => $DIR/branch_match_arms.rs:17:9: 17:19 (#0) + BlockMarkerId(4), BlockMarkerId(5) => $DIR/branch_match_arms.rs:18:9: 18:19 (#0) + BlockMarkerId(6), BlockMarkerId(7) => $DIR/branch_match_arms.rs:19:9: 19:19 (#0) + } + + coverage ExpressionId(0) => Expression { lhs: Counter(1), op: Add, rhs: Counter(2) }; + coverage ExpressionId(1) => Expression { lhs: Expression(0), op: Add, rhs: Counter(3) }; + coverage ExpressionId(2) => Expression { lhs: Counter(0), op: Subtract, rhs: Expression(1) }; + coverage ExpressionId(3) => Expression { lhs: Counter(3), op: Add, rhs: Counter(2) }; + coverage ExpressionId(4) => Expression { lhs: Expression(3), op: Add, rhs: Counter(1) }; + coverage ExpressionId(5) => Expression { lhs: Expression(4), op: Add, rhs: Expression(2) }; ++ coverage ExpressionId(6) => Expression { lhs: Expression(2), op: Add, rhs: Counter(1) }; ++ coverage ExpressionId(7) => Expression { lhs: Expression(6), op: Add, rhs: Counter(2) }; ++ coverage ExpressionId(8) => Expression { lhs: Expression(7), op: Add, rhs: Counter(3) }; + coverage Code(Counter(0)) => $DIR/branch_match_arms.rs:14:1 - 15:21; + coverage Code(Counter(3)) => $DIR/branch_match_arms.rs:16:17 - 16:33; + coverage Code(Counter(2)) => $DIR/branch_match_arms.rs:17:17 - 17:33; + coverage Code(Counter(1)) => $DIR/branch_match_arms.rs:18:17 - 18:33; + coverage Code(Expression(2)) => $DIR/branch_match_arms.rs:19:17 - 19:33; + coverage Code(Expression(5)) => $DIR/branch_match_arms.rs:21:1 - 21:2; ++ coverage Branch { true_term: Counter(1), false_term: Expression(2) } => $DIR/branch_match_arms.rs:18:9 - 18:19; ++ coverage Branch { true_term: Counter(2), false_term: Expression(6) } => $DIR/branch_match_arms.rs:17:9 - 17:19; ++ coverage Branch { true_term: Counter(3), false_term: Expression(7) } => $DIR/branch_match_arms.rs:16:9 - 16:19; + bb0: { + Coverage::CounterIncrement(0); @@ -55,16 +68,19 @@ bb2: { + Coverage::CounterIncrement(3); + Coverage::BlockMarker(0); falseEdge -> [real: bb6, imaginary: bb3]; } bb3: { + Coverage::CounterIncrement(2); + Coverage::BlockMarker(2); falseEdge -> [real: bb8, imaginary: bb4]; } bb4: { + Coverage::CounterIncrement(1); + Coverage::BlockMarker(4); falseEdge -> [real: bb10, imaginary: bb5]; } @@ -74,6 +90,8 @@ _9 = ((_1 as A).0: u32); StorageLive(_10); _10 = _9; + Coverage::BlockMarker(6); + Coverage::BlockMarker(7); _0 = consume(move _10) -> [return: bb12, unwind: bb14]; } @@ -82,6 +100,7 @@ _3 = ((_1 as D).0: u32); StorageLive(_4); _4 = _3; + Coverage::BlockMarker(1); _0 = consume(move _4) -> [return: bb7, unwind: bb14]; } @@ -96,6 +115,7 @@ _5 = ((_1 as C).0: u32); StorageLive(_6); _6 = _5; + Coverage::BlockMarker(3); _0 = consume(move _6) -> [return: bb9, unwind: bb14]; } @@ -110,6 +130,7 @@ _7 = ((_1 as B).0: u32); StorageLive(_8); _8 = _7; + Coverage::BlockMarker(5); _0 = consume(move _8) -> [return: bb11, unwind: bb14]; } diff --git a/tests/mir-opt/coverage/instrument_coverage_cleanup.main.CleanupPostBorrowck.diff b/tests/mir-opt/coverage/instrument_coverage_cleanup.main.CleanupPostBorrowck.diff index 8802f7134b3cc..e2d8f6140c609 100644 --- a/tests/mir-opt/coverage/instrument_coverage_cleanup.main.CleanupPostBorrowck.diff +++ b/tests/mir-opt/coverage/instrument_coverage_cleanup.main.CleanupPostBorrowck.diff @@ -6,13 +6,13 @@ let mut _1: bool; coverage branches { - BlockMarkerId(0) => $DIR/instrument_coverage_cleanup.rs:14:8: 14:36 (#0) - BlockMarkerId(1) => $DIR/instrument_coverage_cleanup.rs:14:8: 14:36 (#0) + BlockMarkerId(0), BlockMarkerId(0) => $DIR/instrument_coverage_cleanup.rs:14:8: 14:36 (#0) + BlockMarkerId(1), BlockMarkerId(1) => $DIR/instrument_coverage_cleanup.rs:14:8: 14:36 (#0) } coverage ExpressionId(0) => Expression { lhs: Counter(0), op: Subtract, rhs: Counter(1) }; coverage ExpressionId(1) => Expression { lhs: Counter(1), op: Add, rhs: Expression(0) }; - coverage ExpressionId(2) => Expression { lhs: Expression(0), op: Add, rhs: Counter(1) }; + coverage ExpressionId(2) => Expression { lhs: Counter(1), op: Add, rhs: Expression(0) }; coverage Code(Counter(0)) => $DIR/instrument_coverage_cleanup.rs:13:1 - 14:36; coverage Code(Expression(0)) => $DIR/instrument_coverage_cleanup.rs:14:37 - 14:39; coverage Code(Counter(1)) => $DIR/instrument_coverage_cleanup.rs:14:39 - 14:40; diff --git a/tests/mir-opt/coverage/instrument_coverage_cleanup.main.InstrumentCoverage.diff b/tests/mir-opt/coverage/instrument_coverage_cleanup.main.InstrumentCoverage.diff index 4739d91de11a1..cf346380249ca 100644 --- a/tests/mir-opt/coverage/instrument_coverage_cleanup.main.InstrumentCoverage.diff +++ b/tests/mir-opt/coverage/instrument_coverage_cleanup.main.InstrumentCoverage.diff @@ -6,13 +6,13 @@ let mut _1: bool; coverage branches { - BlockMarkerId(0) => $DIR/instrument_coverage_cleanup.rs:14:8: 14:36 (#0) - BlockMarkerId(1) => $DIR/instrument_coverage_cleanup.rs:14:8: 14:36 (#0) + BlockMarkerId(0), BlockMarkerId(0) => $DIR/instrument_coverage_cleanup.rs:14:8: 14:36 (#0) + BlockMarkerId(1), BlockMarkerId(1) => $DIR/instrument_coverage_cleanup.rs:14:8: 14:36 (#0) } + coverage ExpressionId(0) => Expression { lhs: Counter(0), op: Subtract, rhs: Counter(1) }; + coverage ExpressionId(1) => Expression { lhs: Counter(1), op: Add, rhs: Expression(0) }; -+ coverage ExpressionId(2) => Expression { lhs: Expression(0), op: Add, rhs: Counter(1) }; ++ coverage ExpressionId(2) => Expression { lhs: Counter(1), op: Add, rhs: Expression(0) }; + coverage Code(Counter(0)) => $DIR/instrument_coverage_cleanup.rs:13:1 - 14:36; + coverage Code(Expression(0)) => $DIR/instrument_coverage_cleanup.rs:14:37 - 14:39; + coverage Code(Counter(1)) => $DIR/instrument_coverage_cleanup.rs:14:39 - 14:40;