r182502 - [analyzer; alternate edges] remove puny edges on the same line that span less than 3 columns.
Ted Kremenek
kremenek at apple.com
Wed May 22 11:52:35 PDT 2013
Author: kremenek
Date: Wed May 22 13:52:35 2013
New Revision: 182502
URL: http://llvm.org/viewvc/llvm-project?rev=182502&view=rev
Log:
[analyzer;alternate edges] remove puny edges on the same line that span less than 3 columns.
These are legitimate control-flow edges, but visually they add
no value.
Implements <rdar://problem/13941325>.
Modified:
cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp
Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp?rev=182502&r1=182501&r2=182502&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp Wed May 22 13:52:35 2013
@@ -1962,12 +1962,77 @@ static bool lexicalContains(ParentMap &P
return false;
}
+// Remove short edges on the same line less than 3 columns in difference.
+static void removePunyEdges(PathPieces &path,
+ SourceManager &SM,
+ ParentMap &PM) {
+
+ bool erased = false;
+
+ for (PathPieces::iterator I = path.begin(), E = path.end(); I != E;
+ erased ? I : ++I) {
+
+ erased = false;
+
+ PathDiagnosticControlFlowPiece *PieceI =
+ dyn_cast<PathDiagnosticControlFlowPiece>(*I);
+
+ if (!PieceI)
+ continue;
+
+ const Stmt *start = getLocStmt(PieceI->getStartLocation());
+ const Stmt *end = getLocStmt(PieceI->getEndLocation());
+
+ if (!start || !end)
+ continue;
+
+ const Stmt *endParent = PM.getParent(end);
+ if (!endParent)
+ continue;
+
+ if (isConditionForTerminator(end, endParent))
+ continue;
+
+ bool Invalid = false;
+ FullSourceLoc StartL(start->getLocStart(), SM);
+ FullSourceLoc EndL(end->getLocStart(), SM);
+
+ unsigned startLine = StartL.getSpellingLineNumber(&Invalid);
+ if (Invalid)
+ continue;
+
+ unsigned endLine = EndL.getSpellingLineNumber(&Invalid);
+ if (Invalid)
+ continue;
+
+ if (startLine != endLine)
+ continue;
+
+ unsigned startCol = StartL.getSpellingColumnNumber(&Invalid);
+ if (Invalid)
+ continue;
+
+ unsigned endCol = EndL.getSpellingColumnNumber(&Invalid);
+ if (Invalid)
+ continue;
+
+ if (abs(startCol - endCol) <= 2) {
+ PathPieces::iterator PieceToErase = I;
+ ++I;
+ erased = true;
+ path.erase(PieceToErase);
+ continue;
+ }
+ }
+}
+
static bool optimizeEdges(PathPieces &path, SourceManager &SM,
OptimizedCallsSet &OCS,
LocationContextMap &LCM) {
bool hasChanges = false;
const LocationContext *LC = LCM[&path];
assert(LC);
+ ParentMap &PM = LC->getParentMap();
bool isFirst = true;
for (PathPieces::iterator I = path.begin(), E = path.end(); I != E; ) {
@@ -1995,7 +2060,6 @@ static bool optimizeEdges(PathPieces &pa
continue;
}
- ParentMap &PM = LC->getParentMap();
const Stmt *s1Start = getLocStmt(PieceI->getStartLocation());
const Stmt *s1End = getLocStmt(PieceI->getEndLocation());
const Stmt *level1 = getStmtParent(s1Start, PM);
@@ -2132,7 +2196,11 @@ static bool optimizeEdges(PathPieces &pa
++I;
}
- // No changes.
+ if (!hasChanges) {
+ // Remove any puny edges left over after primary optimization pass.
+ removePunyEdges(path, SM, PM);
+ }
+
return hasChanges;
}
More information about the cfe-commits
mailing list