[analyzer] Factor getCalleeName to the checker context.

many checkers are trying to get a name of the callee when visiting
a CallExpr, so provide a convenience API.

llvm-svn: 144820
This commit is contained in:
Anna Zaks 2011-11-16 19:57:55 +00:00
parent d1eafe118d
commit 3888aa4beb
2 changed files with 16 additions and 10 deletions

View File

@ -142,6 +142,21 @@ public:
Eng.getBugReporter().EmitReport(R);
}
/// \brief Get the name of the called function (path-sensitive).
StringRef getCalleeName(const CallExpr *CE) {
const ProgramState *State = getState();
const Expr *Callee = CE->getCallee();
SVal L = State->getSVal(Callee);
const FunctionDecl *funDecl = L.getAsFunctionDecl();
if (!funDecl)
return StringRef();
IdentifierInfo *funI = funDecl->getIdentifier();
if (!funI)
return StringRef();
return funI->getName();
}
private:
ExplodedNode *addTransitionImpl(const ProgramState *State,
bool MarkAsSink,

View File

@ -440,16 +440,7 @@ void MacOSKeychainAPIChecker::checkPreStmt(const CallExpr *CE,
void MacOSKeychainAPIChecker::checkPostStmt(const CallExpr *CE,
CheckerContext &C) const {
const ProgramState *State = C.getState();
const Expr *Callee = CE->getCallee();
SVal L = State->getSVal(Callee);
const FunctionDecl *funDecl = L.getAsFunctionDecl();
if (!funDecl)
return;
IdentifierInfo *funI = funDecl->getIdentifier();
if (!funI)
return;
StringRef funName = funI->getName();
StringRef funName = C.getCalleeName(CE);
// If a value has been allocated, add it to the set for tracking.
unsigned idx = getTrackedFunctionIndex(funName, true);