[cfe-commits] r47137 - in /cfe/trunk: Analysis/GRExprEngine.cpp Analysis/GRSimpleVals.cpp Analysis/GRSimpleVals.h Driver/ASTConsumers.cpp Driver/ASTConsumers.h Driver/clang.cpp include/clang/Analysis/Analyses/GRConstants.h include/clang/Analysis/Analyses/GRSimpleVals.h include/clang/Analysis/PathSensitive/GRExprEngine.h

Ted Kremenek kremenek at apple.com
Thu Feb 14 14:36:50 PST 2008


Author: kremenek
Date: Thu Feb 14 16:36:46 2008
New Revision: 47137

URL: http://llvm.org/viewvc/llvm-project?rev=47137&view=rev
Log:
Renamed GRConstants => GRSimpleVals.
Moved driver logic for --grsimple to GRSimpleVals.cpp.

Added:
    cfe/trunk/include/clang/Analysis/Analyses/GRSimpleVals.h
Removed:
    cfe/trunk/include/clang/Analysis/Analyses/GRConstants.h
Modified:
    cfe/trunk/Analysis/GRExprEngine.cpp
    cfe/trunk/Analysis/GRSimpleVals.cpp
    cfe/trunk/Analysis/GRSimpleVals.h
    cfe/trunk/Driver/ASTConsumers.cpp
    cfe/trunk/Driver/ASTConsumers.h
    cfe/trunk/Driver/clang.cpp
    cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h

Modified: cfe/trunk/Analysis/GRExprEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/GRExprEngine.cpp?rev=47137&r1=47136&r2=47137&view=diff

==============================================================================
--- cfe/trunk/Analysis/GRExprEngine.cpp (original)
+++ cfe/trunk/Analysis/GRExprEngine.cpp Thu Feb 14 16:36:46 2008
@@ -14,7 +14,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "clang/Analysis/PathSensitive/GRExprEngine.h"
-#include "GRSimpleVals.h"
+#include "clang/Analysis/PathSensitive/GRTransferFuncs.h"
+
+#include "llvm/Support/Streams.h"
 
 using namespace clang;
 using llvm::dyn_cast;
@@ -1004,7 +1006,7 @@
 }
 
 //===----------------------------------------------------------------------===//
-// Driver.
+// Visualization.
 //===----------------------------------------------------------------------===//
 
 #ifndef NDEBUG
@@ -1210,36 +1212,10 @@
 } // end llvm namespace    
 #endif
 
-namespace clang {
-void RunGRConstants(CFG& cfg, FunctionDecl& FD, ASTContext& Ctx,
-                    Diagnostic& Diag) {
-  
-  GRCoreEngine<GRExprEngine> Engine(cfg, FD, Ctx);
-  GRExprEngine* CheckerState = &Engine.getCheckerState();
-  GRSimpleVals GRSV;
-  CheckerState->setTransferFunctions(GRSV);
-  
-  // Execute the worklist algorithm.
-  Engine.ExecuteWorkList();
-  
-  // Look for explicit-Null dereferences and warn about them.
-
-  
-  for (GRExprEngine::null_iterator I=CheckerState->null_begin(),
-                                  E=CheckerState->null_end(); I!=E; ++I) {
-    
-    const PostStmt& L = cast<PostStmt>((*I)->getLocation());
-    Expr* E = cast<Expr>(L.getStmt());
-    
-    Diag.Report(FullSourceLoc(E->getExprLoc(), Ctx.getSourceManager()),
-                diag::chkr_null_deref_after_check);
-  }
-  
-  
+void GRExprEngine::ViewGraph() {
 #ifndef NDEBUG
-  GraphPrintCheckerState = CheckerState;
-  llvm::ViewGraph(*Engine.getGraph().roots_begin(),"GRExprEngine");
+  GraphPrintCheckerState = this;
+  llvm::ViewGraph(*G.roots_begin(), "GRExprEngine");
   GraphPrintCheckerState = NULL;
-#endif  
+#endif
 }
-} // end clang namespace

Modified: cfe/trunk/Analysis/GRSimpleVals.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/GRSimpleVals.cpp?rev=47137&r1=47136&r2=47137&view=diff

==============================================================================
--- cfe/trunk/Analysis/GRSimpleVals.cpp (original)
+++ cfe/trunk/Analysis/GRSimpleVals.cpp Thu Feb 14 16:36:46 2008
@@ -14,9 +14,39 @@
 //===----------------------------------------------------------------------===//
 
 #include "GRSimpleVals.h"
+#include "clang/Basic/Diagnostic.h"
 
 using namespace clang;
 
+namespace clang {
+  void RunGRSimpleVals(CFG& cfg, FunctionDecl& FD, ASTContext& Ctx,
+                      Diagnostic& Diag) {
+    
+    GRCoreEngine<GRExprEngine> Engine(cfg, FD, Ctx);
+    GRExprEngine* CheckerState = &Engine.getCheckerState();
+    GRSimpleVals GRSV;
+    CheckerState->setTransferFunctions(GRSV);
+    
+    // Execute the worklist algorithm.
+    Engine.ExecuteWorkList();
+    
+    // Look for explicit-Null dereferences and warn about them.
+    for (GRExprEngine::null_iterator I=CheckerState->null_begin(),
+         E=CheckerState->null_end(); I!=E; ++I) {
+      
+      const PostStmt& L = cast<PostStmt>((*I)->getLocation());
+      Expr* E = cast<Expr>(L.getStmt());
+      
+      Diag.Report(FullSourceLoc(E->getExprLoc(), Ctx.getSourceManager()),
+                  diag::chkr_null_deref_after_check);
+    }
+        
+#ifndef NDEBUG
+    CheckerState->ViewGraph();
+#endif  
+  }
+} // end clang namespace
+
 //===----------------------------------------------------------------------===//
 // Transfer function for Casts.
 //===----------------------------------------------------------------------===//

Modified: cfe/trunk/Analysis/GRSimpleVals.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/GRSimpleVals.h?rev=47137&r1=47136&r2=47137&view=diff

==============================================================================
--- cfe/trunk/Analysis/GRSimpleVals.h (original)
+++ cfe/trunk/Analysis/GRSimpleVals.h Thu Feb 14 16:36:46 2008
@@ -17,6 +17,7 @@
 #define LLVM_CLANG_ANALYSIS_GRSIMPLEVALS
 
 #include "clang/Analysis/PathSensitive/GRTransferFuncs.h"
+#include "clang/Analysis/PathSensitive/GRExprEngine.h"
 
 namespace clang {
   

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

==============================================================================
--- cfe/trunk/Driver/ASTConsumers.cpp (original)
+++ cfe/trunk/Driver/ASTConsumers.cpp Thu Feb 14 16:36:46 2008
@@ -20,7 +20,7 @@
 #include "clang/AST/ASTConsumer.h"
 #include "clang/AST/CFG.h"
 #include "clang/Analysis/Analyses/LiveVariables.h"
-#include "clang/Analysis/Analyses/GRConstants.h"
+#include "clang/Analysis/Analyses/GRSimpleVals.h"
 #include "clang/Analysis/LocalCheckers.h"
 #include "llvm/Support/Streams.h"
 using namespace clang;
@@ -574,26 +574,26 @@
 }
 
 //===----------------------------------------------------------------------===//
-// GRConstants - Perform intra-procedural, path-sensitive constant propagation.
+// GRSimpleVals - Perform intra-procedural, path-sensitive constant propagation.
 
 namespace {
-  class GRConstantsVisitor : public CFGVisitor {
+  class GRSimpleValsVisitor : public CFGVisitor {
     Diagnostic &Diags;
     ASTContext* Ctx;
   public:
-    GRConstantsVisitor(Diagnostic &diags) : Diags(diags) {}
+    GRSimpleValsVisitor(Diagnostic &diags) : Diags(diags) {}
     
     virtual void Initialize(ASTContext &Context) { Ctx = &Context; }    
     virtual void VisitCFG(CFG& C, FunctionDecl&);
   };
 } // end anonymous namespace
 
-ASTConsumer* clang::CreateGRConstants(Diagnostic &Diags) {
-  return new GRConstantsVisitor(Diags);
+ASTConsumer* clang::CreateGRSimpleVals(Diagnostic &Diags) {
+  return new GRSimpleValsVisitor(Diags);
 }
 
-void GRConstantsVisitor::VisitCFG(CFG& C, FunctionDecl& FD) {
-  RunGRConstants(C, FD, *Ctx, Diags);
+void GRSimpleValsVisitor::VisitCFG(CFG& C, FunctionDecl& FD) {
+  RunGRSimpleVals(C, FD, *Ctx, Diags);
 }
 
 //===----------------------------------------------------------------------===//

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

==============================================================================
--- cfe/trunk/Driver/ASTConsumers.h (original)
+++ cfe/trunk/Driver/ASTConsumers.h Thu Feb 14 16:36:46 2008
@@ -41,7 +41,7 @@
 
 ASTConsumer *CreateUnitValsChecker(Diagnostic &Diags);
   
-ASTConsumer *CreateGRConstants(Diagnostic &Diags);
+ASTConsumer *CreateGRSimpleVals(Diagnostic &Diags);
 
 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=47137&r1=47136&r2=47137&view=diff

==============================================================================
--- cfe/trunk/Driver/clang.cpp (original)
+++ cfe/trunk/Driver/clang.cpp Thu Feb 14 16:36:46 2008
@@ -68,7 +68,7 @@
   ParseCFGDump,                 // Parse ASTS. Build CFGs. Print CFGs.
   ParseCFGView,                 // Parse ASTS. Build CFGs. View CFGs.
   AnalysisLiveVariables,        // Print results of live-variable analysis.
-  AnalysisGRConstants,          // Perform graph-reachability constant prop.
+  AnalysisGRSimpleVals,          // Perform graph-reachability constant prop.
   WarnDeadStores,               // Run DeadStores checker on parsed ASTs.
   WarnDeadStoresCheck,          // Check diagnostics for "DeadStores".
   WarnUninitVals,               // Run UnitializedVariables checker.
@@ -113,7 +113,7 @@
                         "Flag warnings of stores to dead variables."),
              clEnumValN(WarnUninitVals, "warn-uninit-values",
                         "Flag warnings of uses of unitialized variables."),
-             clEnumValN(AnalysisGRConstants, "grconstants",
+             clEnumValN(AnalysisGRSimpleVals, "grsimple",
                         "Perform path-sensitive constant propagation."),
              clEnumValN(TestSerialization, "test-pickling",
                         "Run prototype serializtion code."),
@@ -971,8 +971,8 @@
     case WarnUninitVals:
       return CreateUnitValsChecker(Diag);
       
-    case AnalysisGRConstants:
-      return CreateGRConstants(Diag);
+    case AnalysisGRSimpleVals:
+      return CreateGRSimpleVals(Diag);
       
     case TestSerialization:
       return CreateSerializationTest(Diag, FileMgr, LangOpts);

Removed: cfe/trunk/include/clang/Analysis/Analyses/GRConstants.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/Analyses/GRConstants.h?rev=47136&view=auto

==============================================================================
--- cfe/trunk/include/clang/Analysis/Analyses/GRConstants.h (original)
+++ cfe/trunk/include/clang/Analysis/Analyses/GRConstants.h (removed)
@@ -1,33 +0,0 @@
-//===-- GRConstants.h- Simple, Path-Sens. Constant Prop. ---------*- C++ -*-==//
-//   
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-//               Constant Propagation via Graph Reachability
-//
-//  This files defines the interface to use the 'GRConstants' path-sensitive
-//  constant-propagation analysis.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_CLANG_GRCONSTANTS
-#define LLVM_CLANG_GRCONSTANTS
-
-namespace clang {
-  class Diagnostic;
-  
-  /// RunGRConstants - This is a simple driver to run the GRConstants analysis
-  ///  on a provided CFG.  This interface will eventually be replaced with
-  ///  something more elaborate as the requirements on the interface become
-  ///  clearer.
-  void RunGRConstants(CFG& cfg, FunctionDecl& FD, ASTContext& Ctx,
-                      Diagnostic& Diag);
-  
-} // end clang namespace
-
-
-#endif

Added: cfe/trunk/include/clang/Analysis/Analyses/GRSimpleVals.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/Analyses/GRSimpleVals.h?rev=47137&view=auto

==============================================================================
--- cfe/trunk/include/clang/Analysis/Analyses/GRSimpleVals.h (added)
+++ cfe/trunk/include/clang/Analysis/Analyses/GRSimpleVals.h Thu Feb 14 16:36:46 2008
@@ -0,0 +1,33 @@
+//===-- GRSimpleVals.h- Simple, Path-Sens. Constant Prop. ---------*- C++ -*-==//
+//   
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+//               Constant Propagation via Graph Reachability
+//
+//  This files defines the interface to use the 'GRSimpleVals' path-sensitive
+//  constant-propagation analysis.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_GRCONSTANTS
+#define LLVM_CLANG_GRCONSTANTS
+
+namespace clang {
+  class Diagnostic;
+  
+  /// RunGRSimpleVals - This is a simple driver to run the GRSimpleVals analysis
+  ///  on a provided CFG.  This interface will eventually be replaced with
+  ///  something more elaborate as the requirements on the interface become
+  ///  clearer.
+  void RunGRSimpleVals(CFG& cfg, FunctionDecl& FD, ASTContext& Ctx,
+                      Diagnostic& Diag);
+  
+} // end clang namespace
+
+
+#endif

Modified: cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h?rev=47137&r1=47136&r2=47137&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h Thu Feb 14 16:36:46 2008
@@ -17,7 +17,6 @@
 
 #include "clang/Analysis/PathSensitive/GRCoreEngine.h"
 #include "clang/Analysis/PathSensitive/GRTransferFuncs.h"
-#include "GRSimpleVals.h"
 
 #include "clang/AST/Expr.h"
 #include "clang/AST/ASTContext.h"
@@ -33,7 +32,6 @@
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/Support/Allocator.h"
 #include "llvm/Support/Compiler.h"
-#include "llvm/Support/Streams.h"
 
 #include <functional>
 
@@ -150,6 +148,10 @@
   void setTransferFunctions(GRTransferFuncs* tf) { TF = tf; }
   void setTransferFunctions(GRTransferFuncs& tf) { TF = &tf; }
   
+  /// ViewGraph - Visualize the ExplodedGraph created by executing the
+  ///  simulation.
+  void ViewGraph();
+  
   /// getInitialState - Return the initial state used for the root vertex
   ///  in the ExplodedGraph.
   StateTy getInitialState() {





More information about the cfe-commits mailing list