[cfe-commits] r47982 - in /cfe/trunk: Analysis/CFRefCount.cpp Analysis/CFRefCount.h Driver/ASTConsumers.cpp Driver/ASTConsumers.h Driver/clang.cpp include/clang/Analysis/LocalCheckers.h

Ted Kremenek kremenek at apple.com
Wed Mar 5 16:08:10 PST 2008


Author: kremenek
Date: Wed Mar  5 18:08:09 2008
New Revision: 47982

URL: http://llvm.org/viewvc/llvm-project?rev=47982&view=rev
Log:
Added boilerplate to execute the CF reference count checker (which isn't yet implemented).

Added:
    cfe/trunk/Analysis/CFRefCount.cpp
    cfe/trunk/Analysis/CFRefCount.h
Modified:
    cfe/trunk/Driver/ASTConsumers.cpp
    cfe/trunk/Driver/ASTConsumers.h
    cfe/trunk/Driver/clang.cpp
    cfe/trunk/include/clang/Analysis/LocalCheckers.h

Added: cfe/trunk/Analysis/CFRefCount.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/CFRefCount.cpp?rev=47982&view=auto

==============================================================================
--- cfe/trunk/Analysis/CFRefCount.cpp (added)
+++ cfe/trunk/Analysis/CFRefCount.cpp Wed Mar  5 18:08:09 2008
@@ -0,0 +1,65 @@
+// CFRefCount.cpp - Transfer functions for tracking simple values -*- C++ -*--
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+//  This files defines the methods for CFRefCount, which implements
+//  a reference count checker for Core Foundation (Mac OS X).
+//
+//===----------------------------------------------------------------------===//
+
+#include "CFRefCount.h"
+#include "clang/Analysis/PathSensitive/ValueState.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Analysis/LocalCheckers.h"
+
+
+using namespace clang;
+
+
+namespace clang {
+  
+void CheckCFRefCount(CFG& cfg, FunctionDecl& FD, ASTContext& Ctx,
+                     Diagnostic& Diag) {
+  
+  if (Diag.hasErrorOccurred())
+    return;
+  
+  // FIXME: Refactor some day so this becomes a single function invocation.
+  
+  GRCoreEngine<GRExprEngine> Engine(cfg, FD, Ctx);
+  GRExprEngine* CS = &Engine.getCheckerState();
+  CFRefCount TF;
+  CS->setTransferFunctions(TF);
+  Engine.ExecuteWorkList(20000);
+  
+}
+  
+}
+
+void CFRefCount::EvalCall(ExplodedNodeSet<ValueState>& Dst,
+                            ValueStateManager& StateMgr,
+                            GRStmtNodeBuilder<ValueState>& Builder,
+                            ValueManager& ValMgr,
+                            CallExpr* CE, LVal L,
+                            ExplodedNode<ValueState>* Pred) {
+  
+  ValueState* St = Pred->getState();
+  
+  // Invalidate all arguments passed in by reference (LVals).
+
+  for (CallExpr::arg_iterator I = CE->arg_begin(), E = CE->arg_end();
+        I != E; ++I) {
+
+    RVal V = StateMgr.GetRVal(St, *I);
+    
+    if (isa<LVal>(V))
+      St = StateMgr.SetRVal(St, cast<LVal>(V), UnknownVal());
+  }
+    
+  Builder.Nodify(Dst, CE, Pred, St);
+}

Added: cfe/trunk/Analysis/CFRefCount.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/CFRefCount.h?rev=47982&view=auto

==============================================================================
--- cfe/trunk/Analysis/CFRefCount.h (added)
+++ cfe/trunk/Analysis/CFRefCount.h Wed Mar  5 18:08:09 2008
@@ -0,0 +1,39 @@
+// CFRefCount.h - Transfer functions for the CF Ref. Count checker -*- C++ -*---
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+//  This files defines CFRefCount, which defines the transfer functions
+//  to implement the Core Foundation reference count checker.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_ANALYSIS_GRREFCOUNT
+#define LLVM_CLANG_ANALYSIS_GRREFCOUNT
+
+#include "GRSimpleVals.h"
+
+namespace clang {
+  
+class CFRefCount : public GRSimpleVals {
+public:
+  CFRefCount() {}
+  virtual ~CFRefCount() {}
+    
+  // Calls.
+  
+  virtual void EvalCall(ExplodedNodeSet<ValueState>& Dst,
+                        ValueStateManager& StateMgr,
+                        GRStmtNodeBuilder<ValueState>& Builder,
+                        ValueManager& ValMgr,
+                        CallExpr* CE, LVal L,
+                        ExplodedNode<ValueState>* Pred);  
+};
+  
+} // end clang namespace
+
+#endif

Modified: cfe/trunk/Driver/ASTConsumers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/ASTConsumers.cpp?rev=47982&r1=47981&r2=47982&view=diff

==============================================================================
--- cfe/trunk/Driver/ASTConsumers.cpp (original)
+++ cfe/trunk/Driver/ASTConsumers.cpp Wed Mar  5 18:08:09 2008
@@ -636,6 +636,43 @@
   }    
 }
 
+
+//===----------------------------------------------------------------------===//
+// Core Foundation Reference Counting Checker
+
+namespace {
+  class CFRefCountCheckerVisitor : public CFGVisitor {
+    Diagnostic &Diags;
+    ASTContext* Ctx;
+    
+  public:
+    CFRefCountCheckerVisitor(Diagnostic &diags, const std::string& fname)
+      : CFGVisitor(fname), Diags(diags) {}
+    
+    virtual void Initialize(ASTContext &Context) { Ctx = &Context; }    
+    virtual void VisitCFG(CFG& C, FunctionDecl&);
+    virtual bool printFuncDeclStart() { return false; }
+  };
+} // end anonymous namespace
+
+
+ASTConsumer* clang::CreateCFRefChecker(Diagnostic &Diags,
+                                       const std::string& FunctionName) {
+  
+  return new CFRefCountCheckerVisitor(Diags, FunctionName);
+}
+
+void CFRefCountCheckerVisitor::VisitCFG(CFG& C, FunctionDecl& FD) {
+  
+  SourceLocation Loc = FD.getLocation();
+  
+  if (!Loc.isFileID() ||
+      Loc.getFileID() != Ctx->getSourceManager().getMainFileID())
+    return;
+     
+  CheckCFRefCount(C, FD, *Ctx, Diags);
+}
+
 //===----------------------------------------------------------------------===//
 // AST Serializer
 

Modified: cfe/trunk/Driver/ASTConsumers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/ASTConsumers.h?rev=47982&r1=47981&r2=47982&view=diff

==============================================================================
--- cfe/trunk/Driver/ASTConsumers.h (original)
+++ cfe/trunk/Driver/ASTConsumers.h Wed Mar  5 18:08:09 2008
@@ -45,6 +45,9 @@
 ASTConsumer *CreateGRSimpleVals(Diagnostic &Diags,
                                 const std::string& Function,
                                 bool Visualize = false);
+  
+ASTConsumer* CreateCFRefChecker(Diagnostic &Diags,
+                                const std::string& FunctionName); 
 
 ASTConsumer *CreateCodeRewriterTest(const std::string& InFile,
                                     Diagnostic &Diags);

Modified: cfe/trunk/Driver/clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/clang.cpp?rev=47982&r1=47981&r2=47982&view=diff

==============================================================================
--- cfe/trunk/Driver/clang.cpp (original)
+++ cfe/trunk/Driver/clang.cpp Wed Mar  5 18:08:09 2008
@@ -71,6 +71,7 @@
   AnalysisLiveVariables,        // Print results of live-variable analysis.
   AnalysisGRSimpleVals,         // Perform graph-reachability constant prop.
   AnalysisGRSimpleValsView,     // Visualize results of path-sens. analysis.
+  CheckerCFRef,                 // Run the Core Foundation Ref. Count Checker.
   WarnDeadStores,               // Run DeadStores checker on parsed ASTs.
   WarnDeadStoresCheck,          // Check diagnostics for "DeadStores".
   WarnUninitVals,               // Run UnitializedVariables checker.
@@ -119,6 +120,8 @@
                         "Perform path-sensitive constant propagation."),
              clEnumValN(AnalysisGRSimpleValsView, "grsimple-view",
                         "View results of path-sensitive constant propagation."),
+             clEnumValN(CheckerCFRef, "check-cfref",
+                        "Run the Core Foundation reference count checker."),
              clEnumValN(TestSerialization, "test-pickling",
                         "Run prototype serializtion code."),
              clEnumValN(EmitLLVM, "emit-llvm",
@@ -1038,6 +1041,9 @@
     case AnalysisGRSimpleValsView:
       return CreateGRSimpleVals(Diag, AnalyzeSpecificFunction, true);
       
+    case CheckerCFRef:
+      return CreateCFRefChecker(Diag, AnalyzeSpecificFunction);
+      
     case TestSerialization:
       return CreateSerializationTest(Diag, FileMgr, LangOpts);
       

Modified: cfe/trunk/include/clang/Analysis/LocalCheckers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/LocalCheckers.h?rev=47982&r1=47981&r2=47982&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/LocalCheckers.h (original)
+++ cfe/trunk/include/clang/Analysis/LocalCheckers.h Wed Mar  5 18:08:09 2008
@@ -27,7 +27,9 @@
   
 void CheckUninitializedValues(CFG& cfg, ASTContext& Ctx, Diagnostic& Diags,
                               bool FullUninitTaint=false);
-
+  
+void CheckCFRefCount(CFG& cfg, FunctionDecl& FD, ASTContext& Ctx,
+                     Diagnostic& Diag);
 
 } // end namespace clang
 





More information about the cfe-commits mailing list