[cfe-commits] r60730 - in /cfe/trunk: include/clang/Analysis/Analyses/LiveVariables.h include/clang/Analysis/Analyses/UninitializedValues.h include/clang/Analysis/Support/BlkExprDeclBitVector.h lib/Analysis/LiveVariables.cpp

Ted Kremenek kremenek at apple.com
Mon Dec 8 16:14:14 PST 2008


Author: kremenek
Date: Mon Dec  8 18:14:14 2008
New Revision: 60730

URL: http://llvm.org/viewvc/llvm-project?rev=60730&view=rev
Log:
Fixed LiveVariables bug where we didn't consider block-level expressions that functioned as the size of a VLA to be live.

Modified:
    cfe/trunk/include/clang/Analysis/Analyses/LiveVariables.h
    cfe/trunk/include/clang/Analysis/Analyses/UninitializedValues.h
    cfe/trunk/include/clang/Analysis/Support/BlkExprDeclBitVector.h
    cfe/trunk/lib/Analysis/LiveVariables.cpp

Modified: cfe/trunk/include/clang/Analysis/Analyses/LiveVariables.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/Analyses/LiveVariables.h?rev=60730&r1=60729&r2=60730&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/Analyses/LiveVariables.h (original)
+++ cfe/trunk/include/clang/Analysis/Analyses/LiveVariables.h Mon Dec  8 18:14:14 2008
@@ -66,7 +66,7 @@
 public:
   typedef LiveVariables_ValueTypes::ObserverTy ObserverTy;
     
-  LiveVariables(CFG& cfg);
+  LiveVariables(ASTContext& Ctx, CFG& cfg);
   
   /// IsLive - Return true if a variable is live at beginning of a
   /// specified block.

Modified: cfe/trunk/include/clang/Analysis/Analyses/UninitializedValues.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/Analyses/UninitializedValues.h?rev=60730&r1=60729&r2=60730&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/Analyses/UninitializedValues.h (original)
+++ cfe/trunk/include/clang/Analysis/Analyses/UninitializedValues.h Mon Dec  8 18:14:14 2008
@@ -63,7 +63,7 @@
 public:
   typedef UninitializedValues_ValueTypes::ObserverTy ObserverTy;
 
-  UninitializedValues(CFG &cfg) { getAnalysisData().setCFG(&cfg); }
+  UninitializedValues(CFG &cfg) { getAnalysisData().setCFG(cfg); }
   
   /// IntializeValues - Create initial dataflow values and meta data for
   ///  a given CFG.  This is intended to be called by the dataflow solver.

Modified: cfe/trunk/include/clang/Analysis/Support/BlkExprDeclBitVector.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/Support/BlkExprDeclBitVector.h?rev=60730&r1=60729&r2=60730&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/Support/BlkExprDeclBitVector.h (original)
+++ cfe/trunk/include/clang/Analysis/Support/BlkExprDeclBitVector.h Mon Dec  8 18:14:14 2008
@@ -25,6 +25,7 @@
 namespace clang {
   
   class Stmt;
+  class ASTContext;
 
 struct DeclBitVector_Types {
   
@@ -170,12 +171,19 @@
   //===--------------------------------------------------------------------===//
 
   class AnalysisDataTy : public DeclBitVector_Types::AnalysisDataTy {
+    ASTContext* ctx;
     CFG* cfg;
   public:
-    AnalysisDataTy() {}
+    AnalysisDataTy() : ctx(0), cfg(0) {}
     virtual ~AnalysisDataTy() {}
 
-    void setCFG(CFG* c) { cfg = c; }
+    void setContext(ASTContext& c) { ctx = &c; }
+    ASTContext& getContext() {
+      assert(ctx && "ASTContext should not be NULL."); 
+      return *ctx;
+    }
+
+    void setCFG(CFG& c) { cfg = &c; }
     CFG& getCFG() { assert(cfg && "CFG should not be NULL."); return *cfg; }
     
     bool isTracked(const Stmt* S) { return cfg->isBlkExpr(S); }

Modified: cfe/trunk/lib/Analysis/LiveVariables.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/LiveVariables.cpp?rev=60730&r1=60729&r2=60730&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/LiveVariables.cpp (original)
+++ cfe/trunk/lib/Analysis/LiveVariables.cpp Mon Dec  8 18:14:14 2008
@@ -13,6 +13,7 @@
 
 #include "clang/Analysis/Analyses/LiveVariables.h"
 #include "clang/Basic/SourceManager.h"
+#include "clang/AST/ASTContext.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/CFG.h"
 #include "clang/Analysis/Visitors/CFGRecStmtDeclVisitor.h"
@@ -95,9 +96,11 @@
 } // end anonymous namespace
 
 
-LiveVariables::LiveVariables(CFG& cfg) {
+LiveVariables::LiveVariables(ASTContext& Ctx, CFG& cfg) {
   // Register all referenced VarDecls.
-  getAnalysisData().setCFG(&cfg);
+  getAnalysisData().setCFG(cfg);
+  getAnalysisData().setContext(Ctx);
+  
   RegisterDecls R(getAnalysisData());
   cfg.VisitBlockStmts(R);
 }
@@ -270,6 +273,13 @@
       if (Expr* Init = VD->getInit())
         Visit(Init);
       
+      if (const VariableArrayType* VT =
+            AD.getContext().getAsVariableArrayType(VD->getType())) {
+        StmtIterator I(const_cast<VariableArrayType*>(VT));
+        StmtIterator E;        
+        for (; I != E; ++I) Visit(*I);
+      }
+      
       // Update liveness information by killing the VarDecl.
       unsigned bit = AD.getIdx(VD);
       LiveState.getDeclBit(bit) = Dead | AD.AlwaysLive.getDeclBit(bit);





More information about the cfe-commits mailing list