[cfe-commits] r112306 - in /cfe/trunk: include/clang/Analysis/Analyses/LiveVariables.h include/clang/Analysis/AnalysisContext.h lib/Analysis/AnalysisContext.cpp lib/Analysis/LiveVariables.cpp

Tom Care tcare at apple.com
Fri Aug 27 15:30:10 PDT 2010


Author: tcare
Date: Fri Aug 27 17:30:10 2010
New Revision: 112306

URL: http://llvm.org/viewvc/llvm-project?rev=112306&view=rev
Log:
Add alternate version of LiveVariables analysis that does not kill liveness at assignments. This 'relaxed' liveness is useful in path sensitive analysis for situations where the resulting extended liveness allows us to find some bugs.
- Added killAtAssign flag to LiveVariables
- Added relaxed LiveVariables to AnalysisContext with an accessor

Modified:
    cfe/trunk/include/clang/Analysis/Analyses/LiveVariables.h
    cfe/trunk/include/clang/Analysis/AnalysisContext.h
    cfe/trunk/lib/Analysis/AnalysisContext.cpp
    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=112306&r1=112305&r2=112306&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/Analyses/LiveVariables.h (original)
+++ cfe/trunk/include/clang/Analysis/Analyses/LiveVariables.h Fri Aug 27 17:30:10 2010
@@ -41,8 +41,9 @@
     ObserverTy* Observer;
     ValTy AlwaysLive;
     AnalysisContext *AC;
+    bool killAtAssign;
 
-    AnalysisDataTy() : Observer(NULL), AC(NULL) {}
+    AnalysisDataTy() : Observer(NULL), AC(NULL), killAtAssign(true) {}
   };
 
   //===-----------------------------------------------------===//
@@ -68,7 +69,7 @@
 public:
   typedef LiveVariables_ValueTypes::ObserverTy ObserverTy;
 
-  LiveVariables(AnalysisContext &AC);
+  LiveVariables(AnalysisContext &AC, bool killAtAssign = true);
 
   /// IsLive - Return true if a variable is live at the end of a
   /// specified block.

Modified: cfe/trunk/include/clang/Analysis/AnalysisContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/AnalysisContext.h?rev=112306&r1=112305&r2=112306&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/AnalysisContext.h (original)
+++ cfe/trunk/include/clang/Analysis/AnalysisContext.h Fri Aug 27 17:30:10 2010
@@ -49,6 +49,7 @@
   CFG *cfg, *completeCFG;
   bool builtCFG, builtCompleteCFG;
   LiveVariables *liveness;
+  LiveVariables *relaxedLiveness;
   ParentMap *PM;
   PseudoConstantAnalysis *PCA;
   llvm::DenseMap<const BlockDecl*,void*> *ReferencedBlockVars;
@@ -61,7 +62,7 @@
                   bool addehedges = false)
     : D(d), TU(tu), cfg(0), completeCFG(0),
       builtCFG(false), builtCompleteCFG(false),
-      liveness(0), PM(0), PCA(0),
+      liveness(0), relaxedLiveness(0), PM(0), PCA(0),
       ReferencedBlockVars(0), UseUnoptimizedCFG(useUnoptimizedCFG),
       AddEHEdges(addehedges) {}
 
@@ -89,6 +90,7 @@
   ParentMap &getParentMap();
   PseudoConstantAnalysis *getPseudoConstantAnalysis();
   LiveVariables *getLiveVariables();
+  LiveVariables *getRelaxedLiveVariables();
 
   typedef const VarDecl * const * referenced_decls_iterator;
 

Modified: cfe/trunk/lib/Analysis/AnalysisContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/AnalysisContext.cpp?rev=112306&r1=112305&r2=112306&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/AnalysisContext.cpp (original)
+++ cfe/trunk/lib/Analysis/AnalysisContext.cpp Fri Aug 27 17:30:10 2010
@@ -104,6 +104,20 @@
   return liveness;
 }
 
+LiveVariables *AnalysisContext::getRelaxedLiveVariables() {
+  if (!relaxedLiveness) {
+    CFG *c = getCFG();
+    if (!c)
+      return 0;
+
+    relaxedLiveness = new LiveVariables(*this, false);
+    relaxedLiveness->runOnCFG(*c);
+    relaxedLiveness->runOnAllBlocks(*c, 0, true);
+  }
+
+  return relaxedLiveness;
+}
+
 AnalysisContext *AnalysisContextManager::getContext(const Decl *D,
                                                     idx::TranslationUnit *TU) {
   AnalysisContext *&AC = Contexts[D];

Modified: cfe/trunk/lib/Analysis/LiveVariables.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/LiveVariables.cpp?rev=112306&r1=112305&r2=112306&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/LiveVariables.cpp (original)
+++ cfe/trunk/lib/Analysis/LiveVariables.cpp Fri Aug 27 17:30:10 2010
@@ -77,12 +77,13 @@
 };
 } // end anonymous namespace
 
-LiveVariables::LiveVariables(AnalysisContext &AC) {  
+LiveVariables::LiveVariables(AnalysisContext &AC, bool killAtAssign) {
   // Register all referenced VarDecls.
   CFG &cfg = *AC.getCFG();
   getAnalysisData().setCFG(cfg);
   getAnalysisData().setContext(AC.getASTContext());
   getAnalysisData().AC = &AC;
+  getAnalysisData().killAtAssign = killAtAssign;
 
   RegisterDecls R(getAnalysisData());
   cfg.VisitBlockStmts(R);
@@ -260,12 +261,13 @@
     if (DR->getDecl()->getType()->isReferenceType()) {
       VisitDeclRefExpr(DR);
     } else {
-      // Update liveness inforamtion.
-      unsigned bit = AD.getIdx(DR->getDecl());
-      LiveState.getDeclBit(bit) = Dead | AD.AlwaysLive.getDeclBit(bit);
-
-      if (AD.Observer) { AD.Observer->ObserverKill(DR); }
+      if (AD.killAtAssign) {
+        // Update liveness inforamtion.
+        unsigned bit = AD.getIdx(DR->getDecl());
+        LiveState.getDeclBit(bit) = Dead | AD.AlwaysLive.getDeclBit(bit);
 
+        if (AD.Observer) { AD.Observer->ObserverKill(DR); }
+      }
       // Handle things like +=, etc., which also generate "uses"
       // of a variable.  Do this just by visiting the subexpression.
       if (B->getOpcode() != BO_Assign)





More information about the cfe-commits mailing list