[cfe-commits] r135748 - in /cfe/trunk: lib/Analysis/UninitializedValues.cpp lib/Sema/AnalysisBasedWarnings.cpp test/Sema/uninit-variables.c

Chandler Carruth chandlerc at gmail.com
Thu Jul 21 22:27:52 PDT 2011


Author: chandlerc
Date: Fri Jul 22 00:27:52 2011
New Revision: 135748

URL: http://llvm.org/viewvc/llvm-project?rev=135748&view=rev
Log:
Move duplicate uninitialized warning suppression into the
AnalysisBasedWarnings Sema layer and out of the Analysis library itself.
This returns the uninitialized values analysis to a more pure form,
allowing its original logic to correctly detect some categories of
definitely uninitialized values. Fixes PR10358 (again).

Thanks to Ted for reviewing and updating this patch after his rewrite of
several portions of this analysis.

Modified:
    cfe/trunk/lib/Analysis/UninitializedValues.cpp
    cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
    cfe/trunk/test/Sema/uninit-variables.c

Modified: cfe/trunk/lib/Analysis/UninitializedValues.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/UninitializedValues.cpp?rev=135748&r1=135747&r2=135748&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/UninitializedValues.cpp (original)
+++ cfe/trunk/lib/Analysis/UninitializedValues.cpp Fri Jul 22 00:27:52 2011
@@ -493,7 +493,8 @@
       if (isUninitialized(val)) {
         if (bo->getOpcode() != BO_Assign)
           reportUninit(res.getDeclRefExpr(), vd, isAlwaysUninit(val));
-        val = Initialized;
+        else
+          val = Initialized;
       }
     }
   }
@@ -513,11 +514,8 @@
         lastDR = 0;
 
         ValueVector::reference val = vals[vd];
-        if (isUninitialized(val)) {
+        if (isUninitialized(val))
           reportUninit(res.getDeclRefExpr(), vd, isAlwaysUninit(val));
-          // Don't cascade warnings.
-          val = Initialized;
-        }
       }
       break;
     }
@@ -575,8 +573,6 @@
     reportUninit(DR, VD, isAlwaysUninit(vals[VD]));
     lastLoad = 0;
     
-    // Prevent cascade of warnings.
-    vals[VD] = Initialized;
     if (DR == lastDR) {
       lastDR = 0;
       return;

Modified: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp?rev=135748&r1=135747&r2=135748&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp (original)
+++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp Fri Jul 22 00:27:52 2011
@@ -560,8 +560,6 @@
       const VarDecl *vd = i->first;
       UsesVec *vec = i->second;
 
-      bool fixitIssued = false;
-            
       // Sort the uses by their SourceLocations.  While not strictly
       // guaranteed to produce them in line/column order, this will provide
       // a stable ordering.
@@ -573,11 +571,11 @@
                                       /*isAlwaysUninit=*/vi->second))
           continue;
 
-        // Suggest a fixit hint the first time we diagnose a use of a variable.
-        if (!fixitIssued) {
-          SuggestInitializationFixit(S, vd);
-          fixitIssued = true;
-        }
+        SuggestInitializationFixit(S, vd);
+
+        // Skip further diagnostics for this variable. We try to warn only on
+        // the first point at which a variable is used uninitialized.
+        break;
       }
 
       delete vec;

Modified: cfe/trunk/test/Sema/uninit-variables.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/uninit-variables.c?rev=135748&r1=135747&r2=135748&view=diff
==============================================================================
--- cfe/trunk/test/Sema/uninit-variables.c (original)
+++ cfe/trunk/test/Sema/uninit-variables.c Fri Jul 22 00:27:52 2011
@@ -77,7 +77,7 @@
 }
 
 void test12(unsigned n) {
-  for (unsigned i ; n ; ++i) ; // expected-warning{{variable 'i' may be uninitialized when used here}} expected-note{{variable 'i' is declared here}} expected-note{{add initialization to silence this warning}}
+  for (unsigned i ; n ; ++i) ; // expected-warning{{variable 'i' is uninitialized when used here}} expected-note{{variable 'i' is declared here}} expected-note{{add initialization to silence this warning}}
 }
 
 int test13() {
@@ -237,7 +237,7 @@
   void **pc; // expected-note{{variable 'pc' is declared here}} expected-note{{add initialization to silence this warning}}
   void *dummy[] = { &&L1, &&L2 };
  L1:
-    goto *pc; // expected-warning{{variable 'pc' may be uninitialized when used here}}
+    goto *pc; // expected-warning{{variable 'pc' is uninitialized when used here}}
  L2:
     goto *pc;
 }
@@ -289,7 +289,7 @@
 void test43(int i) {
   int x; // expected-note {{variable 'x' is declared here}} expected-note{{add initialization to silence this warning}}
   for (i = 0 ; i < 10; i++)
-    test43_aux(x++); // expected-warning {{variable 'x' may be uninitialized when used here}}
+    test43_aux(x++); // expected-warning {{variable 'x' is uninitialized when used here}}
 }
 
 void test44(int i) {
@@ -297,7 +297,7 @@
   int y; // expected-note {{variable 'y' is declared here}} expected-note{{add initialization to silence this warning}}
   for (i = 0; i < 10; i++ ) {
     test43_aux(x++); // no-warning
-    x += y; // expected-warning {{variable 'y' may be uninitialized when used here}}
+    x += y; // expected-warning {{variable 'y' is uninitialized when used here}}
   }
 }
 





More information about the cfe-commits mailing list