]> granicus.if.org Git - clang/commitdiff
Some cleanups around the uninitialized variables warning, and a FIXME. No functional...
authorRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 24 May 2012 23:45:35 +0000 (23:45 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 24 May 2012 23:45:35 +0000 (23:45 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@157440 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/UninitializedValues.cpp
lib/Sema/AnalysisBasedWarnings.cpp

index 4e2d003778005d8f1fbb56895eb1a24115874d1e..c1b9a96f03a4187abc7d742398b4f0a102503e76 100644 (file)
@@ -112,7 +112,7 @@ public:
   
   void computeSetOfDeclarations(const DeclContext &dc);  
   ValueVector &getValueVector(const CFGBlock *block,
-                                const CFGBlock *dstBlock);
+                              const CFGBlock *dstBlock);
 
   BVPair &getValueVectors(const CFGBlock *block, bool shouldLazyCreate);
 
@@ -363,8 +363,7 @@ public:
       lastDR(0), lastLoad(0),
       skipProcessUses(false) {}
   
-  void reportUninit(const DeclRefExpr *ex, const VarDecl *vd,
-                    bool isAlwaysUninit);
+  void reportUse(const Expr *ex, const VarDecl *vd);
 
   void VisitBlockExpr(BlockExpr *be);
   void VisitDeclStmt(DeclStmt *ds);
@@ -399,9 +398,12 @@ static const Expr *stripCasts(ASTContext &C, const Expr *Ex) {
   return Ex;
 }
 
-void TransferFunctions::reportUninit(const DeclRefExpr *ex,
-                                     const VarDecl *vd, bool isAlwaysUnit) {
-  if (handler) handler->handleUseOfUninitVariable(ex, vd, isAlwaysUnit);
+void TransferFunctions::reportUse(const Expr *ex, const VarDecl *vd) {
+  if (!handler)
+    return;
+  Value v = vals[vd];
+  if (isUninitialized(v))
+    handler->handleUseOfUninitVariable(ex, vd, isAlwaysUninit(v));
 }
 
 FindVarResult TransferFunctions::findBlockVarDecl(Expr *ex) {
@@ -442,9 +444,7 @@ void TransferFunctions::VisitBlockExpr(BlockExpr *be) {
       vals[vd] = Initialized;
       continue;
     }
-    Value v = vals[vd];
-    if (handler && isUninitialized(v))
-      handler->handleUseOfUninitVariable(be, vd, isAlwaysUninit(v));
+    reportUse(be, vd);
   }
 }
 
@@ -507,13 +507,10 @@ void TransferFunctions::VisitBinaryOperator(clang::BinaryOperator *bo) {
   if (bo->isAssignmentOp()) {
     const FindVarResult &res = findBlockVarDecl(bo->getLHS());
     if (const VarDecl *vd = res.getDecl()) {
-      ValueVector::reference val = vals[vd];
-      if (isUninitialized(val)) {
-        if (bo->getOpcode() != BO_Assign)
-          reportUninit(res.getDeclRefExpr(), vd, isAlwaysUninit(val));
-        else
-          val = Initialized;
-      }
+      if (bo->getOpcode() != BO_Assign)
+        reportUse(res.getDeclRefExpr(), vd);
+      else
+        vals[vd] = Initialized;
     }
   }
 }
@@ -530,10 +527,7 @@ void TransferFunctions::VisitUnaryOperator(clang::UnaryOperator *uo) {
         // We null out lastDR to indicate we have fully processed it
         // and we don't want the auto-value setting in Visit().
         lastDR = 0;
-
-        ValueVector::reference val = vals[vd];
-        if (isUninitialized(val))
-          reportUninit(res.getDeclRefExpr(), vd, isAlwaysUninit(val));
+        reportUse(res.getDeclRefExpr(), vd);
       }
       break;
     }
@@ -592,8 +586,7 @@ void TransferFunctions::ProcessUses(Stmt *s) {
     // If we reach here, we may have seen a load of an uninitialized value
     // and it hasn't been casted to void or otherwise handled.  In this
     // situation, report the incident.
-    if (isUninitialized(vals[VD]))
-      reportUninit(DR, VD, isAlwaysUninit(vals[VD]));
+    reportUse(DR, VD);
 
     lastLoad = 0;
 
@@ -680,6 +673,9 @@ void clang::runUninitializedVariablesAnalysis(
   vals.computeSetOfDeclarations(dc);
   if (vals.hasNoDeclarations())
     return;
+#if 0
+  cfg.dump(dc.getParentASTContext().getLangOpts(), true);
+#endif
 
   stats.NumVariablesAnalyzed = vals.getNumEntries();
 
index e602ef1a23e985dc2e5965032d9ea4a4564256a3..01deec1975923ed20052415ae52eca90b7487fc5 100644 (file)
@@ -748,6 +748,8 @@ public:
     if (!uses)
       return;
     
+    // FIXME: This iteration order, and thus the resulting diagnostic order,
+    //        is nondeterministic.
     for (UsesMap::iterator i = uses->begin(), e = uses->end(); i != e; ++i) {
       const VarDecl *vd = i->first;
       const UsesMap::mapped_type &V = i->second;