mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
coverage. MCDC ConditionId start from 0 to keep with llvm 19
This commit is contained in:
parent
911ac56e95
commit
99bd601df5
@ -111,7 +111,7 @@ enum RegionKind {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mod mcdc {
|
mod mcdc {
|
||||||
use rustc_middle::mir::coverage::{ConditionInfo, DecisionInfo};
|
use rustc_middle::mir::coverage::{ConditionId, ConditionInfo, DecisionInfo};
|
||||||
|
|
||||||
/// Must match the layout of `LLVMRustMCDCDecisionParameters`.
|
/// Must match the layout of `LLVMRustMCDCDecisionParameters`.
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
@ -167,12 +167,13 @@ mod mcdc {
|
|||||||
|
|
||||||
impl From<ConditionInfo> for BranchParameters {
|
impl From<ConditionInfo> for BranchParameters {
|
||||||
fn from(value: ConditionInfo) -> Self {
|
fn from(value: ConditionInfo) -> Self {
|
||||||
|
let to_llvm_cond_id = |cond_id: Option<ConditionId>| {
|
||||||
|
cond_id.and_then(|id| LLVMConditionId::try_from(id.as_usize()).ok()).unwrap_or(-1)
|
||||||
|
};
|
||||||
|
let ConditionInfo { condition_id, true_next_id, false_next_id } = value;
|
||||||
Self {
|
Self {
|
||||||
condition_id: value.condition_id.as_u32() as LLVMConditionId,
|
condition_id: to_llvm_cond_id(Some(condition_id)),
|
||||||
condition_ids: [
|
condition_ids: [to_llvm_cond_id(false_next_id), to_llvm_cond_id(true_next_id)],
|
||||||
value.false_next_id.as_u32() as LLVMConditionId,
|
|
||||||
value.true_next_id.as_u32() as LLVMConditionId,
|
|
||||||
],
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ rustc_index::newtype_index! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ConditionId {
|
impl ConditionId {
|
||||||
pub const NONE: Self = Self::from_u32(0);
|
pub const START: Self = Self::from_usize(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Enum that can hold a constant zero value, the ID of an physical coverage
|
/// Enum that can hold a constant zero value, the ID of an physical coverage
|
||||||
@ -291,18 +291,8 @@ pub struct BranchSpan {
|
|||||||
#[derive(TyEncodable, TyDecodable, Hash, HashStable, TypeFoldable, TypeVisitable)]
|
#[derive(TyEncodable, TyDecodable, Hash, HashStable, TypeFoldable, TypeVisitable)]
|
||||||
pub struct ConditionInfo {
|
pub struct ConditionInfo {
|
||||||
pub condition_id: ConditionId,
|
pub condition_id: ConditionId,
|
||||||
pub true_next_id: ConditionId,
|
pub true_next_id: Option<ConditionId>,
|
||||||
pub false_next_id: ConditionId,
|
pub false_next_id: Option<ConditionId>,
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for ConditionInfo {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
condition_id: ConditionId::NONE,
|
|
||||||
true_next_id: ConditionId::NONE,
|
|
||||||
false_next_id: ConditionId::NONE,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
@ -106,22 +106,27 @@ impl MCDCState {
|
|||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
let parent_condition = decision_ctx.decision_stack.pop_back().unwrap_or_default();
|
let parent_condition = decision_ctx.decision_stack.pop_back().unwrap_or_else(|| {
|
||||||
let lhs_id = if parent_condition.condition_id == ConditionId::NONE {
|
assert_eq!(
|
||||||
|
decision.num_conditions, 0,
|
||||||
|
"decision stack must be empty only for empty decision"
|
||||||
|
);
|
||||||
decision.num_conditions += 1;
|
decision.num_conditions += 1;
|
||||||
ConditionId::from(decision.num_conditions)
|
ConditionInfo {
|
||||||
} else {
|
condition_id: ConditionId::START,
|
||||||
parent_condition.condition_id
|
true_next_id: None,
|
||||||
};
|
false_next_id: None,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
let lhs_id = parent_condition.condition_id;
|
||||||
|
|
||||||
decision.num_conditions += 1;
|
|
||||||
let rhs_condition_id = ConditionId::from(decision.num_conditions);
|
let rhs_condition_id = ConditionId::from(decision.num_conditions);
|
||||||
|
decision.num_conditions += 1;
|
||||||
let (lhs, rhs) = match op {
|
let (lhs, rhs) = match op {
|
||||||
LogicalOp::And => {
|
LogicalOp::And => {
|
||||||
let lhs = ConditionInfo {
|
let lhs = ConditionInfo {
|
||||||
condition_id: lhs_id,
|
condition_id: lhs_id,
|
||||||
true_next_id: rhs_condition_id,
|
true_next_id: Some(rhs_condition_id),
|
||||||
false_next_id: parent_condition.false_next_id,
|
false_next_id: parent_condition.false_next_id,
|
||||||
};
|
};
|
||||||
let rhs = ConditionInfo {
|
let rhs = ConditionInfo {
|
||||||
@ -135,7 +140,7 @@ impl MCDCState {
|
|||||||
let lhs = ConditionInfo {
|
let lhs = ConditionInfo {
|
||||||
condition_id: lhs_id,
|
condition_id: lhs_id,
|
||||||
true_next_id: parent_condition.true_next_id,
|
true_next_id: parent_condition.true_next_id,
|
||||||
false_next_id: rhs_condition_id,
|
false_next_id: Some(rhs_condition_id),
|
||||||
};
|
};
|
||||||
let rhs = ConditionInfo {
|
let rhs = ConditionInfo {
|
||||||
condition_id: rhs_condition_id,
|
condition_id: rhs_condition_id,
|
||||||
@ -164,10 +169,10 @@ impl MCDCState {
|
|||||||
let Some(decision) = decision_ctx.processing_decision.as_mut() else {
|
let Some(decision) = decision_ctx.processing_decision.as_mut() else {
|
||||||
bug!("Processing decision should have been created before any conditions are taken");
|
bug!("Processing decision should have been created before any conditions are taken");
|
||||||
};
|
};
|
||||||
if condition_info.true_next_id == ConditionId::NONE {
|
if condition_info.true_next_id.is_none() {
|
||||||
decision.end_markers.push(true_marker);
|
decision.end_markers.push(true_marker);
|
||||||
}
|
}
|
||||||
if condition_info.false_next_id == ConditionId::NONE {
|
if condition_info.false_next_id.is_none() {
|
||||||
decision.end_markers.push(false_marker);
|
decision.end_markers.push(false_marker);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user