diff options
author | Hans Wennborg <hans@chromium.org> | 2020-07-22 17:01:57 +0200 |
---|---|---|
committer | Hans Wennborg <hans@chromium.org> | 2020-07-22 17:09:20 +0200 |
commit | 238bbd48c5a5f84deca36e5df980241578f7c1df (patch) | |
tree | 6a726a47f655de00111726cdb0d9084ef65982ac /clang/lib/CodeGen/CoverageMappingGen.cpp | |
parent | b99898c1e9c5d8bade1d898e84604d3241b0087c (diff) | |
download | llvm-238bbd48c5a5f84deca36e5df980241578f7c1df.zip llvm-238bbd48c5a5f84deca36e5df980241578f7c1df.tar.gz llvm-238bbd48c5a5f84deca36e5df980241578f7c1df.tar.bz2 |
Revert abd45154b "[Coverage] Add comment to skipped regions"
This casued assertions during Chromium builds. See comment on the code review
> Bug filled here: https://bugs.llvm.org/show_bug.cgi?id=45757.
> Add comment to skipped regions so we don't track execution count for lines containing only comments.
>
> Differential Revision: https://reviews.llvm.org/D84208
This reverts commit abd45154bdb6b76c5b480455eacc8c75b08242aa and the
follow-up 87d725473380652bbe845fd2fbd9c0507a55172f.
Diffstat (limited to 'clang/lib/CodeGen/CoverageMappingGen.cpp')
-rw-r--r-- | clang/lib/CodeGen/CoverageMappingGen.cpp | 74 |
1 files changed, 5 insertions, 69 deletions
diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp b/clang/lib/CodeGen/CoverageMappingGen.cpp index 6729c7f..78b268f 100644 --- a/clang/lib/CodeGen/CoverageMappingGen.cpp +++ b/clang/lib/CodeGen/CoverageMappingGen.cpp @@ -35,40 +35,8 @@ using namespace clang; using namespace CodeGen; using namespace llvm::coverage; -CoverageSourceInfo * -CoverageMappingModuleGen::setUpCoverageCallbacks(Preprocessor &PP) { - CoverageSourceInfo *CoverageInfo = new CoverageSourceInfo; - PP.addPPCallbacks(std::unique_ptr<PPCallbacks>(CoverageInfo)); - PP.addCommentHandler(CoverageInfo); - PP.setPreprocessToken(true); - PP.setTokenWatcher([CoverageInfo](clang::Token Tok) { - // Update previous token location. - CoverageInfo->PrevTokLoc = Tok.getLocation(); - CoverageInfo->updateNextTokLoc(Tok.getLocation()); - }); - return CoverageInfo; -} - void CoverageSourceInfo::SourceRangeSkipped(SourceRange Range, SourceLocation) { - SkippedRanges.push_back({Range}); -} - -bool CoverageSourceInfo::HandleComment(Preprocessor &PP, SourceRange Range) { - if (PrevTokLoc.isValid() && PrevTokLoc == BeforeCommentLoc) - SkippedRanges.back().Range.setEnd(Range.getEnd()); - else { - SkippedRanges.push_back({Range, PrevTokLoc}); - BeforeCommentLoc = PrevTokLoc; - } - LastCommentIndex = SkippedRanges.size() - 1; - return false; -} - -void CoverageSourceInfo::updateNextTokLoc(SourceLocation Loc) { - if (LastCommentIndex) { - SkippedRanges[LastCommentIndex.getValue()].NextTokLoc = Loc; - LastCommentIndex = None; - } + SkippedRanges.push_back(Range); } namespace { @@ -306,34 +274,8 @@ public: return None; } - /// This shrinks the skipped range if it spans a line that contains a - /// non-comment token. If shrinking the skipped range would make it empty, - /// this returns None. - Optional<SpellingRegion> adjustSkippedRange(SourceManager &SM, - SpellingRegion SR, - SourceLocation PrevTokLoc, - SourceLocation NextTokLoc) { - // If Range begin location is invalid, it's not a comment region. - if (PrevTokLoc.isInvalid()) - return SR; - unsigned PrevTokLine = SM.getSpellingLineNumber(PrevTokLoc); - unsigned NextTokLine = SM.getSpellingLineNumber(NextTokLoc); - SpellingRegion newSR(SR); - if (SR.LineStart == PrevTokLine) { - newSR.LineStart = SR.LineStart + 1; - newSR.ColumnStart = 1; - } - if (SR.LineEnd == NextTokLine) { - newSR.LineEnd = SR.LineEnd - 1; - newSR.ColumnEnd = 1; - } - if (newSR.isInSourceOrder()) - return newSR; - return None; - } - /// Gather all the regions that were skipped by the preprocessor - /// using the constructs like #if or comments. + /// using the constructs like #if. void gatherSkippedRegions() { /// An array of the minimum lineStarts and the maximum lineEnds /// for mapping regions from the appropriate source files. @@ -349,10 +291,9 @@ public: } auto SkippedRanges = CVM.getSourceInfo().getSkippedRanges(); - for (auto &I : SkippedRanges) { - SourceRange Range = I.Range; - auto LocStart = Range.getBegin(); - auto LocEnd = Range.getEnd(); + for (const auto &I : SkippedRanges) { + auto LocStart = I.getBegin(); + auto LocEnd = I.getEnd(); assert(SM.isWrittenInSameFile(LocStart, LocEnd) && "region spans multiple files"); @@ -360,11 +301,6 @@ public: if (!CovFileID) continue; SpellingRegion SR{SM, LocStart, LocEnd}; - if (Optional<SpellingRegion> res = - adjustSkippedRange(SM, SR, I.PrevTokLoc, I.NextTokLoc)) - SR = res.getValue(); - else - continue; auto Region = CounterMappingRegion::makeSkipped( *CovFileID, SR.LineStart, SR.ColumnStart, SR.LineEnd, SR.ColumnEnd); // Make sure that we only collect the regions that are inside |