From: Ted Kremenek Date: Fri, 26 Oct 2012 16:02:36 +0000 (+0000) Subject: Add comments for RemoveRedundantMsgs, rename it to removeRedundantMsgs() per Jordan... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3800165e56107df7430520aa98afdf7065db2dd2;p=clang Add comments for RemoveRedundantMsgs, rename it to removeRedundantMsgs() per Jordan's feedback. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@166778 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/StaticAnalyzer/Core/BugReporter.cpp b/lib/StaticAnalyzer/Core/BugReporter.cpp index ed91988258..2bf701bb9c 100644 --- a/lib/StaticAnalyzer/Core/BugReporter.cpp +++ b/lib/StaticAnalyzer/Core/BugReporter.cpp @@ -138,20 +138,29 @@ eventsDescribeSameCondition(PathDiagnosticEventPiece *X, return 0; } -static void RemoveRedundantMsgs(PathPieces &path) { +/// An optimization pass over PathPieces that removes redundant diagnostics +/// generated by both ConditionBRVisitor and TrackConstraintBRVisitor. Both +/// BugReporterVisitors use different methods to generate diagnostics, with +/// one capable of emitting diagnostics in some cases but not in others. This +/// can lead to redundant diagnostic pieces at the same point in a path. +static void removeRedundantMsgs(PathPieces &path) { unsigned N = path.size(); if (N < 2) return; + // NOTE: this loop intentionally is not using an iterator. Instead, we + // are streaming the path and modifying it in place. This is done by + // grabbing the front, processing it, and if we decide to keep it append + // it to the end of the path. The entire path is processed in this way. for (unsigned i = 0; i < N; ++i) { IntrusiveRefCntPtr piece(path.front()); path.pop_front(); switch (piece->getKind()) { case clang::ento::PathDiagnosticPiece::Call: - RemoveRedundantMsgs(cast(piece)->path); + removeRedundantMsgs(cast(piece)->path); break; case clang::ento::PathDiagnosticPiece::Macro: - RemoveRedundantMsgs(cast(piece)->subPieces); + removeRedundantMsgs(cast(piece)->subPieces); break; case clang::ento::PathDiagnosticPiece::ControlFlow: break; @@ -2080,7 +2089,7 @@ bool GRBugReporter::generatePathDiagnostic(PathDiagnostic& PD, // Finally, prune the diagnostic path of uninteresting stuff. if (!PD.path.empty()) { // Remove messages that are basically the same. - RemoveRedundantMsgs(PD.getMutablePieces()); + removeRedundantMsgs(PD.getMutablePieces()); if (R->shouldPrunePath()) { bool hasSomethingInteresting = RemoveUneededCalls(PD.getMutablePieces(),