From e881efe78596a6ce9219237b737ced4adb1f8251 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Mon, 12 Mar 2012 22:10:57 +0000 Subject: [PATCH] [analyzer] Include inlining call stack depth in plist output. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152584 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/StaticAnalyzer/Core/PlistDiagnostics.cpp | 36 +++-- test/Analysis/inline-plist.c | 132 ++++++++++++++++++- 2 files changed, 155 insertions(+), 13 deletions(-) diff --git a/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp b/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp index cce75ad555..ee2b3f35fb 100644 --- a/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp +++ b/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp @@ -197,7 +197,8 @@ static void ReportEvent(raw_ostream &o, const PathDiagnosticPiece& P, const FIDMap& FM, const SourceManager &SM, const LangOptions &LangOpts, - unsigned indent) { + unsigned indent, + unsigned depth) { Indent(o, indent) << "\n"; ++indent; @@ -223,6 +224,10 @@ static void ReportEvent(raw_ostream &o, const PathDiagnosticPiece& P, --indent; Indent(o, indent) << "\n"; } + + // Output the call depth. + Indent(o, indent) << "depth" + << "" << depth << "\n"; // Output the text. assert(!P.getString().empty()); @@ -245,52 +250,58 @@ static void ReportPiece(raw_ostream &o, const FIDMap& FM, const SourceManager &SM, const LangOptions &LangOpts, unsigned indent, + unsigned depth, bool includeControlFlow); static void ReportCall(raw_ostream &o, const PathDiagnosticCallPiece &P, const FIDMap& FM, const SourceManager &SM, const LangOptions &LangOpts, - unsigned indent) { + unsigned indent, + unsigned depth) { IntrusiveRefCntPtr callEnter = P.getCallEnterEvent(); if (callEnter) - ReportPiece(o, *callEnter, FM, SM, LangOpts, indent, true); + ReportPiece(o, *callEnter, FM, SM, LangOpts, indent, depth, true); IntrusiveRefCntPtr callEnterWithinCaller = P.getCallEnterWithinCallerEvent(); + ++depth; + if (callEnterWithinCaller) - ReportPiece(o, *callEnterWithinCaller, FM, SM, LangOpts, indent, true); + ReportPiece(o, *callEnterWithinCaller, FM, SM, LangOpts, + indent, depth, true); for (PathPieces::const_iterator I = P.path.begin(), E = P.path.end();I!=E;++I) - ReportPiece(o, **I, FM, SM, LangOpts, indent, true); + ReportPiece(o, **I, FM, SM, LangOpts, indent, depth, true); IntrusiveRefCntPtr callExit = P.getCallExitEvent(); if (callExit) - ReportPiece(o, *callExit, FM, SM, LangOpts, indent, true); + ReportPiece(o, *callExit, FM, SM, LangOpts, indent, depth, true); } static void ReportMacro(raw_ostream &o, const PathDiagnosticMacroPiece& P, const FIDMap& FM, const SourceManager &SM, const LangOptions &LangOpts, - unsigned indent) { + unsigned indent, + unsigned depth) { for (PathPieces::const_iterator I = P.subPieces.begin(), E=P.subPieces.end(); I!=E; ++I) { - ReportPiece(o, **I, FM, SM, LangOpts, indent, false); + ReportPiece(o, **I, FM, SM, LangOpts, indent, depth, false); } } static void ReportDiag(raw_ostream &o, const PathDiagnosticPiece& P, const FIDMap& FM, const SourceManager &SM, const LangOptions &LangOpts) { - ReportPiece(o, P, FM, SM, LangOpts, 4, true); + ReportPiece(o, P, FM, SM, LangOpts, 4, 0, true); } static void ReportPiece(raw_ostream &o, @@ -298,6 +309,7 @@ static void ReportPiece(raw_ostream &o, const FIDMap& FM, const SourceManager &SM, const LangOptions &LangOpts, unsigned indent, + unsigned depth, bool includeControlFlow) { switch (P.getKind()) { case PathDiagnosticPiece::ControlFlow: @@ -307,15 +319,15 @@ static void ReportPiece(raw_ostream &o, break; case PathDiagnosticPiece::Call: ReportCall(o, cast(P), FM, SM, LangOpts, - indent); + indent, depth); break; case PathDiagnosticPiece::Event: ReportEvent(o, cast(P), FM, SM, LangOpts, - indent); + indent, depth); break; case PathDiagnosticPiece::Macro: ReportMacro(o, cast(P), FM, SM, LangOpts, - indent); + indent, depth); break; } } diff --git a/test/Analysis/inline-plist.c b/test/Analysis/inline-plist.c index f2ef606601..08b2aedc67 100644 --- a/test/Analysis/inline-plist.c +++ b/test/Analysis/inline-plist.c @@ -14,6 +14,15 @@ int foo(int x, int y) { return 5/x; } +// Test a bug triggering only when inlined. +void has_bug(int *p) { + *p = 0xDEADBEEF; +} + +void test_has_bug() { + has_bug(0); +} + // CHECK: // CHECK: // CHECK: @@ -116,6 +125,7 @@ int foo(int x, int y) { // CHECK: // CHECK: // CHECK: +// CHECK: depth0 // CHECK: extended_message // CHECK: Assuming 'x' is equal to 0 // CHECK: message @@ -212,6 +222,7 @@ int foo(int x, int y) { // CHECK: // CHECK: // CHECK: +// CHECK: depth0 // CHECK: extended_message // CHECK: Division by zero // CHECK: message @@ -228,7 +239,126 @@ int foo(int x, int y) { // CHECK: file0 // CHECK: // CHECK: +// CHECK: +// CHECK: path +// CHECK: +// CHECK: +// CHECK: kindevent +// CHECK: location +// CHECK: +// CHECK: line23 +// CHECK: col3 +// CHECK: file0 +// CHECK: +// CHECK: ranges +// CHECK: +// CHECK: +// CHECK: +// CHECK: line23 +// CHECK: col3 +// CHECK: file0 +// CHECK: +// CHECK: +// CHECK: line23 +// CHECK: col12 +// CHECK: file0 +// CHECK: +// CHECK: +// CHECK: +// CHECK: depth0 +// CHECK: extended_message +// CHECK: Calling 'has_bug' +// CHECK: message +// CHECK: Calling 'has_bug' +// CHECK: +// CHECK: +// CHECK: kindevent +// CHECK: location +// CHECK: +// CHECK: line18 +// CHECK: col1 +// CHECK: file0 +// CHECK: +// CHECK: depth1 +// CHECK: extended_message +// CHECK: Entered call to 'has_bug' +// CHECK: message +// CHECK: Entered call to 'has_bug' +// CHECK: +// CHECK: +// CHECK: kindcontrol +// CHECK: edges +// CHECK: +// CHECK: +// CHECK: start +// CHECK: +// CHECK: +// CHECK: line18 +// CHECK: col1 +// CHECK: file0 +// CHECK: +// CHECK: +// CHECK: line18 +// CHECK: col1 +// CHECK: file0 +// CHECK: +// CHECK: +// CHECK: end +// CHECK: +// CHECK: +// CHECK: line19 +// CHECK: col3 +// CHECK: file0 +// CHECK: +// CHECK: +// CHECK: line19 +// CHECK: col4 +// CHECK: file0 +// CHECK: +// CHECK: +// CHECK: +// CHECK: +// CHECK: +// CHECK: +// CHECK: kindevent +// CHECK: location +// CHECK: +// CHECK: line19 +// CHECK: col3 +// CHECK: file0 +// CHECK: +// CHECK: ranges +// CHECK: +// CHECK: +// CHECK: +// CHECK: line19 +// CHECK: col4 +// CHECK: file0 +// CHECK: +// CHECK: +// CHECK: line19 +// CHECK: col4 +// CHECK: file0 +// CHECK: +// CHECK: +// CHECK: +// CHECK: depth1 +// CHECK: extended_message +// CHECK: Dereference of null pointer (loaded from variable 'p') +// CHECK: message +// CHECK: Dereference of null pointer (loaded from variable 'p') +// CHECK: +// CHECK: +// CHECK: descriptionDereference of null pointer (loaded from variable 'p') +// CHECK: categoryLogic error +// CHECK: typeDereference of null pointer +// CHECK: location +// CHECK: +// CHECK: line19 +// CHECK: col3 +// CHECK: file0 +// CHECK: +// CHECK: // CHECK: // CHECK: // CHECK: - -- 2.40.0