[cfe-commits] r128840 - in /cfe/trunk: lib/Analysis/CFG.cpp lib/Analysis/UninitializedValues.cpp test/SemaCXX/uninit-variables.cpp

Ted Kremenek kremenek at apple.com
Mon Apr 4 13:30:58 PDT 2011


Author: kremenek
Date: Mon Apr  4 15:30:58 2011
New Revision: 128840

URL: http://llvm.org/viewvc/llvm-project?rev=128840&view=rev
Log:
-Wuninitialized: don't warn about uninitialized variables in unreachable code.

Modified:
    cfe/trunk/lib/Analysis/CFG.cpp
    cfe/trunk/lib/Analysis/UninitializedValues.cpp
    cfe/trunk/test/SemaCXX/uninit-variables.cpp

Modified: cfe/trunk/lib/Analysis/CFG.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFG.cpp?rev=128840&r1=128839&r2=128840&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CFG.cpp (original)
+++ cfe/trunk/lib/Analysis/CFG.cpp Mon Apr  4 15:30:58 2011
@@ -428,8 +428,8 @@
     if (!BuildOpts.PruneTriviallyFalseEdges)
       return false;
     return !S->isTypeDependent() && 
-    !S->isValueDependent() &&
-    S->Evaluate(outResult, *Context);
+           !S->isValueDependent() &&
+           S->Evaluate(outResult, *Context);
   }
 
   /// tryEvaluateBool - Try and evaluate the Stmt and return 0 or 1

Modified: cfe/trunk/lib/Analysis/UninitializedValues.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/UninitializedValues.cpp?rev=128840&r1=128839&r2=128840&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/UninitializedValues.cpp (original)
+++ cfe/trunk/lib/Analysis/UninitializedValues.cpp Mon Apr  4 15:30:58 2011
@@ -156,6 +156,8 @@
     return declToIndex.getValueIndex(vd).hasValue();
   }
   
+  bool hasValues(const CFGBlock *block);
+  
   void resetScratch();
   ValueVector &getScratch() { return scratch; }
   
@@ -231,6 +233,11 @@
   return lazyCreate(vals[idx].first);
 }
 
+bool CFGBlockValues::hasValues(const CFGBlock *block) {
+  unsigned idx = block->getBlockID();
+  return vals[idx].second != 0;  
+}
+
 BVPair &CFGBlockValues::getValueVectors(const clang::CFGBlock *block,
                                         bool shouldLazyCreate) {
   unsigned idx = block->getBlockID();
@@ -603,9 +610,12 @@
 
 static bool runOnBlock(const CFGBlock *block, const CFG &cfg,
                        AnalysisContext &ac, CFGBlockValues &vals,
+                       llvm::BitVector &wasAnalyzed,
                        UninitVariablesHandler *handler = 0,
                        bool flagBlockUses = false) {
   
+  wasAnalyzed[block->getBlockID()] = true;
+  
   if (const BinaryOperator *b = getLogicalOperatorInChain(block)) {
     CFGBlock::const_pred_iterator itr = block->pred_begin();
     BVPair vA = vals.getValueVectors(*itr, false);
@@ -663,10 +673,11 @@
   llvm::BitVector previouslyVisited(cfg.getNumBlockIDs());
   
   worklist.enqueueSuccessors(&cfg.getEntry());
+  llvm::BitVector wasAnalyzed(cfg.getNumBlockIDs(), false);
 
   while (const CFGBlock *block = worklist.dequeue()) {
     // Did the block change?
-    bool changed = runOnBlock(block, cfg, ac, vals);    
+    bool changed = runOnBlock(block, cfg, ac, vals, wasAnalyzed);    
     if (changed || !previouslyVisited[block->getBlockID()])
       worklist.enqueueSuccessors(block);    
     previouslyVisited[block->getBlockID()] = true;
@@ -674,7 +685,9 @@
   
   // Run through the blocks one more time, and report uninitialized variabes.
   for (CFG::const_iterator BI = cfg.begin(), BE = cfg.end(); BI != BE; ++BI) {
-    runOnBlock(*BI, cfg, ac, vals, &handler, /* flagBlockUses */ true);
+    if (wasAnalyzed[(*BI)->getBlockID()])
+      runOnBlock(*BI, cfg, ac, vals, wasAnalyzed, &handler,
+                 /* flagBlockUses */ true);
   }
 }
 

Modified: cfe/trunk/test/SemaCXX/uninit-variables.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/uninit-variables.cpp?rev=128840&r1=128839&r2=128840&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/uninit-variables.cpp (original)
+++ cfe/trunk/test/SemaCXX/uninit-variables.cpp Mon Apr  4 15:30:58 2011
@@ -70,3 +70,11 @@
   virtual void bar(void) const;
 };
 void Rdar9188004C::bar(void) const {}
+
+// Don't warn about uninitialized variables in unreachable code.
+void PR9625() {
+  if (false) {
+    int x;
+    (void)static_cast<float>(x); // no-warning
+  }
+}





More information about the cfe-commits mailing list