diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2019-01-20 14:02:54 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2019-01-20 14:02:54 +0000 |
| commit | d5ea6fa648f8835a44adfb322b788e615d77cb71 (patch) | |
| tree | 570aa90958a58b9d6a71fa8594ee0ad8d2a18f2c /contrib/llvm/tools/clang/lib/CodeGen/CoverageMappingGen.cpp | |
| parent | d9484dd61cc151c4f34c31e07f693fefa66316b5 (diff) | |
| parent | 676fbe8105eeb6ff4bb2ed261cb212fcfdbe7b63 (diff) | |
Notes
Diffstat (limited to 'contrib/llvm/tools/clang/lib/CodeGen/CoverageMappingGen.cpp')
| -rw-r--r-- | contrib/llvm/tools/clang/lib/CodeGen/CoverageMappingGen.cpp | 53 |
1 files changed, 33 insertions, 20 deletions
diff --git a/contrib/llvm/tools/clang/lib/CodeGen/CoverageMappingGen.cpp b/contrib/llvm/tools/clang/lib/CodeGen/CoverageMappingGen.cpp index 45a260b41d41..35962c73d9a8 100644 --- a/contrib/llvm/tools/clang/lib/CodeGen/CoverageMappingGen.cpp +++ b/contrib/llvm/tools/clang/lib/CodeGen/CoverageMappingGen.cpp @@ -67,7 +67,6 @@ public: void setStartLoc(SourceLocation Loc) { LocStart = Loc; } - SourceLocation getStartLoc() const LLVM_READONLY { return getBeginLoc(); } SourceLocation getBeginLoc() const { assert(LocStart && "Region has no start location"); return *LocStart; @@ -117,7 +116,7 @@ struct SpellingRegion { } SpellingRegion(SourceManager &SM, SourceMappingRegion &R) - : SpellingRegion(SM, R.getStartLoc(), R.getEndLoc()) {} + : SpellingRegion(SM, R.getBeginLoc(), R.getEndLoc()) {} /// Check if the start and end locations appear in source order, i.e /// top->bottom, left->right. @@ -205,7 +204,7 @@ public: /// Get the start of \c S ignoring macro arguments and builtin macros. SourceLocation getStart(const Stmt *S) { - SourceLocation Loc = S->getLocStart(); + SourceLocation Loc = S->getBeginLoc(); while (SM.isMacroArgExpansion(Loc) || isInBuiltin(Loc)) Loc = SM.getImmediateExpansionRange(Loc).getBegin(); return Loc; @@ -213,7 +212,7 @@ public: /// Get the end of \c S ignoring macro arguments and builtin macros. SourceLocation getEnd(const Stmt *S) { - SourceLocation Loc = S->getLocEnd(); + SourceLocation Loc = S->getEndLoc(); while (SM.isMacroArgExpansion(Loc) || isInBuiltin(Loc)) Loc = SM.getImmediateExpansionRange(Loc).getBegin(); return getPreciseTokenLocEnd(Loc); @@ -230,7 +229,7 @@ public: llvm::SmallSet<FileID, 8> Visited; SmallVector<std::pair<SourceLocation, unsigned>, 8> FileLocs; for (const auto &Region : SourceRegions) { - SourceLocation Loc = Region.getStartLoc(); + SourceLocation Loc = Region.getBeginLoc(); FileID File = SM.getFileID(Loc); if (!Visited.insert(File).second) continue; @@ -312,7 +311,7 @@ public: for (const auto &Region : SourceRegions) { assert(Region.hasEndLoc() && "incomplete region"); - SourceLocation LocStart = Region.getStartLoc(); + SourceLocation LocStart = Region.getBeginLoc(); assert(SM.getFileID(LocStart).isValid() && "region in invalid file"); // Ignore regions from system headers. @@ -503,7 +502,7 @@ struct CounterCoverageMappingBuilder DeferredRegion = None; // If the region ends in an expansion, find the expansion site. - FileID StartFile = SM.getFileID(DR.getStartLoc()); + FileID StartFile = SM.getFileID(DR.getBeginLoc()); if (SM.getFileID(DeferredEndLoc) != StartFile) { if (isNestedIn(DeferredEndLoc, StartFile)) { do { @@ -516,12 +515,12 @@ struct CounterCoverageMappingBuilder // The parent of this deferred region ends where the containing decl ends, // so the region isn't useful. - if (DR.getStartLoc() == DeferredEndLoc) + if (DR.getBeginLoc() == DeferredEndLoc) return Index; // If we're visiting statements in non-source order (e.g switch cases or // a loop condition) we can't construct a sensible deferred region. - if (!SpellingRegion(SM, DR.getStartLoc(), DeferredEndLoc).isInSourceOrder()) + if (!SpellingRegion(SM, DR.getBeginLoc(), DeferredEndLoc).isInSourceOrder()) return Index; DR.setGap(true); @@ -572,7 +571,7 @@ struct CounterCoverageMappingBuilder while (RegionStack.size() > ParentIndex) { SourceMappingRegion &Region = RegionStack.back(); if (Region.hasStartLoc()) { - SourceLocation StartLoc = Region.getStartLoc(); + SourceLocation StartLoc = Region.getBeginLoc(); SourceLocation EndLoc = Region.hasEndLoc() ? Region.getEndLoc() : RegionStack[ParentIndex].getEndLoc(); @@ -620,7 +619,7 @@ struct CounterCoverageMappingBuilder EndLoc == getEndOfFileOrMacro(EndLoc)) MostRecentLocation = getIncludeOrExpansionLoc(EndLoc); - assert(SM.isWrittenInSameFile(Region.getStartLoc(), EndLoc)); + assert(SM.isWrittenInSameFile(Region.getBeginLoc(), EndLoc)); assert(SpellingRegion(SM, Region).isInSourceOrder()); SourceRegions.push_back(Region); @@ -657,18 +656,21 @@ struct CounterCoverageMappingBuilder return RegionStack.back(); } - /// Propagate counts through the children of \c S. - Counter propagateCounts(Counter TopCount, const Stmt *S) { + /// Propagate counts through the children of \p S if \p VisitChildren is true. + /// Otherwise, only emit a count for \p S itself. + Counter propagateCounts(Counter TopCount, const Stmt *S, + bool VisitChildren = true) { SourceLocation StartLoc = getStart(S); SourceLocation EndLoc = getEnd(S); size_t Index = pushRegion(TopCount, StartLoc, EndLoc); - Visit(S); + if (VisitChildren) + Visit(S); Counter ExitCount = getRegion().getCounter(); popRegions(Index); // The statement may be spanned by an expansion. Make sure we handle a file // exit out of this expansion before moving to the next statement. - if (SM.isBeforeInTranslationUnit(StartLoc, S->getLocStart())) + if (SM.isBeforeInTranslationUnit(StartLoc, S->getBeginLoc())) MostRecentLocation = EndLoc; return ExitCount; @@ -680,7 +682,7 @@ struct CounterCoverageMappingBuilder return SourceRegions.rend() != std::find_if(SourceRegions.rbegin(), SourceRegions.rend(), [&](const SourceMappingRegion &Region) { - return Region.getStartLoc() == StartLoc && + return Region.getBeginLoc() == StartLoc && Region.getEndLoc() == EndLoc; }); } @@ -732,7 +734,7 @@ struct CounterCoverageMappingBuilder for (SourceMappingRegion &I : llvm::reverse(RegionStack)) { if (!I.hasStartLoc()) continue; - SourceLocation Loc = I.getStartLoc(); + SourceLocation Loc = I.getBeginLoc(); if (!isNestedIn(Loc, ParentFile)) { ParentCounter = I.getCounter(); break; @@ -858,7 +860,7 @@ struct CounterCoverageMappingBuilder } void VisitStmt(const Stmt *S) { - if (S->getLocStart().isValid()) + if (S->getBeginLoc().isValid()) extendRegion(S); for (const Stmt *Child : S->children()) if (Child) @@ -875,7 +877,16 @@ struct CounterCoverageMappingBuilder if (Body && SM.isInSystemHeader(SM.getSpellingLoc(getStart(Body)))) return; - propagateCounts(getRegionCounter(Body), Body); + // Do not visit the artificial children nodes of defaulted methods. The + // lexer may not be able to report back precise token end locations for + // these children nodes (llvm.org/PR39822), and moreover users will not be + // able to see coverage for them. + bool Defaulted = false; + if (auto *Method = dyn_cast<CXXMethodDecl>(D)) + Defaulted = Method->isDefaulted(); + + propagateCounts(getRegionCounter(Body), Body, + /*VisitChildren=*/!Defaulted); assert(RegionStack.empty() && "Regions entered but never exited"); // Discard the last uncompleted deferred region in a decl, if one exists. @@ -1036,6 +1047,8 @@ struct CounterCoverageMappingBuilder void VisitCXXForRangeStmt(const CXXForRangeStmt *S) { extendRegion(S); + if (S->getInit()) + Visit(S->getInit()); Visit(S->getLoopVarStmt()); Visit(S->getRangeStmt()); @@ -1141,7 +1154,7 @@ struct CounterCoverageMappingBuilder Counter Count = addCounters(Parent.getCounter(), getRegionCounter(S)); // Reuse the existing region if it starts at our label. This is typical of // the first case in a switch. - if (Parent.hasStartLoc() && Parent.getStartLoc() == getStart(S)) + if (Parent.hasStartLoc() && Parent.getBeginLoc() == getStart(S)) Parent.setCounter(Count); else pushRegion(Count, getStart(S)); |
