• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

xd009642 / llvm-profparser / #196

03 May 2025 12:05PM UTC coverage: 72.652% (+0.06%) from 72.597%
#196

push

web-flow
more perf improvements (#45)

* Try FxHashMap for symtab

* Add LLVM-20 and fix report performance issue`

* Bump some versions

* Fix warnings and typo

10 of 12 new or added lines in 1 file covered. (83.33%)

2 existing lines in 2 files now uncovered.

1222 of 1682 relevant lines covered (72.65%)

7.56 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

79.34
/src/coverage/coverage_mapping.rs
1
use crate::coverage::reporting::*;
2
use crate::coverage::*;
3
use crate::instrumentation_profile::types::*;
4
use crate::util::*;
5
use anyhow::{bail, Result};
6
use nom::error::Error as NomError;
7
use object::{Endian, Endianness, Object, ObjectSection, Section};
8
use std::convert::TryInto;
9
use std::error::Error;
10
use std::fmt;
11
use std::fs;
12
use std::path::{Path, PathBuf};
13
use tracing::{debug, error, trace, warn};
14

15
/// Stores the instrumentation profile and information from the coverage mapping sections in the
16
/// object files in order to construct a coverage report. Inspired, from the LLVM implementation
17
/// with some differences/simplifications due to the fact this only hands instrumentation profiles
18
/// for coverage.
19
///
20
/// So what the LLVM one has that this one doesn't yet:
21
///
22
/// 1. DenseMap<size_t, DenseSet<size_t>> RecordProvenance
23
/// 2. std::vector<FunctionRecord> functions (this is probably taken straight from
24
/// InstrumentationProfile
25
/// 3. DenseMap<size_t, SmallVector<unsigned, 0>> FilenameHash2RecordIndices
26
/// 4. Vec<Pair<String, u64>> FuncHashMismatches
27
#[derive(Debug)]
28
pub struct CoverageMapping<'a> {
29
    profile: &'a InstrumentationProfile,
30
    pub mapping_info: Vec<CoverageMappingInfo>,
31
}
32

33
#[derive(Copy, Clone, Debug)]
34
pub enum LlvmSection {
35
    CoverageMap,
36
    ProfileNames,
37
    ProfileCounts,
38
    ProfileData,
39
    CoverageFunctions,
40
}
41

42
#[derive(Copy, Clone, Debug)]
43
pub enum SectionReadError {
44
    EmptySection(LlvmSection),
45
    MissingSection(LlvmSection),
46
    InvalidPathList,
47
}
48

49
impl fmt::Display for SectionReadError {
50
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
×
51
        match self {
×
52
            Self::EmptySection(s) => write!(f, "empty section: {:?}", s),
×
53
            Self::MissingSection(s) => write!(f, "missing section: {:?}", s),
×
54
            Self::InvalidPathList => write!(f, "unable to read path list"),
×
55
        }
56
    }
57
}
58

59
impl Error for SectionReadError {}
60

61
pub fn read_object_file(object: &Path, version: u64) -> Result<CoverageMappingInfo> {
1✔
62
    // I believe vnode sections added by llvm are unnecessary
63

64
    let binary_data = fs::read(object)?;
1✔
65
    let object_file = object::File::parse(&*binary_data)?;
2✔
66

67
    let cov_fun = object_file
3✔
68
        .section_by_name("__llvm_covfun")
69
        .or(object_file.section_by_name(".lcovfun"))
1✔
70
        .map(|x| parse_coverage_functions(object_file.endianness(), &x))
2✔
71
        .ok_or(SectionReadError::MissingSection(
1✔
72
            LlvmSection::CoverageFunctions,
1✔
73
        ))??;
74

75
    debug!("Parsed covfun section: {:?}", cov_fun);
2✔
76

77
    let cov_map = object_file
3✔
78
        .section_by_name("__llvm_covmap")
79
        .or(object_file.section_by_name(".lcovmap"))
1✔
80
        .map(|x| parse_coverage_mapping(object_file.endianness(), &x, version))
2✔
81
        .ok_or(SectionReadError::MissingSection(LlvmSection::CoverageMap))??;
1✔
82

83
    debug!("Parsed covmap section: {:?}", cov_map);
2✔
84

85
    let prof_counts = object_file
2✔
86
        .section_by_name("__llvm_prf_cnts")
87
        .or(object_file.section_by_name(".lprfc"))
1✔
88
        .and_then(|x| parse_profile_counters(object_file.endianness(), &x).ok());
2✔
89

90
    debug!("Parsed prf_cnts: {:?}", prof_counts);
2✔
91

92
    let prof_data = object_file
2✔
93
        .section_by_name("__llvm_prf_data")
94
        .or(object_file.section_by_name(".lprfd"))
1✔
95
        .and_then(|x| parse_profile_data(object_file.endianness(), &x).ok());
2✔
96

97
    debug!("Parsed prf_data section: {:?}", prof_data);
2✔
98

99
    Ok(CoverageMappingInfo {
1✔
100
        cov_map,
1✔
101
        cov_fun,
1✔
102
        prof_counts,
1✔
103
        prof_data,
1✔
104
    })
105
}
106

107
impl<'a> CoverageMapping<'a> {
108
    pub fn new(
1✔
109
        object_files: &[PathBuf],
110
        profile: &'a InstrumentationProfile,
111
        allow_parsing_failures: bool,
112
    ) -> Result<Self> {
113
        let mut mapping_info = vec![];
1✔
114
        let version = match profile.version() {
2✔
115
            Some(v) => v,
1✔
116
            None => bail!("Invalid profile instrumentation, no version number provided"),
×
117
        };
118
        for file in object_files {
3✔
119
            match read_object_file(file.as_path(), version) {
2✔
120
                Ok(info) => mapping_info.push(info),
2✔
121
                Err(e) => {
×
122
                    error!("{} couldn't be interpretted: {}", file.display(), e);
×
123
                    if !allow_parsing_failures {
×
124
                        return Err(e);
×
125
                    }
126
                }
127
            };
128
        }
129
        Ok(Self {
1✔
130
            profile,
×
131
            mapping_info,
1✔
132
        })
133
    }
134

135
    /// All counters of type `CounterKind::ProfileInstrumentation` can be used in function regions
136
    /// other than their own (particulary for functions which are only called from one location).
137
    /// This gathers them all to use as a base list of counters.
138
    pub(crate) fn get_simple_counters(&self, func: &FunctionRecordV3) -> FxHashMap<Counter, i64> {
1✔
139
        let mut result = FxHashMap::default();
1✔
140
        result.insert(Counter::default(), 0);
2✔
141
        let record = self.profile.records().iter().find(|x| {
2✔
142
            x.hash == Some(func.header.fn_hash) && Some(func.header.name_hash) == x.name_hash
1✔
143
        });
144
        if let Some(func_record) = record.as_ref() {
1✔
145
            for (id, count) in func_record.record.counts.iter().enumerate() {
2✔
146
                result.insert(Counter::instrumentation(id as u64), *count as i64);
1✔
147
            }
148
        }
149
        result
1✔
150
    }
151

152
    pub fn generate_subreport<P>(&self, mut predicate: P) -> CoverageReport
1✔
153
    where
154
        P: FnMut(&[PathBuf]) -> bool,
155
    {
156
        let mut report = CoverageReport::default();
1✔
157
        //let base_region_ids = info.get_simple_counters(self.profile);
158
        for info in &self.mapping_info {
3✔
159
            for func in &info.cov_fun {
1✔
160
                let base_region_ids = self.get_simple_counters(func);
1✔
161
                let paths = info.get_files_from_id(func.header.filenames_ref);
1✔
162
                if paths.is_empty() || !predicate(&paths) {
3✔
163
                    continue;
×
164
                }
165

166
                let mut region_ids = base_region_ids.clone();
1✔
167

168
                for region in func.regions.iter().filter(|x| !x.count.is_expression()) {
5✔
169
                    let count = region_ids.get(&region.count).copied().unwrap_or_default();
2✔
170
                    let result = report
1✔
171
                        .files
×
172
                        .entry(paths[region.file_id].clone())
1✔
173
                        .or_default();
174
                    result.insert(region.loc.clone(), count as usize);
1✔
175
                }
176

177
                let mut pending_exprs = vec![];
1✔
178

179
                for (expr_index, expr) in func.expressions.iter().enumerate() {
3✔
180
                    let lhs = region_ids.get(&expr.lhs);
2✔
181
                    let rhs = region_ids.get(&expr.rhs);
1✔
182
                    match (lhs, rhs) {
1✔
183
                        (Some(lhs), Some(rhs)) => {
1✔
184
                            let count: i64 = match expr.kind {
1✔
185
                                ExprKind::Subtract => {
×
186
                                    trace!("Subtracting counts: {} - {}", lhs, rhs);
2✔
187
                                    lhs - rhs
2✔
188
                                }
189
                                ExprKind::Add => {
×
190
                                    trace!("Adding counts: {} + {}", lhs, rhs);
2✔
191
                                    lhs + rhs
2✔
192
                                }
193
                            };
194

195
                            let counter = Counter {
196
                                kind: CounterType::Expression(expr.kind),
1✔
197
                                id: expr_index as _,
1✔
198
                            };
199

200
                            region_ids.insert(counter, count);
2✔
201
                            if let Some(expr_region) = func.regions.iter().find(|x| {
2✔
202
                                x.count.is_expression() && x.count.id == expr_index as u64
1✔
203
                            }) {
204
                                let result = report
1✔
205
                                    .files
×
206
                                    .entry(paths[expr_region.file_id].clone())
1✔
207
                                    .or_default();
208
                                result.insert(expr_region.loc.clone(), count as _);
1✔
209
                            }
210
                        }
211
                        _ => {
×
212
                            let lhs_none = lhs.is_none();
2✔
213
                            let rhs_none = rhs.is_none();
1✔
214
                            // These counters have been optimised out, so just add then in as 0
215
                            if lhs_none && expr.lhs.is_instrumentation() {
2✔
216
                                region_ids.insert(expr.lhs, 0);
×
217
                            }
218
                            if rhs_none && expr.rhs.is_instrumentation() {
2✔
219
                                region_ids.insert(expr.rhs, 0);
×
220
                            }
221
                            pending_exprs.push(Some((expr_index, expr)));
2✔
222
                            continue;
×
223
                        }
224
                    }
225
                }
226
                let mut index = 0;
1✔
227
                let mut cleared_expressions = 0;
1✔
228
                let mut tries_left = pending_exprs.len() + 1;
2✔
229
                while pending_exprs.len() != cleared_expressions {
3✔
230
                    assert!(tries_left > 0);
1✔
231
                    if index >= pending_exprs.len() {
2✔
232
                        index = 0;
1✔
233
                        tries_left -= 1;
1✔
234
                    }
235
                    let (expr_index, expr) = match pending_exprs[index].as_ref() {
3✔
236
                        Some((idx, expr)) => (idx, expr),
1✔
NEW
237
                        None => {
×
238
                            index += 1;
2✔
NEW
239
                            continue;
×
240
                        }
241
                    };
242
                    let lhs = region_ids.get(&expr.lhs);
2✔
243
                    let rhs = region_ids.get(&expr.rhs);
1✔
244
                    match (lhs, rhs) {
1✔
245
                        (Some(lhs), Some(rhs)) => {
1✔
246
                            let count = match expr.kind {
1✔
UNCOV
247
                                ExprKind::Subtract => lhs - rhs,
×
248
                                ExprKind::Add => lhs + rhs,
2✔
249
                            };
250

251
                            let counter = Counter {
252
                                kind: CounterType::Expression(expr.kind),
1✔
253
                                id: *expr_index as _,
1✔
254
                            };
255

256
                            region_ids.insert(counter, count);
2✔
257
                            if let Some(expr_region) = func.regions.iter().find(|x| {
2✔
258
                                x.count.is_expression() && x.count.id == *expr_index as u64
1✔
259
                            }) {
260
                                let result = report
1✔
261
                                    .files
×
262
                                    .entry(paths[expr_region.file_id].clone())
2✔
263
                                    .or_default();
264
                                result.insert(expr_region.loc.clone(), count as _);
1✔
265
                            }
266
                            pending_exprs[index] = None;
2✔
267
                            cleared_expressions += 1;
1✔
268
                        }
269
                        _ => {
×
270
                            index += 1;
2✔
271
                            continue;
×
272
                        }
273
                    }
274
                }
275
            }
276
        }
277
        report
1✔
278
    }
279

280
    pub fn generate_report(&self) -> CoverageReport {
1✔
281
        self.generate_subreport(|_| true)
3✔
282
    }
283
}
284

285
fn parse_coverage_mapping(
1✔
286
    endian: Endianness,
287
    section: &Section<'_, '_>,
288
    version: u64,
289
) -> Result<FxHashMap<u64, Vec<PathBuf>>, SectionReadError> {
290
    if let Ok(mut data) = section.data() {
2✔
291
        let mut result = FxHashMap::default();
1✔
292
        while !data.is_empty() {
3✔
293
            let data_len = data.len();
1✔
294
            // Read the number of affixed function records (now just 0 as not in this header)
295
            debug_assert_eq!(endian.read_i32_bytes(data[0..4].try_into().unwrap()), 0);
2✔
296
            let filename_data_len = endian.read_i32_bytes(data[4..8].try_into().unwrap());
1✔
297
            // Read the length of the affixed string that contains encoded coverage mapping data (now 0
298
            // as not in this header)
299
            debug_assert_eq!(endian.read_i32_bytes(data[8..12].try_into().unwrap()), 0);
1✔
300
            let _format_version = endian.read_i32_bytes(data[12..16].try_into().unwrap());
1✔
301

302
            let hash = md5::compute(&data[16..(filename_data_len as usize + 16)]);
1✔
303
            let hash = endian.read_u64_bytes(hash.0[..8].try_into().unwrap());
1✔
304

305
            //let bytes = &data[16..(16 + filename_data_len as usize)];
306
            let bytes = &data[16..];
1✔
307
            let (bytes, file_strings) = parse_path_list(bytes, version)
1✔
308
                .map_err(|_: nom::Err<NomError<_>>| SectionReadError::InvalidPathList)?;
×
309
            result.insert(hash, file_strings);
2✔
310
            let read_len = data_len - bytes.len();
1✔
311
            let padding = if !bytes.is_empty() && (read_len & 0x07) != 0 {
3✔
312
                8 - (read_len & 0x07)
1✔
313
            } else {
314
                0
×
315
            };
316
            if padding > bytes.len() {
1✔
317
                break;
318
            }
319
            data = &bytes[padding..];
2✔
320
        }
321
        Ok(result)
1✔
322
    } else {
323
        Err(SectionReadError::EmptySection(LlvmSection::CoverageMap))
×
324
    }
325
}
326

327
fn parse_coverage_functions(
1✔
328
    endian: Endianness,
329
    section: &Section<'_, '_>,
330
) -> Result<Vec<FunctionRecordV3>, SectionReadError> {
331
    debug!("Parsing coverage functions");
1✔
332
    if let Ok(original_data) = section.data() {
3✔
333
        let mut bytes = original_data;
1✔
334
        let mut res = vec![];
1✔
335
        let section_len = bytes.len();
1✔
336
        while !bytes.is_empty() {
2✔
337
            let name_hash = endian.read_u64_bytes(bytes[0..8].try_into().unwrap());
2✔
338
            let data_len = endian.read_u32_bytes(bytes[8..12].try_into().unwrap());
1✔
339
            let fn_hash = endian.read_u64_bytes(bytes[12..20].try_into().unwrap());
1✔
340
            let filenames_ref = endian.read_u64_bytes(bytes[20..28].try_into().unwrap());
1✔
341
            let header = FunctionRecordHeader {
342
                name_hash,
343
                data_len,
344
                fn_hash,
345
                filenames_ref,
346
            };
347
            let _start_len = bytes[28..].len();
1✔
348
            bytes = &bytes[28..];
1✔
349

350
            let (data, id_len) = parse_leb128::<NomError<_>>(bytes).unwrap();
1✔
351
            bytes = data;
1✔
352
            let mut filename_indices = vec![];
1✔
353
            for _ in 0..id_len {
3✔
354
                let (data, id) = parse_leb128::<NomError<_>>(bytes).unwrap(); // Issue
2✔
355
                filename_indices.push(id);
1✔
356
                bytes = data;
1✔
357
            }
358

359
            let (data, expr_len) = parse_leb128::<NomError<_>>(bytes).unwrap();
2✔
360
            let expr_len = expr_len as usize;
1✔
361
            bytes = data;
1✔
362
            let mut exprs = vec![Expression::default(); expr_len];
1✔
363
            for i in 0..expr_len {
4✔
364
                let (data, lhs) = parse_leb128::<NomError<_>>(bytes).unwrap();
2✔
365
                let (data, rhs) = parse_leb128::<NomError<_>>(data).unwrap();
1✔
366
                let lhs = parse_counter(lhs, &mut exprs);
1✔
367
                let rhs = parse_counter(rhs, &mut exprs);
1✔
368
                exprs[i].lhs = lhs;
1✔
369
                exprs[i].rhs = rhs;
1✔
370
                bytes = data;
1✔
371
            }
372

373
            let (data, regions) =
1✔
374
                parse_mapping_regions(bytes, &filename_indices, &mut exprs).unwrap();
375

376
            res.push(FunctionRecordV3 {
1✔
377
                header,
378
                regions,
1✔
379
                expressions: exprs,
1✔
380
            });
381

382
            // Todo set couners for expansion regions - counter of expansion region is the counter
383
            // of the first region from the expanded file. This requires multiple passes to
384
            // correctly propagate across all nested regions. N.B. I haven't seen any expansion
385
            // regions in use so may not be an issue!
386

387
            bytes = data;
1✔
388
            let function_len = section_len - bytes.len(); // this should match header
1✔
389

390
            let padding = if function_len < section_len && (function_len & 0x07) != 0 {
3✔
391
                8 - (function_len & 0x07)
2✔
392
            } else {
393
                0
1✔
394
            };
395

396
            if padding > bytes.len() {
1✔
397
                break;
398
            }
399
            // Now apply padding, and if hash is 0 move on as it's a dummy otherwise add to result
400
            // And decide what end type will be
401
            bytes = &bytes[padding..];
2✔
402
        }
403
        Ok(res)
1✔
404
    } else {
405
        error!("Can't read data for coverage function section");
×
406
        Err(SectionReadError::EmptySection(
×
407
            LlvmSection::CoverageFunctions,
×
408
        ))
409
    }
410
}
411

412
/// This code is ported from `RawCoverageMappingReader::readMappingRegionsSubArray`
413
fn parse_mapping_regions<'a>(
1✔
414
    mut bytes: &'a [u8],
415
    file_indices: &[u64],
416
    expressions: &mut Vec<Expression>,
417
) -> IResult<&'a [u8], Vec<CounterMappingRegion>> {
418
    let mut mapping = vec![];
1✔
419
    for i in file_indices {
3✔
420
        let (data, regions_len) = parse_leb128(bytes)?;
2✔
421
        bytes = data;
1✔
422
        let mut last_line = 0;
1✔
423
        for _ in 0..regions_len {
2✔
424
            let mut false_count = Counter::default();
1✔
425
            let mut kind = RegionKind::Code;
1✔
426
            let (data, raw_header) = parse_leb128(bytes)?;
1✔
427
            bytes = data;
1✔
428
            let mut expanded_file_id = 0;
1✔
429
            let mut counter = parse_counter(raw_header, expressions);
2✔
430
            if counter.is_zero() {
1✔
431
                if raw_header & Counter::ENCODING_EXPANSION_REGION_BIT > 0 {
×
432
                    kind = RegionKind::Expansion;
×
433
                    expanded_file_id = raw_header >> Counter::ENCODING_TAG_AND_EXP_REGION_BITS;
×
434
                    if expanded_file_id >= file_indices.len() as u64 {
×
435
                        todo!()
436
                    }
437
                } else {
438
                    let shifted_counter = raw_header >> Counter::ENCODING_TAG_AND_EXP_REGION_BITS;
×
439
                    match shifted_counter.try_into() {
×
440
                        Ok(RegionKind::Code) | Ok(RegionKind::Skipped) => {}
×
441
                        Ok(RegionKind::Branch) => {
×
442
                            kind = RegionKind::Branch;
×
443
                            let (data, c1) = parse_leb128(bytes)?;
×
444
                            let (data, c2) = parse_leb128(data)?;
×
445

446
                            counter = parse_counter(c1, expressions);
×
447
                            false_count = parse_counter(c2, expressions);
×
448
                            bytes = data;
×
449
                        }
450
                        e => panic!("Malformed: {:?}", e),
×
451
                    }
452
                }
453
            }
454

455
            let (data, delta_line) = parse_leb128(bytes)?;
2✔
456
            let (data, column_start) = parse_leb128(data)?;
2✔
457
            let (data, lines_len) = parse_leb128(data)?;
2✔
458
            let (data, column_end) = parse_leb128(data)?;
2✔
459
            bytes = data;
1✔
460

461
            let (column_start, column_end) = if column_start == 0 && column_end == 0 {
4✔
462
                (1usize, usize::MAX)
×
463
            } else {
464
                (column_start as usize, column_end as usize)
1✔
465
            };
466

467
            let line_start = last_line + delta_line as usize;
1✔
468
            let line_end = line_start + lines_len as usize;
2✔
469
            last_line = line_start;
1✔
470

471
            // Add region working-out-stuff
472
            mapping.push(CounterMappingRegion {
2✔
473
                kind,
1✔
474
                count: counter,
1✔
475
                false_count,
1✔
476
                file_id: *i as usize,
1✔
477
                expanded_file_id: expanded_file_id as _,
1✔
478
                loc: SourceLocation {
1✔
479
                    line_start,
×
480
                    line_end,
×
481
                    column_start,
×
482
                    column_end,
×
483
                },
484
            });
485
        }
486
    }
487
    Ok((bytes, mapping))
1✔
488
}
489

490
fn parse_profile_data(
1✔
491
    endian: Endianness,
492
    section: &Section<'_, '_>,
493
) -> Result<Vec<ProfileData>, SectionReadError> {
494
    if let Ok(data) = section.data() {
2✔
495
        let mut bytes = data;
1✔
496
        let mut res = vec![];
1✔
497
        while !bytes.is_empty() {
2✔
498
            // bytes.len() >= 24 {
499
            let name_md5 = endian.read_u64_bytes(bytes[..8].try_into().unwrap());
2✔
500
            let structural_hash = endian.read_u64_bytes(bytes[8..16].try_into().unwrap());
1✔
501

502
            let _counter_ptr = endian.read_u64_bytes(bytes[16..24].try_into().unwrap());
1✔
503
            let counters_location = 24 + 16;
1✔
504
            if bytes.len() <= counters_location {
2✔
505
                bytes = &bytes[counters_location..];
×
506
                let counters_len = endian.read_u32_bytes(bytes[..4].try_into().unwrap());
×
507
                // TODO Might need to get the counter offset and get the list of counters from this?
508
                // And potentially check against the maximum number of counters just to make sure that
509
                // it's not being exceeded?
510
                //
511
                // Also counters_len >= 1 so this should be checked to make sure it's not malformed
512

513
                bytes = &bytes[8..];
×
514

515
                res.push(ProfileData {
×
516
                    name_md5,
517
                    structural_hash,
518
                    counters_len,
519
                });
520
            } else {
521
                bytes = &[];
1✔
522
            }
523
        }
524
        if !bytes.is_empty() {
2✔
525
            warn!("{} bytes left in profile data", bytes.len());
×
526
        }
527
        Ok(res)
1✔
528
    } else {
529
        Err(SectionReadError::EmptySection(LlvmSection::ProfileData))
×
530
    }
531
}
532

533
fn parse_profile_counters(
1✔
534
    endian: Endianness,
535
    section: &Section<'_, '_>,
536
) -> Result<Vec<u64>, SectionReadError> {
537
    if let Ok(data) = section.data() {
2✔
538
        let mut result = vec![];
1✔
539
        for i in (0..data.len()).step_by(8) {
3✔
540
            if data.len() < (i + 8) {
1✔
541
                break;
542
            }
543
            result.push(endian.read_u64_bytes(data[i..(i + 8)].try_into().unwrap()));
1✔
544
        }
545
        Ok(result)
1✔
546
    } else {
547
        Err(SectionReadError::EmptySection(LlvmSection::ProfileCounts))
×
548
    }
549
}
550

551
/// The equivalent llvm function is `RawCoverageMappingReader::decodeCounter`. This makes it
552
/// stateless as I don't want to be maintaining an expression vector and clearing it and
553
/// repopulating for every function record.
554
fn parse_counter(input: u64, exprs: &mut Vec<Expression>) -> Counter {
1✔
555
    let ty = (Counter::ENCODING_TAG_MASK & input) as u8;
2✔
556
    let id = input >> 2; // For zero we don't actually care about this but we'll still do it
2✔
557
    let kind = match ty {
2✔
558
        0 => CounterType::Zero,
1✔
559
        1 => CounterType::ProfileInstrumentation,
1✔
560
        2 | 3 => {
561
            let expr_kind = if ty == 2 {
2✔
562
                ExprKind::Subtract
1✔
563
            } else {
564
                ExprKind::Add
1✔
565
            };
566
            let id = id as usize;
1✔
567
            if exprs.len() <= id {
1✔
568
                debug!(
×
569
                    "Not enough expressions resizing {}->{}",
570
                    exprs.len(),
×
571
                    id + 1
×
572
                );
573
                exprs.resize(id + 1, Expression::default());
×
574
            }
575
            exprs[id].set_kind(expr_kind);
1✔
576
            CounterType::Expression(expr_kind)
1✔
577
        }
578
        _ => unreachable!(),
579
    };
580
    Counter { kind, id }
581
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc