summaryrefslogtreecommitdiffstats
path: root/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
diff options
context:
space:
mode:
authorJordan Rose <jordan_rose@apple.com>2013-06-03 22:59:45 +0000
committerJordan Rose <jordan_rose@apple.com>2013-06-03 22:59:45 +0000
commitc892bb04ca196433520892aef95617d1e4373ce7 (patch)
treea3686dc7a8073811679fde87e917b27fb9fb7edb /clang/lib/StaticAnalyzer/Core/BugReporter.cpp
parent5250b873bb12716e60818f5a97aa6df824760af3 (diff)
downloadbcm5719-llvm-c892bb04ca196433520892aef95617d1e4373ce7.tar.gz
bcm5719-llvm-c892bb04ca196433520892aef95617d1e4373ce7.zip
[analyzer; new edges] Include a top-level function entry edge while optimizing.
Although we don't want to show a function entry edge for a top-level path, having it makes optimizing edges a little more uniform. This does not affect any edges now, but will affect context edge generation (next commit). llvm-svn: 183158
Diffstat (limited to 'clang/lib/StaticAnalyzer/Core/BugReporter.cpp')
-rw-r--r--clang/lib/StaticAnalyzer/Core/BugReporter.cpp52
1 files changed, 29 insertions, 23 deletions
diff --git a/clang/lib/StaticAnalyzer/Core/BugReporter.cpp b/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
index b69b615b740..86b6daf0309 100644
--- a/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
+++ b/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
@@ -1820,6 +1820,14 @@ GenerateAlternateExtensivePathDiagnostic(PathDiagnostic& PD,
}
}
+ // Add an edge to the start of the function.
+ // We'll prune it out later, but it helps make diagnostics more uniform.
+ const StackFrameContext *CalleeLC = PDB.LC->getCurrentStackFrame();
+ const Decl *D = CalleeLC->getDecl();
+ addEdgeToPath(PD.getActivePath(), PrevLoc,
+ PathDiagnosticLocation::createBegin(D, SM),
+ CalleeLC);
+
return report->isValid();
}
@@ -2057,12 +2065,8 @@ static bool optimizeEdges(PathPieces &path, SourceManager &SM,
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; ) {
- bool wasFirst = isFirst;
- isFirst = false;
-
// Optimize subpaths.
if (PathDiagnosticCallPiece *CallI = dyn_cast<PathDiagnosticCallPiece>(*I)){
// Record the fact that a call has been optimized so we only do the
@@ -2089,25 +2093,6 @@ static bool optimizeEdges(PathPieces &path, SourceManager &SM,
const Stmt *level1 = getStmtParent(s1Start, PM);
const Stmt *level2 = getStmtParent(s1End, PM);
- if (wasFirst) {
- // If the first edge (in isolation) is just a transition from
- // an expression to a parent expression then eliminate that edge.
- if (level1 && level2 && level2 == PM.getParent(level1)) {
- path.erase(I);
- // Since we are erasing the current edge at the start of the
- // path, just return now so we start analyzing the start of the path
- // again.
- return true;
- }
-
- // If the first edge (in isolation) is a transition from the
- // initialization or increment in a for loop then remove it.
- if (level1 && isIncrementOrInitInForLoop(s1Start, level1)) {
- path.erase(I);
- return true;
- }
- }
-
PathPieces::iterator NextI = I; ++NextI;
if (NextI == E)
break;
@@ -2427,6 +2412,23 @@ static void simplifySimpleBranches(PathPieces &pieces) {
}
}
+/// Drop the very first edge in a path, which should be a function entry edge.
+static void dropFunctionEntryEdge(PathPieces &Path,
+ LocationContextMap &LCM,
+ SourceManager &SM) {
+#ifndef NDEBUG
+ const Decl *D = LCM[&Path]->getDecl();
+ PathDiagnosticLocation EntryLoc =
+ PathDiagnosticLocation::createBegin(D, SM);
+ const PathDiagnosticControlFlowPiece *FirstEdge =
+ cast<PathDiagnosticControlFlowPiece>(Path.front());
+ assert(FirstEdge->getStartLocation() == EntryLoc && "not an entry edge");
+#endif
+
+ Path.pop_front();
+}
+
+
//===----------------------------------------------------------------------===//
// Methods for BugType and subclasses.
//===----------------------------------------------------------------------===//
@@ -3126,6 +3128,10 @@ bool GRBugReporter::generatePathDiagnostic(PathDiagnostic& PD,
// Hoist edges originating from branch conditions to branches
// for simple branches.
simplifySimpleBranches(PD.getMutablePieces());
+
+ // Drop the very first function-entry edge. It's not really necessary
+ // for top-level functions.
+ dropFunctionEntryEdge(PD.getMutablePieces(), LCM, SM);
}
}
OpenPOWER on IntegriCloud