]> granicus.if.org Git - clang/commitdiff
Fix bug when processing '?' operator: invalidate the old "Uninitialized" value of...
authorTed Kremenek <kremenek@apple.com>
Tue, 26 Feb 2008 23:37:01 +0000 (23:37 +0000)
committerTed Kremenek <kremenek@apple.com>
Tue, 26 Feb 2008 23:37:01 +0000 (23:37 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@47645 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 674454c7cd361254b6f612afc241bb6702a1023f..c911064b99f96237ddfe22c5fb8f7280361139b4 100644 (file)
@@ -40,7 +40,7 @@ GRExprEngine::SetRVal(StateTy St, Expr* Ex, const RVal& V) {
       return St;
   }
 
-  return StateMgr.SetRVal(St, Ex, isBlkExpr, V);
+  return StateMgr.SetRVal(St, Ex, V, isBlkExpr, false);
 }
 
 const GRExprEngine::StateTy::BufferTy&
@@ -606,7 +606,9 @@ void GRExprEngine::VisitGuardedExpr(Expr* Ex, Expr* L, Expr* R,
   assert (SE);
     
   X = GetBlkExprRVal(St, SE);
-  Nodify(Dst, Ex, Pred, SetBlkExprRVal(St, Ex, X));
+  
+  // Make sure that we invalidate the previous binding.
+  Nodify(Dst, Ex, Pred, StateMgr.SetRVal(St, Ex, X, true, true));
 }
 
 /// VisitSizeOfAlignOfTypeExpr - Transfer function for sizeof(type).
index 7be59ce5f5fa6100e0137249c57f3e9894353c48..97a090dad7031fde589c3f9da58b2a7719e7d0cb 100644 (file)
@@ -387,12 +387,27 @@ RVal ValueStateManager::GetLVal(ValueState St, Expr* E) {
 }
 
 ValueState 
-ValueStateManager::SetRVal(ValueState St, Expr* E, bool isBlkExpr, RVal V) {
+ValueStateManager::SetRVal(ValueState St, Expr* E, RVal V,
+                           bool isBlkExpr, bool Invalidate) {
   
   assert (E);
 
-  if (V.isUnknown())
+  if (V.isUnknown()) {
+    
+    if (Invalidate) {
+      
+      ValueStateImpl NewSt = *St;
+      
+      if (isBlkExpr)
+        NewSt.BlockExprBindings = EXFactory.Remove(NewSt.BlockExprBindings, E);
+      else
+        NewSt.SubExprBindings = EXFactory.Remove(NewSt.SubExprBindings, E);
+      
+      return getPersistentState(NewSt);
+    }
+  
     return St;
+  }
   
   ValueStateImpl NewSt = *St;
   
@@ -406,8 +421,8 @@ ValueStateManager::SetRVal(ValueState St, Expr* E, bool isBlkExpr, RVal V) {
   return getPersistentState(NewSt);
 }
 
-ValueState
-ValueStateManager::SetRVal(ValueState St, LVal LV, RVal V) {
+
+ValueState ValueStateManager::SetRVal(ValueState St, LVal LV, RVal V) {
   
   switch (LV.getSubKind()) {
       
index 3e0012287b69ea080a1ff643ad76bd9c6188cb5d..5458ab86e59ca4ee09fae30af9329a642b98ed6f 100644 (file)
@@ -255,7 +255,9 @@ public:
     return getPersistentState(NewSt);    
   }
   
-  ValueState SetRVal(ValueState St, Expr* E, bool isBlkExpr, RVal V);
+  ValueState SetRVal(ValueState St, Expr* E, RVal V,
+                     bool isBlkExpr, bool Invalidate);
+  
   ValueState SetRVal(ValueState St, LVal LV, RVal V);
 
   RVal GetRVal(ValueState St, Expr* E);
index 5c9092943bbdf9f8808506d53574ce9844359824..4945f3107afdcc7c83ce6af912e5d438c5f76f70 100644 (file)
@@ -243,7 +243,7 @@ protected:
   }
  
   StateTy SetBlkExprRVal(StateTy St, Expr* Ex, const RVal& V) {
-    return StateMgr.SetRVal(St, Ex, true, V);
+    return StateMgr.SetRVal(St, Ex, V, true, false);
   }
   
   /// SetRVal - This version of SetRVal is used to batch process a set