]> granicus.if.org Git - clang/commitdiff
Enhance Checker class (and GRExprEngine) to support PostVisitation for CallExprs...
authorTed Kremenek <kremenek@apple.com>
Thu, 12 Nov 2009 04:35:08 +0000 (04:35 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 12 Nov 2009 04:35:08 +0000 (04:35 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86949 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Analysis/PathSensitive/Checker.h
include/clang/Analysis/PathSensitive/CheckerVisitor.def
include/clang/Analysis/PathSensitive/CheckerVisitor.h
lib/Analysis/GRExprEngine.cpp

index 5503a9099b7ebacfd70b0482560153b1085487c6..37ae2e8ed4a29997c1ee650d85b58de6909b347d 100644 (file)
@@ -119,8 +119,10 @@ private:
     CheckerContext C(Dst, Builder, Eng, Pred, tag,
                      isPrevisit ? ProgramPoint::PreStmtKind :
                      ProgramPoint::PostStmtKind);
-    assert(isPrevisit && "Only previsit supported for now.");
-    _PreVisit(C, S);
+    if (isPrevisit)
+      _PreVisit(C, S);
+    else
+      _PostVisit(C, S);
   }
 
   // FIXME: Remove the 'tag' option.
@@ -153,7 +155,8 @@ private:
 
 public:
   virtual ~Checker() {}
-  virtual void _PreVisit(CheckerContext &C, const Stmt *ST) {}
+  virtual void _PreVisit(CheckerContext &C, const Stmt *S) {}
+  virtual void _PostVisit(CheckerContext &C, const Stmt *S) {}
   virtual void VisitLocation(CheckerContext &C, const Stmt *S, SVal location) {}
   virtual void PreVisitBind(CheckerContext &C, const Stmt *AssignE,
                             const Stmt *StoreE, SVal location, SVal val) {}
index 44c6f18f0d7613ef8f2f9d8ba7d444afa8e36cc4..090a5d397549d190ce625938b173664205a30d29 100644 (file)
@@ -11,6 +11,7 @@
 //
 //===---------------------------------------------------------------------===//
 
+#ifdef PREVISIT
 PREVISIT(ArraySubscriptExpr)
 PREVISIT(BinaryOperator)
 PREVISIT(CallExpr)
@@ -18,5 +19,11 @@ PREVISIT(CastExpr)
 PREVISIT(DeclStmt)
 PREVISIT(ObjCMessageExpr)
 PREVISIT(ReturnStmt)
-
 #undef PREVISIT
+#endif
+
+#ifdef POSTVISIT
+POSTVISIT(CallExpr)
+#undef POSTVISIT
+#endif
+
index f2e8f29aa64b62295ba0a23e859efde81e4e99f7..7cef17eb659186a7f164fb41c28b59a2f200c0ac 100644 (file)
@@ -27,8 +27,12 @@ namespace clang {
 template<typename ImplClass>
 class CheckerVisitor : public Checker {
 public:
-  virtual void _PreVisit(CheckerContext &C, const Stmt *stmt) {
-    PreVisit(C, stmt);
+  virtual void _PreVisit(CheckerContext &C, const Stmt *S) {
+    PreVisit(C, S);
+  }
+  
+  virtual void _PostVisit(CheckerContext &C, const Stmt *S) {
+    PostVisit(C, S);
   }
 
   void PreVisit(CheckerContext &C, const Stmt *S) {
@@ -53,6 +57,20 @@ public:
 case Stmt::NAME ## Class:\
 static_cast<ImplClass*>(this)->PreVisit ## NAME(C,static_cast<const NAME*>(S));\
 break;
+#include "clang/Analysis/PathSensitive/CheckerVisitor.def"
+    }
+  }
+    
+  void PostVisit(CheckerContext &C, const Stmt *S) {
+    switch (S->getStmtClass()) {
+      default:
+        assert(false && "Unsupport statement.");
+        return;
+#define POSTVISIT(NAME) \
+case Stmt::NAME ## Class:\
+static_cast<ImplClass*>(this)->\
+PostVisit ## NAME(C,static_cast<const NAME*>(S));\
+break;
 #include "clang/Analysis/PathSensitive/CheckerVisitor.def"
     }
   }
@@ -60,9 +78,12 @@ break;
 #define PREVISIT(NAME) \
 void PreVisit ## NAME(CheckerContext &C, const NAME* S) {}
 #include "clang/Analysis/PathSensitive/CheckerVisitor.def"
+      
+#define POSTVISIT(NAME) \
+void PostVisit ## NAME(CheckerContext &C, const NAME* S) {}
+#include "clang/Analysis/PathSensitive/CheckerVisitor.def"
 };
 
 } // end clang namespace
 
 #endif
-
index 08151e7d61113b52c0b5ce8727d3eb8ef4a53b2f..50d53df2b7839e8b03106d4c8a397e579397c3cd 100644 (file)
@@ -1575,25 +1575,25 @@ void GRExprEngine::VisitCallRec(CallExpr* CE, ExplodedNode* Pred,
       continue;
 
     // Dispatch to the plug-in transfer function.
-
-    unsigned size = Dst.size();
     SaveOr OldHasGen(Builder->HasGeneratedNode);
+    Pred = *DI;
 
     // Dispatch to transfer function logic to handle the call itself.
+    // FIXME: Allow us to chain together transfer functions.
     assert(Builder && "GRStmtNodeBuilder must be defined.");
+    ExplodedNodeSet DstTmp;
     
-    // FIXME: Allow us to chain together transfer functions.
-    Pred = *DI;
-
-    if (!EvalOSAtomic(Dst, *this, *Builder, CE, L, Pred))
-      getTF().EvalCall(Dst, *this, *Builder, CE, L, Pred);
+    if (!EvalOSAtomic(DstTmp, *this, *Builder, CE, L, Pred))
+      getTF().EvalCall(DstTmp, *this, *Builder, CE, L, Pred);
 
     // Handle the case where no nodes where generated.  Auto-generate that
     // contains the updated state if we aren't generating sinks.
-
-    if (!Builder->BuildSinks && Dst.size() == size &&
+    if (!Builder->BuildSinks && DstTmp.empty() &&
         !Builder->HasGeneratedNode)
-      MakeNode(Dst, CE, Pred, state);
+      MakeNode(DstTmp, CE, Pred, state);
+    
+    // Perform the post-condition check of the CallExpr.
+    CheckerVisit(CE, Dst, DstTmp, false);
   }
 }