]> granicus.if.org Git - clang/commitdiff
[analyzer] Add checker helpers to CheckerContext.
authorAnna Zaks <ganna@apple.com>
Mon, 29 Oct 2012 22:51:44 +0000 (22:51 +0000)
committerAnna Zaks <ganna@apple.com>
Mon, 29 Oct 2012 22:51:44 +0000 (22:51 +0000)
- Adding Immutable Map to GDM and getIdentifierInfo helper method.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@166975 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
lib/StaticAnalyzer/Checkers/StreamChecker.cpp

index 953527da34a1fff18b58d7ab104c0395e40395e5..4351fe16f0ab2dbec7320e2a79e44d9bd091245e 100644 (file)
 #define LLVM_CLANG_SA_CORE_PATHSENSITIVE_CHECKERCONTEXT
 
 #include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
+#include "llvm/ADT/ImmutableMap.h"
+
+// Declare an immutable map suitable for placement into program states's GDM.
+#define REGISTER_MAP_WITH_GDM(Map, Key, Value) \
+  typedef llvm::ImmutableMap<Key, Value> Map; \
+  namespace clang { \
+  namespace ento { \
+    template <> \
+    struct ProgramStateTrait<Map> \
+      : public ProgramStatePartialTrait<Map> { \
+      static void *GDMIndex() { static int Index; return &Index; } \
+    }; \
+  } \
+  }
+
 
 namespace clang {
 namespace ento {
@@ -197,6 +212,15 @@ public:
   /// \brief Get the name of the called function (path-sensitive).
   StringRef getCalleeName(const FunctionDecl *FunDecl) const;
 
+  /// \brief Get the identifier of the called function (path-sensitive).
+  const IdentifierInfo *getCalleeIdentifier(const CallExpr *CE) const {
+    const FunctionDecl *FunDecl = getCalleeDecl(CE);
+    if (FunDecl)
+      return FunDecl->getIdentifier();
+    else
+      return 0;
+  }
+
   /// \brief Get the name of the called function (path-sensitive).
   StringRef getCalleeName(const CallExpr *CE) const {
     const FunctionDecl *FunDecl = getCalleeDecl(CE);
index 510556dc9a5201b112d71359a2d9d8cedccc12ce..ab1e2a71f9d3f77d0b4341fc0579c57a3a52ff38 100644 (file)
@@ -406,11 +406,13 @@ ProgramStateRef StreamChecker::CheckDoubleClose(const CallExpr *CE,
 
 void StreamChecker::checkDeadSymbols(SymbolReaper &SymReaper,
                                      CheckerContext &C) const {
+  // TODO: Clean up the state.
   for (SymbolReaper::dead_iterator I = SymReaper.dead_begin(),
          E = SymReaper.dead_end(); I != E; ++I) {
     SymbolRef Sym = *I;
     ProgramStateRef state = C.getState();
     const StreamState *SS = state->get<StreamState>(Sym);
+    // TODO: Shouldn't we have a continue here?
     if (!SS)
       return;