[cfe-commits] r144820 - in /cfe/trunk: include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp

Ted Kremenek kremenek at apple.com
Wed Nov 16 13:39:19 PST 2011


Good idea.  Can we, however, make the definition of this method out of line? (e.g., in CheckerContext.cpp)

On Nov 16, 2011, at 11:57 AM, Anna Zaks wrote:

> Author: zaks
> Date: Wed Nov 16 13:57:55 2011
> New Revision: 144820
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=144820&view=rev
> Log:
> [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.
> 
> Modified:
>    cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
>    cfe/trunk/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp
> 
> Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h?rev=144820&r1=144819&r2=144820&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h (original)
> +++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h Wed Nov 16 13:57:55 2011
> @@ -142,6 +142,21 @@
>     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,
> 
> Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp?rev=144820&r1=144819&r2=144820&view=diff
> ==============================================================================
> --- cfe/trunk/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp (original)
> +++ cfe/trunk/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp Wed Nov 16 13:57:55 2011
> @@ -440,16 +440,7 @@
> 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);
> 
> 
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits




More information about the cfe-commits mailing list