r177649 - [analyzer] Print return values from debug.DumpCalls checker.

Jordan Rose jordan_rose at apple.com
Thu Mar 21 11:16:59 PDT 2013


Author: jrose
Date: Thu Mar 21 13:16:59 2013
New Revision: 177649

URL: http://llvm.org/viewvc/llvm-project?rev=177649&view=rev
Log:
[analyzer] Print return values from debug.DumpCalls checker.

Debug utility only, no functionality change.

Modified:
    cfe/trunk/lib/StaticAnalyzer/Checkers/TraversalChecker.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/TraversalChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/TraversalChecker.cpp?rev=177649&r1=177648&r2=177649&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/TraversalChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/TraversalChecker.cpp Thu Mar 21 13:16:59 2013
@@ -61,9 +61,11 @@ void ento::registerTraversalDumper(Check
 //------------------------------------------------------------------------------
 
 namespace {
-class CallDumper : public Checker< check::PreCall > {
+class CallDumper : public Checker< check::PreCall,
+                                   check::PostCall > {
 public:
   void checkPreCall(const CallEvent &Call, CheckerContext &C) const;
+  void checkPostCall(const CallEvent &Call, CheckerContext &C) const;
 };
 }
 
@@ -80,6 +82,26 @@ void CallDumper::checkPreCall(const Call
   Call.dump(llvm::outs());
 }
 
+void CallDumper::checkPostCall(const CallEvent &Call, CheckerContext &C) const {
+  const Expr *CallE = Call.getOriginExpr();
+  if (!CallE)
+    return;
+
+  unsigned Indentation = 0;
+  for (const LocationContext *LC = C.getLocationContext()->getParent();
+       LC != 0; LC = LC->getParent())
+    ++Indentation;
+
+  // It is mildly evil to print directly to llvm::outs() rather than emitting
+  // warnings, but this ensures things do not get filtered out by the rest of
+  // the static analyzer machinery.
+  llvm::outs().indent(Indentation);
+  if (Call.getResultType()->isVoidType())
+    llvm::outs() << "Returning void\n";
+  else
+    llvm::outs() << "Returning " << C.getSVal(CallE) << "\n";
+}
+
 void ento::registerCallDumper(CheckerManager &mgr) {
   mgr.registerChecker<CallDumper>();
 }





More information about the cfe-commits mailing list