coverage. Fix panic when generating mcdc code for inlined functions

This commit is contained in:
zhuyunxing 2024-07-02 18:34:26 +08:00
parent c77788f011
commit 83fa6b726a
4 changed files with 85 additions and 0 deletions

View File

@ -41,6 +41,12 @@ struct CallSite<'tcx> {
impl<'tcx> MirPass<'tcx> for Inline {
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
// FIXME(#127234): Coverage instrumentation currently doesn't handle inlined
// MIR correctly when Modified Condition/Decision Coverage is enabled.
if sess.instrument_coverage_mcdc() {
return false;
}
if let Some(enabled) = sess.opts.unstable_opts.inline_mir {
return enabled;
}

View File

@ -0,0 +1,21 @@
Function name: inlined_expressions::inlined_instance
Raw bytes (52): 0x[01, 01, 03, 01, 05, 0b, 02, 09, 0d, 06, 01, 08, 01, 01, 06, 28, 00, 02, 01, 05, 00, 0b, 30, 05, 02, 01, 02, 00, 00, 05, 00, 06, 05, 00, 0a, 00, 0b, 30, 09, 0d, 02, 00, 00, 00, 0a, 00, 0b, 07, 01, 01, 00, 02]
Number of files: 1
- file 0 => global file 1
Number of expressions: 3
- expression 0 operands: lhs = Counter(0), rhs = Counter(1)
- expression 1 operands: lhs = Expression(2, Add), rhs = Expression(0, Sub)
- expression 2 operands: lhs = Counter(2), rhs = Counter(3)
Number of file 0 mappings: 6
- Code(Counter(0)) at (prev + 8, 1) to (start + 1, 6)
- MCDCDecision { bitmap_idx: 0, conditions_num: 2 } at (prev + 1, 5) to (start + 0, 11)
- MCDCBranch { true: Counter(1), false: Expression(0, Sub), condition_id: 1, true_next_id: 2, false_next_id: 0 } at (prev + 0, 5) to (start + 0, 6)
true = c1
false = (c0 - c1)
- Code(Counter(1)) at (prev + 0, 10) to (start + 0, 11)
- MCDCBranch { true: Counter(2), false: Counter(3), condition_id: 2, true_next_id: 0, false_next_id: 0 } at (prev + 0, 10) to (start + 0, 11)
true = c2
false = c3
- Code(Expression(1, Add)) at (prev + 1, 1) to (start + 0, 2)
= ((c2 + c3) + (c0 - c1))

View File

@ -0,0 +1,41 @@
LL| |#![feature(coverage_attribute)]
LL| |//@ edition: 2021
LL| |//@ min-llvm-version: 18
LL| |//@ compile-flags: -Zcoverage-options=mcdc -Copt-level=z -Cllvm-args=--inline-threshold=0
LL| |//@ llvm-cov-flags: --show-branches=count --show-mcdc
LL| |
LL| |#[inline(always)]
LL| 3|fn inlined_instance(a: bool, b: bool) -> bool {
LL| 3| a && b
^2
------------------
| Branch (LL:5): [True: 2, False: 1]
| Branch (LL:10): [True: 1, False: 1]
------------------
|---> MC/DC Decision Region (LL:5) to (LL:11)
|
| Number of Conditions: 2
| Condition C1 --> (LL:5)
| Condition C2 --> (LL:10)
|
| Executed MC/DC Test Vectors:
|
| C1, C2 Result
| 1 { F, - = F }
| 2 { T, F = F }
| 3 { T, T = T }
|
| C1-Pair: covered: (1,3)
| C2-Pair: covered: (2,3)
| MC/DC Coverage for Decision: 100.00%
|
------------------
LL| 3|}
LL| |
LL| |#[coverage(off)]
LL| |fn main() {
LL| | let _ = inlined_instance(true, false);
LL| | let _ = inlined_instance(false, true);
LL| | let _ = inlined_instance(true, true);
LL| |}

View File

@ -0,0 +1,17 @@
#![feature(coverage_attribute)]
//@ edition: 2021
//@ min-llvm-version: 18
//@ compile-flags: -Zcoverage-options=mcdc -Copt-level=z -Cllvm-args=--inline-threshold=0
//@ llvm-cov-flags: --show-branches=count --show-mcdc
#[inline(always)]
fn inlined_instance(a: bool, b: bool) -> bool {
a && b
}
#[coverage(off)]
fn main() {
let _ = inlined_instance(true, false);
let _ = inlined_instance(false, true);
let _ = inlined_instance(true, true);
}