Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MC/DC][Coverage] Add assertions into emitSourceRegions() #89572

Merged
merged 5 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions clang/lib/CodeGen/CoverageMappingGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ class SourceMappingRegion {

bool isBranch() const { return FalseCount.has_value(); }

bool isMCDCBranch() const {
return std::holds_alternative<mcdc::BranchParameters>(MCDCParams);
}

bool isMCDCDecision() const {
return std::holds_alternative<mcdc::DecisionParameters>(MCDCParams);
}
Expand Down Expand Up @@ -472,13 +476,19 @@ class CoverageMappingBuilder {
// Ignore regions from system headers unless collecting coverage from
// system headers is explicitly enabled.
if (!SystemHeadersCoverage &&
SM.isInSystemHeader(SM.getSpellingLoc(LocStart)))
SM.isInSystemHeader(SM.getSpellingLoc(LocStart))) {
assert(!Region.isMCDCBranch() && !Region.isMCDCDecision() &&
"Don't suppress the condition in system headers");
continue;
}

auto CovFileID = getCoverageFileID(LocStart);
// Ignore regions that don't have a file, such as builtin macros.
if (!CovFileID)
if (!CovFileID) {
assert(!Region.isMCDCBranch() && !Region.isMCDCDecision() &&
"Don't suppress the condition in non-file regions");
continue;
}

SourceLocation LocEnd = Region.getEndLoc();
assert(SM.isWrittenInSameFile(LocStart, LocEnd) &&
Expand All @@ -488,8 +498,11 @@ class CoverageMappingBuilder {
// This not only suppresses redundant regions, but sometimes prevents
// creating regions with wrong counters if, for example, a statement's
// body ends at the end of a nested macro.
if (Filter.count(std::make_pair(LocStart, LocEnd)))
if (Filter.count(std::make_pair(LocStart, LocEnd))) {
assert(!Region.isMCDCBranch() && !Region.isMCDCDecision() &&
"Don't suppress the condition");
continue;
}

// Find the spelling locations for the mapping region.
SpellingRegion SR{SM, LocStart, LocEnd};
Expand Down
27 changes: 27 additions & 0 deletions clang/test/CoverageMapping/mcdc-scratch-space.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c99 -fcoverage-mcdc -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only %s
// XFAIL: *
// REQUIRES: asserts

int builtin_macro0(int a) {
return (__LINE__
&& a);
}

int builtin_macro1(int a) {
return (a
|| __LINE__);
}

#define PRE(x) pre_##x

int pre0(int pre_a, int b_post) {
return (PRE(a)
&& b_post);
}

#define POST(x) x##_post

int post0(int pre_a, int b_post) {
return (pre_a
|| POST(b));
}
Loading