Skip to content

Commit 99bd601

Browse files
author
zhuyunxing
committed
coverage. MCDC ConditionId start from 0 to keep with llvm 19
1 parent 911ac56 commit 99bd601

3 files changed

Lines changed: 27 additions & 31 deletions

File tree

  • compiler

‎compiler/rustc_codegen_llvm/src/coverageinfo/ffi.rs‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ enum RegionKind {
111111
}
112112

113113
mod mcdc {
114-
use rustc_middle::mir::coverage::{ConditionInfo,DecisionInfo};
114+
use rustc_middle::mir::coverage::{ConditionId,ConditionInfo,DecisionInfo};
115115

116116
/// Must match the layout of `LLVMRustMCDCDecisionParameters`.
117117
#[repr(C)]
@@ -167,12 +167,13 @@ mod mcdc {
167167

168168
implFrom<ConditionInfo>forBranchParameters{
169169
fnfrom(value:ConditionInfo) -> Self{
170+
let to_llvm_cond_id = |cond_id:Option<ConditionId>| {
171+
cond_id.and_then(|id| LLVMConditionId::try_from(id.as_usize()).ok()).unwrap_or(-1)
172+
};
173+
letConditionInfo{ condition_id, true_next_id, false_next_id } = value;
170174
Self{
171-
condition_id: value.condition_id.as_u32()asLLVMConditionId,
172-
condition_ids:[
173-
value.false_next_id.as_u32()asLLVMConditionId,
174-
value.true_next_id.as_u32()asLLVMConditionId,
175-
],
175+
condition_id:to_llvm_cond_id(Some(condition_id)),
176+
condition_ids:[to_llvm_cond_id(false_next_id),to_llvm_cond_id(true_next_id)],
176177
}
177178
}
178179
}

‎compiler/rustc_middle/src/mir/coverage.rs‎

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ rustc_index::newtype_index! {
6767
}
6868

6969
implConditionId{
70-
pubconstNONE:Self = Self::from_u32(0);
70+
pubconstSTART:Self = Self::from_usize(0);
7171
}
7272

7373
/// Enum that can hold a constant zero value, the ID of an physical coverage
@@ -291,18 +291,8 @@ pub struct BranchSpan {
291291
#[derive(TyEncodable,TyDecodable,Hash,HashStable,TypeFoldable,TypeVisitable)]
292292
pubstructConditionInfo{
293293
pubcondition_id:ConditionId,
294-
pubtrue_next_id:ConditionId,
295-
pubfalse_next_id:ConditionId,
296-
}
297-
298-
implDefaultforConditionInfo{
299-
fndefault() -> Self{
300-
Self{
301-
condition_id:ConditionId::NONE,
302-
true_next_id:ConditionId::NONE,
303-
false_next_id:ConditionId::NONE,
304-
}
305-
}
294+
pubtrue_next_id:Option<ConditionId>,
295+
pubfalse_next_id:Option<ConditionId>,
306296
}
307297

308298
#[derive(Clone,Debug)]

‎compiler/rustc_mir_build/src/build/coverageinfo/mcdc.rs‎

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,22 +106,27 @@ impl MCDCState {
106106
}),
107107
};
108108

109-
let parent_condition = decision_ctx.decision_stack.pop_back().unwrap_or_default();
110-
let lhs_id = if parent_condition.condition_id == ConditionId::NONE{
109+
let parent_condition = decision_ctx.decision_stack.pop_back().unwrap_or_else(|| {
110+
assert_eq!(
111+
decision.num_conditions,0,
112+
"decision stack must be empty only for empty decision"
113+
);
111114
decision.num_conditions += 1;
112-
ConditionId::from(decision.num_conditions)
113-
}else{
114-
parent_condition.condition_id
115-
};
115+
ConditionInfo{
116+
condition_id:ConditionId::START,
117+
true_next_id:None,
118+
false_next_id:None,
119+
}
120+
});
121+
let lhs_id = parent_condition.condition_id;
116122

117-
decision.num_conditions += 1;
118123
let rhs_condition_id = ConditionId::from(decision.num_conditions);
119-
124+
decision.num_conditions += 1;
120125
let(lhs, rhs) = match op {
121126
LogicalOp::And => {
122127
let lhs = ConditionInfo{
123128
condition_id: lhs_id,
124-
true_next_id: rhs_condition_id,
129+
true_next_id:Some(rhs_condition_id),
125130
false_next_id: parent_condition.false_next_id,
126131
};
127132
let rhs = ConditionInfo{
@@ -135,7 +140,7 @@ impl MCDCState {
135140
let lhs = ConditionInfo{
136141
condition_id: lhs_id,
137142
true_next_id: parent_condition.true_next_id,
138-
false_next_id: rhs_condition_id,
143+
false_next_id:Some(rhs_condition_id),
139144
};
140145
let rhs = ConditionInfo{
141146
condition_id: rhs_condition_id,
@@ -164,10 +169,10 @@ impl MCDCState {
164169
letSome(decision) = decision_ctx.processing_decision.as_mut()else{
165170
bug!("Processing decision should have been created before any conditions are taken");
166171
};
167-
if condition_info.true_next_id == ConditionId::NONE{
172+
if condition_info.true_next_id.is_none(){
168173
decision.end_markers.push(true_marker);
169174
}
170-
if condition_info.false_next_id == ConditionId::NONE{
175+
if condition_info.false_next_id.is_none(){
171176
decision.end_markers.push(false_marker);
172177
}
173178

0 commit comments

Comments
 (0)