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

Ted Kremenek kremenek at apple.com
Tue Jul 19 14:41:51 PDT 2011


Author: kremenek
Date: Tue Jul 19 16:41:51 2011
New Revision: 135525

URL: http://llvm.org/viewvc/llvm-project?rev=135525&view=rev
Log:
Fix false negative in -Wuninitialized involving a () wrapping an lvalue-to-rvalue conversion in a DeclStmt.

Modified:
    cfe/trunk/lib/Analysis/UninitializedValues.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=135525&r1=135524&r2=135525&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/UninitializedValues.cpp (original)
+++ cfe/trunk/lib/Analysis/UninitializedValues.cpp Tue Jul 19 16:41:51 2011
@@ -464,14 +464,19 @@
           if (init == lastLoad) {
             DeclRefExpr *DR =
               cast<DeclRefExpr>(lastLoad->getSubExpr()->IgnoreParens());
-            vals[vd] = (DR->getDecl() == vd) ? Uninitialized : Initialized;
-            lastLoad = 0;
-            if (lastDR == DR)
+            if (DR->getDecl() == vd) {
+              // int x = x;
+              // Propagate uninitialized value, but don't immediately report
+              // a problem.
+              vals[vd] = Uninitialized;
+              lastLoad = 0;
               lastDR = 0;
+              return;
+            }
           }
-          else {
-            vals[vd] = Initialized;
-          }
+
+          // All other cases: treat the new variable as initialized.
+          vals[vd] = Initialized;
         }
       }
     }

Modified: cfe/trunk/test/Sema/uninit-variables.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/uninit-variables.c?rev=135525&r1=135524&r2=135525&view=diff
==============================================================================
--- cfe/trunk/test/Sema/uninit-variables.c (original)
+++ cfe/trunk/test/Sema/uninit-variables.c Tue Jul 19 16:41:51 2011
@@ -354,8 +354,8 @@
 }
 
 void test53() {
-  int x;
-  int y = (x);
+  int x; // expected-note {{variable 'x' is declared here}} expected-note {{add initialization to silence this warning}}
+  int y = (x);  // expected-warning {{variable 'x' is uninitialized when used here}}
 }
 
 // This CFG caused the uninitialized values warning to inf-loop.





More information about the cfe-commits mailing list