diff options
author | Zequan Wu <zequanwu@google.com> | 2020-08-11 12:39:25 -0700 |
---|---|---|
committer | Zequan Wu <zequanwu@google.com> | 2020-08-12 16:25:27 -0700 |
commit | a31c89c1b7a0a2fd3e2c0b8a587a60921abf4abd (patch) | |
tree | 739239cc6e23a8f73915ec989b2953c6ef8c4be6 /clang/lib/CodeGen/CoverageMappingGen.cpp | |
parent | fc544dcf2daa378c74ea6dd4c86ed5478e7b48c5 (diff) | |
download | llvm-a31c89c1b7a0a2fd3e2c0b8a587a60921abf4abd.zip llvm-a31c89c1b7a0a2fd3e2c0b8a587a60921abf4abd.tar.gz llvm-a31c89c1b7a0a2fd3e2c0b8a587a60921abf4abd.tar.bz2 |
[Coverage] Enable emitting gap area between macros
Differential Revision: https://reviews.llvm.org/D85176
Diffstat (limited to 'clang/lib/CodeGen/CoverageMappingGen.cpp')
-rw-r--r-- | clang/lib/CodeGen/CoverageMappingGen.cpp | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp b/clang/lib/CodeGen/CoverageMappingGen.cpp index 9a7096b..e6e1b21 100644 --- a/clang/lib/CodeGen/CoverageMappingGen.cpp +++ b/clang/lib/CodeGen/CoverageMappingGen.cpp @@ -864,22 +864,13 @@ struct CounterCoverageMappingBuilder /// Find a valid gap range between \p AfterLoc and \p BeforeLoc. Optional<SourceRange> findGapAreaBetween(SourceLocation AfterLoc, SourceLocation BeforeLoc) { - // If the start and end locations of the gap are both within the same macro - // file, the range may not be in source order. - if (AfterLoc.isMacroID() || BeforeLoc.isMacroID()) - return None; + AfterLoc = SM.getExpansionLoc(AfterLoc); + BeforeLoc = SM.getExpansionLoc(BeforeLoc); if (!SM.isWrittenInSameFile(AfterLoc, BeforeLoc)) return None; return {{AfterLoc, BeforeLoc}}; } - /// Find the source range after \p AfterStmt and before \p BeforeStmt. - Optional<SourceRange> findGapAreaBetween(const Stmt *AfterStmt, - const Stmt *BeforeStmt) { - return findGapAreaBetween(getPreciseTokenLocEnd(getEnd(AfterStmt)), - getStart(BeforeStmt)); - } - /// Emit a gap region between \p StartLoc and \p EndLoc with the given count. void fillGapAreaWithCount(SourceLocation StartLoc, SourceLocation EndLoc, Counter Count) { @@ -1044,7 +1035,8 @@ struct CounterCoverageMappingBuilder adjustForOutOfOrderTraversal(getEnd(S)); // The body count applies to the area immediately after the increment. - auto Gap = findGapAreaBetween(S->getCond(), S->getBody()); + auto Gap = findGapAreaBetween(getPreciseTokenLocEnd(S->getRParenLoc()), + getStart(S->getBody())); if (Gap) fillGapAreaWithCount(Gap->getBegin(), Gap->getEnd(), BodyCount); @@ -1261,7 +1253,8 @@ struct CounterCoverageMappingBuilder propagateCounts(ParentCount, S->getCond()); // The 'then' count applies to the area immediately after the condition. - auto Gap = findGapAreaBetween(S->getCond(), S->getThen()); + auto Gap = findGapAreaBetween(getPreciseTokenLocEnd(S->getRParenLoc()), + getStart(S->getThen())); if (Gap) fillGapAreaWithCount(Gap->getBegin(), Gap->getEnd(), ThenCount); @@ -1271,7 +1264,8 @@ struct CounterCoverageMappingBuilder Counter ElseCount = subtractCounters(ParentCount, ThenCount); if (const Stmt *Else = S->getElse()) { // The 'else' count applies to the area immediately after the 'then'. - Gap = findGapAreaBetween(S->getThen(), Else); + Gap = findGapAreaBetween(getPreciseTokenLocEnd(getEnd(S->getThen())), + getStart(Else)); if (Gap) fillGapAreaWithCount(Gap->getBegin(), Gap->getEnd(), ElseCount); extendRegion(Else); |