@@ -302,6 +302,8 @@ our $FILTER_MISSING_FILE;
302302our $FILTER_EXCEPTION_BRANCH ;
303303# remove lone branch in block - it can't be an actual conditional
304304our $FILTER_ORPHAN_BRANCH ;
305+ # MC/DC with single expression is identical to branch
306+ our $FILTER_MCDC_SINGLE ;
305307our $FILTER_OMIT_PATTERNS ; # special/somewhat faked filter
306308
307309our %COVERAGE_FILTERS = (" branch" => \$FILTER_BRANCH_NO_COND ,
@@ -317,6 +319,7 @@ our %COVERAGE_FILTERS = ("branch" => \$FILTER_BRANCH_NO_COND,
317319 ' branch_region' => \$FILTER_EXCLUDE_BRANCH ,
318320 ' exception' => \$FILTER_EXCEPTION_BRANCH ,
319321 ' orphan' => \$FILTER_ORPHAN_BRANCH ,
322+ ' mcdc' => \$FILTER_MCDC_SINGLE ,
320323 " trivial" => \$FILTER_TRIVIAL_FUNCTION ,);
321324our @cov_filter ; # 'undef' if filter is not enabled,
322325 # [line_count, coverpoint_count] histogram if
@@ -2439,6 +2442,10 @@ sub parse_cov_filters(@)
24392442 " branch filter enabled but neither branch or condition coverage is enabled"
24402443 );
24412444 }
2445+ lcovutil::ignorable_warning($ERROR_USAGE ,
2446+ " 'mcdc' filter enabled but MC/DC coverage is not enabled." )
2447+ if (defined ($cov_filter [$FILTER_MCDC_SINGLE ]) &&
2448+ !$mcdc_coverage );
24422449 if ($cov_filter [$FILTER_BRANCH_NO_COND ]) {
24432450 # turn on exception and orphan filtering too
24442451 $cov_filter [$FILTER_EXCEPTION_BRANCH ] = [' exception' , 0, 0];
@@ -7432,6 +7439,8 @@ sub _filterFile
74327439 my $directive = $cov_filter [$FILTER_DIRECTIVE ];
74337440 my $omit = $cov_filter [$FILTER_OMIT_PATTERNS ]
74347441 if defined ($FILTER_OMIT_PATTERNS );
7442+ my $mcdc_single = $cov_filter [$FILTER_MCDC_SINGLE ]
7443+ if defined ($FILTER_MCDC_SINGLE && $lcovutil::mcdc_coverage );
74357444
74367445 my $context = MessageContext-> new(" filtering $source_file " );
74377446 if (lcovutil::is_filter_enabled()) {
@@ -7637,7 +7646,23 @@ sub _filterFile
76377646 }
76387647 } # foreach line
76397648 } # if branch_coverage
7640- # Line related data
7649+ if ($mcdc_single ) {
7650+ # find single-expression MC/DC's - if there is a matching branch
7651+ # expression on the same line, then remove the MC/DC
7652+ foreach my $line ($mcdc_count -> keylist()) {
7653+ my $block = $mcdc_count -> value($line );
7654+ my $groups = $block -> groups();
7655+ if (exists ($groups -> {1 }) &&
7656+ scalar (keys %$groups ) == 1) {
7657+ my $branch = $testbrcount -> value($line );
7658+ next unless $branch && ($branch -> totals())[0] == 2;
7659+ $mcdc_count -> remove($line );
7660+ ++$mcdc_single -> [-2]; # one MC/DC skipped
7661+
7662+ $mcdc -> remove($line ); # remove at top
7663+ }
7664+ }
7665+ }
76417666 next
76427667 unless $region ||
76437668 $range ||
@@ -7647,6 +7672,7 @@ sub _filterFile
76477672 $omit ||
76487673 $filter_initializer_list ;
76497674
7675+ # Line related data
76507676 my %initializerListRange ;
76517677 foreach my $line ($testcount -> keylist()) {
76527678 # don't suppresss if this line has associated branch or MC/DC data
0 commit comments