[cfe-commits] r151872 - in /cfe/trunk: lib/StaticAnalyzer/Core/BugReporter.cpp lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp test/Analysis/html-diags-multifile.c test/Analysis/html-diags-multifile.h test/Analysis/html-diags.c
Ted Kremenek
kremenek at apple.com
Thu Mar 1 17:27:31 PST 2012
Author: kremenek
Date: Thu Mar 1 19:27:31 2012
New Revision: 151872
URL: http://llvm.org/viewvc/llvm-project?rev=151872&view=rev
Log:
[analyzer diagnostics] Change CompactPathDiagnostic to recursively compact diagnostics in calls into macro pieces.
Also fix handling of macros within calls in the HTMLDiagnostics.
This also adds a test case for r151774.
Added:
cfe/trunk/test/Analysis/html-diags-multifile.c
cfe/trunk/test/Analysis/html-diags-multifile.h
cfe/trunk/test/Analysis/html-diags.c
Modified:
cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp
cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp?rev=151872&r1=151871&r2=151872&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp Thu Mar 1 19:27:31 2012
@@ -564,7 +564,7 @@
// "Minimal" path diagnostic generation algorithm.
//===----------------------------------------------------------------------===//
-static void CompactPathDiagnostic(PathDiagnostic &PD, const SourceManager& SM);
+static void CompactPathDiagnostic(PathPieces &path, const SourceManager& SM);
static void GenerateMinimalPathDiagnostic(PathDiagnostic& PD,
PathDiagnosticBuilder &PDB,
@@ -877,7 +877,7 @@
// After constructing the full PathDiagnostic, do a pass over it to compact
// PathDiagnosticPieces that occur within a macro.
- CompactPathDiagnostic(PD, PDB.getSourceManager());
+ CompactPathDiagnostic(PD.getMutablePieces(), PDB.getSourceManager());
}
//===----------------------------------------------------------------------===//
@@ -1652,7 +1652,7 @@
/// CompactPathDiagnostic - This function postprocesses a PathDiagnostic object
/// and collapses PathDiagosticPieces that are expanded by macros.
-static void CompactPathDiagnostic(PathDiagnostic &PD, const SourceManager& SM) {
+static void CompactPathDiagnostic(PathPieces &path, const SourceManager& SM) {
typedef std::vector<std::pair<IntrusiveRefCntPtr<PathDiagnosticMacroPiece>,
SourceLocation> > MacroStackTy;
@@ -1662,10 +1662,18 @@
MacroStackTy MacroStack;
PiecesTy Pieces;
- for (PathPieces::const_iterator I = PD.path.begin(), E = PD.path.end();
+ for (PathPieces::const_iterator I = path.begin(), E = path.end();
I!=E; ++I) {
+
+ PathDiagnosticPiece *piece = I->getPtr();
+
+ // Recursively compact calls.
+ if (PathDiagnosticCallPiece *call=dyn_cast<PathDiagnosticCallPiece>(piece)){
+ CompactPathDiagnostic(call->path, SM);
+ }
+
// Get the location of the PathDiagnosticPiece.
- const FullSourceLoc Loc = (*I)->getLocation().asLocation();
+ const FullSourceLoc Loc = piece->getLocation().asLocation();
// Determine the instantiation location, which is the location we group
// related PathDiagnosticPieces.
@@ -1675,7 +1683,7 @@
if (Loc.isFileID()) {
MacroStack.clear();
- Pieces.push_back(*I);
+ Pieces.push_back(piece);
continue;
}
@@ -1683,7 +1691,7 @@
// Is the PathDiagnosticPiece within the same macro group?
if (!MacroStack.empty() && InstantiationLoc == MacroStack.back().second) {
- MacroStack.back().first->subPieces.push_back(*I);
+ MacroStack.back().first->subPieces.push_back(piece);
continue;
}
@@ -1714,7 +1722,7 @@
// Create a new macro group and add it to the stack.
PathDiagnosticMacroPiece *NewGroup =
new PathDiagnosticMacroPiece(
- PathDiagnosticLocation::createSingleLocation((*I)->getLocation()));
+ PathDiagnosticLocation::createSingleLocation(piece->getLocation()));
if (MacroGroup)
MacroGroup->subPieces.push_back(NewGroup);
@@ -1728,15 +1736,14 @@
}
// Finally, add the PathDiagnosticPiece to the group.
- MacroGroup->subPieces.push_back(*I);
+ MacroGroup->subPieces.push_back(piece);
}
// Now take the pieces and construct a new PathDiagnostic.
- PD.getMutablePieces().clear();
+ path.clear();
- for (PiecesTy::iterator I=Pieces.begin(), E=Pieces.end(); I!=E; ++I) {
- PD.getMutablePieces().push_back(*I);
- }
+ for (PiecesTy::iterator I=Pieces.begin(), E=Pieces.end(); I!=E; ++I)
+ path.push_back(*I);
}
void GRBugReporter::GeneratePathDiagnostic(PathDiagnostic& PD,
Modified: cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp?rev=151872&r1=151871&r2=151872&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp Thu Mar 1 19:27:31 2012
@@ -95,7 +95,8 @@
}
}
-static void flattenPath(PathPieces &path, const PathPieces &oldPath) {
+static void flattenPath(PathPieces &primaryPath, PathPieces ¤tPath,
+ const PathPieces &oldPath) {
for (PathPieces::const_iterator it = oldPath.begin(), et = oldPath.end();
it != et; ++it ) {
PathDiagnosticPiece *piece = it->getPtr();
@@ -104,16 +105,24 @@
IntrusiveRefCntPtr<PathDiagnosticEventPiece> callEnter =
call->getCallEnterEvent();
if (callEnter)
- path.push_back(callEnter);
- flattenPath(path, call->path);
+ currentPath.push_back(callEnter);
+ flattenPath(primaryPath, primaryPath, call->path);
IntrusiveRefCntPtr<PathDiagnosticEventPiece> callExit =
call->getCallExitEvent();
if (callExit)
- path.push_back(callExit);
+ currentPath.push_back(callExit);
continue;
}
-
- path.push_back(piece);
+ if (PathDiagnosticMacroPiece *macro =
+ dyn_cast<PathDiagnosticMacroPiece>(piece)) {
+ currentPath.push_back(piece);
+ PathPieces newPath;
+ flattenPath(primaryPath, newPath, macro->subPieces);
+ macro->subPieces = newPath;
+ continue;
+ }
+
+ currentPath.push_back(piece);
}
}
@@ -144,7 +153,7 @@
// First flatten out the entire path to make it easier to use.
PathPieces path;
- flattenPath(path, D.path);
+ flattenPath(path, path, D.path);
// The path as already been prechecked that all parts of the path are
// from the same file and that it is non-empty.
Added: cfe/trunk/test/Analysis/html-diags-multifile.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/html-diags-multifile.c?rev=151872&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/html-diags-multifile.c (added)
+++ cfe/trunk/test/Analysis/html-diags-multifile.c Thu Mar 1 19:27:31 2012
@@ -0,0 +1,17 @@
+// RUN: mkdir -p %t.dir
+// RUN: %clang_cc1 -analyze -analyzer-output=html -analyzer-checker=core -o %t.dir
+// RUN: ls %t.dir | grep report | count 0
+// RUN: rm -fR %t.dir
+// REQUIRES: shell
+
+// This tests that we do not currently emit HTML diagnostics for reports that
+// cross file boundaries.
+
+#include "html-diags-multifile.h"
+
+#define CALL_HAS_BUG(q) has_bug(q)
+
+void test_call_macro() {
+ CALL_HAS_BUG(0);
+}
+
Added: cfe/trunk/test/Analysis/html-diags-multifile.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/html-diags-multifile.h?rev=151872&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/html-diags-multifile.h (added)
+++ cfe/trunk/test/Analysis/html-diags-multifile.h Thu Mar 1 19:27:31 2012
@@ -0,0 +1,4 @@
+#define DEREF(p) *p = 0xDEADBEEF
+void has_bug(int *p) {
+ DEREF(p);
+}
Added: cfe/trunk/test/Analysis/html-diags.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/html-diags.c?rev=151872&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/html-diags.c (added)
+++ cfe/trunk/test/Analysis/html-diags.c Thu Mar 1 19:27:31 2012
@@ -0,0 +1,20 @@
+// RUN: mkdir %t.dir
+// RUN: %clang_cc1 -analyze -analyzer-output=html -analyzer-checker=core -o %T.dir %s
+// RUN: rm -fR %t.dir
+
+// Currently this test mainly checks that the HTML diagnostics doesn't crash
+// when handling macros will calls with macros. We should actually validate
+// the output, but that requires being able to match against a specifically
+// generate HTML file.
+
+#define DEREF(p) *p = 0xDEADBEEF
+
+void has_bug(int *p) {
+ DEREF(p);
+}
+
+#define CALL_HAS_BUG(q) has_bug(q)
+
+void test_call_macro() {
+ CALL_HAS_BUG(0);
+}
More information about the cfe-commits
mailing list