diff --git a/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp b/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp index 871400e29362f..82b560b2613f8 100644 --- a/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp +++ b/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp @@ -760,11 +760,11 @@ void AnalysisConsumer::HandleCode(Decl *D, AnalysisMode Mode, ++NumFunctionsAnalyzedSyntaxOnly; if (SyntaxCheckTimer) { SyntaxCheckTimer->stopTimer(); - llvm::TimeRecord CheckerEndTime = SyntaxCheckTimer->getTotalTime(); - CheckerEndTime -= CheckerStartTime; + llvm::TimeRecord CheckerDuration = + SyntaxCheckTimer->getTotalTime() - CheckerStartTime; FunctionSummaries.findOrInsertSummary(D)->second.SyntaxRunningTime = - std::lround(CheckerEndTime.getWallTime() * 1000); - DisplayTime(CheckerEndTime); + std::lround(CheckerDuration.getWallTime() * 1000); + DisplayTime(CheckerDuration); if (AnalyzerTimers && ShouldClearTimersToPreventDisplayingThem) { AnalyzerTimers->clear(); } @@ -825,11 +825,11 @@ void AnalysisConsumer::RunPathSensitiveChecks(Decl *D, Mgr->options.MaxNodesPerTopLevelFunction); if (ExprEngineTimer) { ExprEngineTimer->stopTimer(); - llvm::TimeRecord ExprEngineEndTime = ExprEngineTimer->getTotalTime(); - ExprEngineEndTime -= ExprEngineStartTime; + llvm::TimeRecord ExprEngineDuration = + ExprEngineTimer->getTotalTime() - ExprEngineStartTime; PathRunningTime.set(static_cast( - std::lround(ExprEngineEndTime.getWallTime() * 1000))); - DisplayTime(ExprEngineEndTime); + std::lround(ExprEngineDuration.getWallTime() * 1000))); + DisplayTime(ExprEngineDuration); if (AnalyzerTimers && ShouldClearTimersToPreventDisplayingThem) { AnalyzerTimers->clear(); } diff --git a/llvm/include/llvm/Support/Timer.h b/llvm/include/llvm/Support/Timer.h index a4ed712577582..6a4475882000a 100644 --- a/llvm/include/llvm/Support/Timer.h +++ b/llvm/include/llvm/Support/Timer.h @@ -66,6 +66,12 @@ class TimeRecord { MemUsed -= RHS.MemUsed; InstructionsExecuted -= RHS.InstructionsExecuted; } + TimeRecord operator-(const TimeRecord &RHS) const { + TimeRecord R = *this; + R -= RHS; + return R; + } + // Feel free to add operator+ if you need it /// Print the current time record to \p OS, with a breakdown showing /// contributions to the \p Total time record.