aboutsummaryrefslogtreecommitdiff
path: root/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp
diff options
context:
space:
mode:
authorJordan Rose <jordan_rose@apple.com>2012-11-02 23:49:35 +0000
committerJordan Rose <jordan_rose@apple.com>2012-11-02 23:49:35 +0000
commit0c396d618dfa7cdd6ddafea24df7f74789d1f829 (patch)
tree3aeba0199ff3929c6b85850276b1b7e1d2face02 /lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp
parent1f03a8a0334924719ff85c993d652480e93fda98 (diff)
[analyzer] Convert SimpleStreamChecker over to CallEvent.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@167340 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp')
-rw-r--r--lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp36
1 files changed, 23 insertions, 13 deletions
diff --git a/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp b/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp
index fd548bc1b0..641f2ed0b9 100644
--- a/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp
+++ b/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp
@@ -18,6 +18,7 @@
#include "ClangSACheckers.h"
#include "clang/StaticAnalyzer/Core/Checker.h"
#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
using namespace clang;
@@ -46,8 +47,8 @@ public:
}
};
-class SimpleStreamChecker : public Checker<check::PostStmt<CallExpr>,
- check::PreStmt<CallExpr>,
+class SimpleStreamChecker : public Checker<check::PostCall,
+ check::PreCall,
check::DeadSymbols > {
mutable IdentifierInfo *IIfopen, *IIfclose;
@@ -58,7 +59,7 @@ class SimpleStreamChecker : public Checker<check::PostStmt<CallExpr>,
void initIdentifierInfo(ASTContext &Ctx) const;
void reportDoubleClose(SymbolRef FileDescSym,
- const CallExpr *Call,
+ const CallEvent &Call,
CheckerContext &C) const;
void reportLeaks(SymbolVector LeakedStreams,
@@ -69,9 +70,9 @@ public:
SimpleStreamChecker();
/// Process fopen.
- void checkPostStmt(const CallExpr *Call, CheckerContext &C) const;
+ void checkPostCall(const CallEvent &Call, CheckerContext &C) const;
/// Process fclose.
- void checkPreStmt(const CallExpr *Call, CheckerContext &C) const;
+ void checkPreCall(const CallEvent &Call, CheckerContext &C) const;
void checkDeadSymbols(SymbolReaper &SymReaper, CheckerContext &C) const;
};
@@ -93,15 +94,18 @@ SimpleStreamChecker::SimpleStreamChecker() : IIfopen(0), IIfclose(0) {
LeakBugType->setSuppressOnSink(true);
}
-void SimpleStreamChecker::checkPostStmt(const CallExpr *Call,
+void SimpleStreamChecker::checkPostCall(const CallEvent &Call,
CheckerContext &C) const {
initIdentifierInfo(C.getASTContext());
- if (C.getCalleeIdentifier(Call) != IIfopen)
+ if (!Call.isGlobalCFunction())
+ return;
+
+ if (Call.getCalleeIdentifier() != IIfopen)
return;
// Get the symbolic value corresponding to the file handle.
- SymbolRef FileDesc = C.getSVal(Call).getAsSymbol();
+ SymbolRef FileDesc = Call.getReturnValue().getAsSymbol();
if (!FileDesc)
return;
@@ -111,15 +115,21 @@ void SimpleStreamChecker::checkPostStmt(const CallExpr *Call,
C.addTransition(State);
}
-void SimpleStreamChecker::checkPreStmt(const CallExpr *Call,
+void SimpleStreamChecker::checkPreCall(const CallEvent &Call,
CheckerContext &C) const {
initIdentifierInfo(C.getASTContext());
- if (C.getCalleeIdentifier(Call) != IIfclose || Call->getNumArgs() != 1)
+ if (!Call.isGlobalCFunction())
+ return;
+
+ if (Call.getCalleeIdentifier() != IIfclose)
+ return;
+
+ if (Call.getNumArgs() != 1)
return;
// Get the symbolic value corresponding to the file handle.
- SymbolRef FileDesc = C.getSVal(Call->getArg(0)).getAsSymbol();
+ SymbolRef FileDesc = Call.getArgSVal(0).getAsSymbol();
if (!FileDesc)
return;
@@ -172,7 +182,7 @@ void SimpleStreamChecker::checkDeadSymbols(SymbolReaper &SymReaper,
}
void SimpleStreamChecker::reportDoubleClose(SymbolRef FileDescSym,
- const CallExpr *CallExpr,
+ const CallEvent &Call,
CheckerContext &C) const {
// We reached a bug, stop exploring the path here by generating a sink.
ExplodedNode *ErrNode = C.generateSink();
@@ -183,7 +193,7 @@ void SimpleStreamChecker::reportDoubleClose(SymbolRef FileDescSym,
// Generate the report.
BugReport *R = new BugReport(*DoubleCloseBugType,
"Closing a previously closed file stream", ErrNode);
- R->addRange(CallExpr->getSourceRange());
+ R->addRange(Call.getSourceRange());
R->markInteresting(FileDescSym);
C.emitReport(R);
}