]> granicus.if.org Git - clang/commitdiff
Flow-sensitive uninitialized values analysis:
authorTed Kremenek <kremenek@apple.com>
Tue, 11 Nov 2008 19:41:42 +0000 (19:41 +0000)
committerTed Kremenek <kremenek@apple.com>
Tue, 11 Nov 2008 19:41:42 +0000 (19:41 +0000)
- Added support for ObjCForCollectionStmt
- Fixed bug where expression values would be always set to uninitialized when loops were involved

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59076 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/UninitializedValues.cpp

index 60489023b26e068ad718f9370cc0ba7e464edbd6..3a84b2861acc66ac9a7328fdfc79f63a5aed1c3f 100644 (file)
@@ -64,7 +64,8 @@ public:
   CFG& getCFG() { return AD.getCFG(); }
   
   void SetTopValue(UninitializedValues::ValTy& X) {
-    X.resetValues(AD);
+    X.setDeclValues(AD);
+    X.resetExprValues(AD);
   }
     
   bool VisitDeclRefExpr(DeclRefExpr* DR);
@@ -74,6 +75,7 @@ public:
   bool VisitCallExpr(CallExpr* C);
   bool VisitDeclStmt(DeclStmt* D);
   bool VisitConditionalOperator(ConditionalOperator* C);
+  bool VisitObjCForCollectionStmt(ObjCForCollectionStmt* S);
   
   bool Visit(Stmt *S);
   bool BlockStmt_VisitExpr(Expr* E);
@@ -81,8 +83,8 @@ public:
   void VisitTerminator(CFGBlock* B) { }
 };
   
-static const bool Initialized = true;
-static const bool Uninitialized = false;  
+static const bool Initialized = false;
+static const bool Uninitialized = true;  
 
 bool TransferFuncs::VisitDeclRefExpr(DeclRefExpr* DR) {
   
@@ -178,6 +180,27 @@ bool TransferFuncs::VisitUnaryOperator(UnaryOperator* U) {
   return Visit(U->getSubExpr());
 }
   
+bool TransferFuncs::VisitObjCForCollectionStmt(ObjCForCollectionStmt* S) {
+  // This represents a use of the 'collection'
+  bool x = Visit(S->getCollection());
+
+  if (x == Uninitialized)
+    return Uninitialized;
+
+  // This represents an initialization of the 'element' value.
+  Stmt* Element = S->getElement();
+  VarDecl* VD = 0;
+
+  if (DeclStmt* DS = dyn_cast<DeclStmt>(Element))
+    VD = cast<VarDecl>(DS->getSolitaryDecl());
+  else
+    VD = cast<VarDecl>(cast<DeclRefExpr>(Element)->getDecl());
+
+  V(VD,AD) = Initialized;
+  return Initialized;
+}
+  
+  
 bool TransferFuncs::VisitConditionalOperator(ConditionalOperator* C) {
   Visit(C->getCond());
 
@@ -227,7 +250,7 @@ bool TransferFuncs::BlockStmt_VisitExpr(Expr* E) {
 //===----------------------------------------------------------------------===//      
 
 namespace {
-  typedef ExprDeclBitVector_Types::Intersect Merge;
+  typedef ExprDeclBitVector_Types::Union Merge;
   typedef DataflowSolver<UninitializedValues,TransferFuncs,Merge> Solver;
 }