[cfe-commits] r157440 - in /cfe/trunk/lib: Analysis/UninitializedValues.cpp Sema/AnalysisBasedWarnings.cpp

Richard Smith richard-llvm at metafoo.co.uk
Thu May 24 16:45:36 PDT 2012


Author: rsmith
Date: Thu May 24 18:45:35 2012
New Revision: 157440

URL: http://llvm.org/viewvc/llvm-project?rev=157440&view=rev
Log:
Some cleanups around the uninitialized variables warning, and a FIXME. No functional change.

Modified:
    cfe/trunk/lib/Analysis/UninitializedValues.cpp
    cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp

Modified: cfe/trunk/lib/Analysis/UninitializedValues.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/UninitializedValues.cpp?rev=157440&r1=157439&r2=157440&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/UninitializedValues.cpp (original)
+++ cfe/trunk/lib/Analysis/UninitializedValues.cpp Thu May 24 18:45:35 2012
@@ -112,7 +112,7 @@
   
   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 @@
       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 @@
   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 @@
       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 @@
   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 @@
         // 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 @@
     // 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 @@
   vals.computeSetOfDeclarations(dc);
   if (vals.hasNoDeclarations())
     return;
+#if 0
+  cfg.dump(dc.getParentASTContext().getLangOpts(), true);
+#endif
 
   stats.NumVariablesAnalyzed = vals.getNumEntries();
 

Modified: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp?rev=157440&r1=157439&r2=157440&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp (original)
+++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp Thu May 24 18:45:35 2012
@@ -748,6 +748,8 @@
     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;





More information about the cfe-commits mailing list