File tree 1 file changed +20
-0
lines changed
compiler/rustc_mir_transform/src/coverage
1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -294,6 +294,26 @@ fn make_code_region(
294
294
let end_line = end_line as u32 ;
295
295
let end_col = end_col as u32 ;
296
296
297
+ // Line/column coordinates are supposed to be 1-based. If we ever emit
298
+ // coordinates of 0, `llvm-cov` might misinterpret them.
299
+ let all_nonzero = [ start_line, start_col, end_line, end_col] . iter ( ) . all ( |& n| n != 0 ) ;
300
+ debug_assert ! ( all_nonzero, "{start_line}:{start_col} to {end_line}:{end_col}" ) ;
301
+ if !all_nonzero {
302
+ debug ! (
303
+ "Skipping region with zero coordinates: {start_line}:{start_col} to {end_line}:{end_col}"
304
+ ) ;
305
+ return None ;
306
+ }
307
+
308
+ // Coverage mappings use the high bit of `end_col` to indicate that a
309
+ // region is actually a "gap" region, so make sure it's unset.
310
+ let end_col_has_high_bit_unset = ( end_col & ( 1 << 31 ) ) == 0 ;
311
+ debug_assert ! ( end_col_has_high_bit_unset, "{end_col}" ) ;
312
+ if !end_col_has_high_bit_unset {
313
+ debug ! ( "Skipping region with high bit set in end column: {end_col}" ) ;
314
+ return None ;
315
+ }
316
+
297
317
// If we ever emit a region that is improperly ordered (end < start),
298
318
// `llvm-cov` will fail with `coveragemap_error::malformed`, which is
299
319
// inconvenient for users and also very hard to debug.
You can’t perform that action at this time.
0 commit comments