]> granicus.if.org Git - clang/commitdiff
Bug fix: Don't call RemoveDeadBindings more than once (can kill newly generated value...
authorTed Kremenek <kremenek@apple.com>
Sun, 9 Mar 2008 03:30:59 +0000 (03:30 +0000)
committerTed Kremenek <kremenek@apple.com>
Sun, 9 Mar 2008 03:30:59 +0000 (03:30 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@48079 91177308-0d34-0410-b5e6-96231b3b80d8

Analysis/GRExprEngine.cpp
Analysis/RValues.cpp
Analysis/ValueState.cpp
include/clang/Analysis/PathSensitive/GRExprEngine.h
include/clang/Analysis/PathSensitive/RValues.h

index 3bf0151180804481fff25e54e8770ec660596fd0..b31f5e539f4320b436b7f5191c5f53ac9c8b5fd6 100644 (file)
@@ -92,6 +92,16 @@ ValueState* GRExprEngine::SetRVal(ValueState* St, LVal LV, RVal RV) {
   return StateMgr.SetRVal(St, LV, RV);
 }
 
+ValueState* GRExprEngine::SetBlkExprRVal(ValueState* St, Expr* Ex, RVal V) {
+  
+  if (!StateCleaned) {
+    St = RemoveDeadBindings(CurrentStmt, St);
+    StateCleaned = true;
+  }
+  
+  return StateMgr.SetRVal(St, Ex, V, true, false);
+}
+
 ValueState* GRExprEngine::MarkBranch(ValueState* St, Stmt* Terminator,
                                      bool branchTaken) {
   
@@ -420,7 +430,10 @@ void GRExprEngine::ProcessStmt(Stmt* S, StmtNodeBuilder& builder) {
   // dead mappings removed.
   
   if (Dst.size() == 1 && *Dst.begin() == StmtEntryNode) {
-    ValueState* St = RemoveDeadBindings(S, StmtEntryNode->getState());
+    ValueState* St =
+      StateCleaned ? StmtEntryNode->getState() : 
+                     RemoveDeadBindings(S, StmtEntryNode->getState());
+    
     builder.generateNode(S, St, StmtEntryNode);
   }
   
@@ -442,7 +455,9 @@ void GRExprEngine::VisitDeclRefExpr(DeclRefExpr* D, NodeTy* Pred, NodeSet& Dst){
   // it to the block-level expression.
   
   ValueState* St = Pred->getState();  
-  Nodify(Dst, D, Pred, SetRVal(St, D, GetRVal(St, D)));
+  RVal X = RVal::MakeVal(BasicVals, D);
+  RVal Y = isa<lval::DeclVal>(X) ? GetRVal(St, cast<lval::DeclVal>(X)) : X;
+  Nodify(Dst, D, Pred, SetBlkExprRVal(St, D, Y));
 }
 
 void GRExprEngine::VisitCall(CallExpr* CE, NodeTy* Pred,
@@ -1709,9 +1724,11 @@ struct VISIBILITY_HIDDEN DOTGraphTraits<GRExprEngine::NodeTy*> :
         Out << S->getStmtClassName() << ' ' << (void*) S << ' ';        
         S->printPretty(Out);
         
-        Out << "\\lline="
-          << GraphPrintSourceManager->getLineNumber(SLoc) << " col="
-          << GraphPrintSourceManager->getColumnNumber(SLoc) << "\\l";
+        if (SLoc.isFileID()) {        
+          Out << "\\lline="
+            << GraphPrintSourceManager->getLineNumber(SLoc) << " col="
+            << GraphPrintSourceManager->getColumnNumber(SLoc) << "\\l";          
+        }
         
         if (GraphPrintCheckerState->isImplicitNullDeref(N))
           Out << "\\|Implicit-Null Dereference.\\l";
@@ -1750,9 +1767,11 @@ struct VISIBILITY_HIDDEN DOTGraphTraits<GRExprEngine::NodeTy*> :
           
           E.getSrc()->printTerminator(Out);
           
-          Out << "\\lline="
-            << GraphPrintSourceManager->getLineNumber(SLoc) << " col="
-            << GraphPrintSourceManager->getColumnNumber(SLoc);
+          if (SLoc.isFileID()) {
+            Out << "\\lline="
+              << GraphPrintSourceManager->getLineNumber(SLoc) << " col="
+              << GraphPrintSourceManager->getColumnNumber(SLoc);
+          }
             
           if (isa<SwitchStmt>(T)) {
             Stmt* Label = E.getDst()->getLabel();
index 9d5bd683a6bc3ce61c4ee11050d0678d2d29c841..a4b464949aaf47e46148c8182ecf23f6ae1f869a 100644 (file)
@@ -237,6 +237,36 @@ RVal RVal::GetSymbolValue(SymbolManager& SymMgr, VarDecl* D) {
 
 LVal LVal::MakeVal(AddrLabelExpr* E) { return lval::GotoLabel(E->getLabel()); }
 
+//===----------------------------------------------------------------------===//
+// Utility methods for constructing RVals (both NonLVals and LVals).
+//===----------------------------------------------------------------------===//
+
+RVal RVal::MakeVal(BasicValueFactory& BasicVals, DeclRefExpr* E) {
+  
+  ValueDecl* D = cast<DeclRefExpr>(E)->getDecl();
+  
+  if (VarDecl* VD = dyn_cast<VarDecl>(D)) {
+    return lval::DeclVal(VD);
+  }
+  else if (EnumConstantDecl* ED = dyn_cast<EnumConstantDecl>(D)) {
+    
+    // FIXME: Do we need to cache a copy of this enum, since it
+    // already has persistent storage?  We do this because we
+    // are comparing states using pointer equality.  Perhaps there is
+    // a better way, since APInts are fairly lightweight.
+    
+    return nonlval::ConcreteInt(BasicVals.getValue(ED->getInitVal()));          
+  }
+  else if (FunctionDecl* FD = dyn_cast<FunctionDecl>(D)) {
+    return lval::FuncVal(FD);
+  }
+  
+  assert (false &&
+          "ValueDecl support for this ValueDecl not implemented.");
+  
+  return UnknownVal();
+}
+
 //===----------------------------------------------------------------------===//
 // Pretty-Printing.
 //===----------------------------------------------------------------------===//
index 4eb2a5eb540e1cbd33101e19d6882bbf63871bb8..4b097ee4a42cd4f7070bebcecde75a4f46c59c6d 100644 (file)
@@ -232,28 +232,14 @@ RVal ValueStateManager::GetRVal(ValueState* St, Expr* E) {
         // within the referenced variables.
         
       case Stmt::DeclRefExprClass: {
-        
-        ValueDecl* D = cast<DeclRefExpr>(E)->getDecl();
-        
-        if (VarDecl* VD = dyn_cast<VarDecl>(D)) {          
-          return GetRVal(St, lval::DeclVal(VD));          
-        }
-        else if (EnumConstantDecl* ED = dyn_cast<EnumConstantDecl>(D)) {
-          
-          // FIXME: Do we need to cache a copy of this enum, since it
-          // already has persistent storage?  We do this because we
-          // are comparing states using pointer equality.  Perhaps there is
-          // a better way, since APInts are fairly lightweight.
 
-          return nonlval::ConcreteInt(BasicVals.getValue(ED->getInitVal()));          
-        }
-        else if (FunctionDecl* FD = dyn_cast<FunctionDecl>(D))
-          return lval::FuncVal(FD);
-        
-        assert (false &&
-                "ValueDecl support for this ValueDecl not implemented.");
+        // Check if this expression is a block-level expression.  If so,
+        // return its value.
+        ValueState::ExprBindingsTy::TreeTy* T=St->BlockExprBindings.SlimFind(E);
+        if (T) return T->getValue().second;
         
-        return UnknownVal();
+        RVal X = RVal::MakeVal(BasicVals, cast<DeclRefExpr>(E));
+        return isa<lval::DeclVal>(X) ? GetRVal(St, cast<lval::DeclVal>(X)) : X;
       }
         
       case Stmt::CharacterLiteralClass: {
index 520c3732c852aedb06c6b2cd13f3b0f71301d1e8..37220ff5cd00055747beff446e8fa27bfeae457e 100644 (file)
@@ -275,17 +275,7 @@ protected:
     return SetRVal(St, const_cast<Expr*>(Ex), V);
   }
  
-  ValueState* SetBlkExprRVal(ValueState* St, Expr* Ex, RVal V) {
-    return StateMgr.SetRVal(St, Ex, V, true, false);
-  }
-  
-#if 0
-  /// SetRVal - This version of SetRVal is used to batch process a set
-  ///  of different possible RVals and return a set of different states.
-  const ValueState*::BufferTy& SetRVal(ValueState* St, Expr* Ex,
-                                       const RVal::BufferTy& V,
-                                       ValueState*::BufferTy& RetBuf);
-#endif
+  ValueState* SetBlkExprRVal(ValueState* St, Expr* Ex, RVal V);
   
   ValueState* SetRVal(ValueState* St, LVal LV, RVal V);
   
index eb632ed40519aec485df0f6d2f8be9a594d0d61d..dd99a2ee791eaccb959f53a6e4ec32f6daa64727 100644 (file)
@@ -90,6 +90,8 @@ public:
   symbol_iterator symbol_begin() const;
   symbol_iterator symbol_end() const;  
   
+  static RVal MakeVal(BasicValueFactory& BasicVals, DeclRefExpr* E);
+  
   // Implement isa<T> support.
   static inline bool classof(const RVal*) { return true; }
 };