]> granicus.if.org Git - clang/commitdiff
Fix false negative in -Wuninitialized involving a () wrapping an lvalue-to-rvalue...
authorTed Kremenek <kremenek@apple.com>
Tue, 19 Jul 2011 21:41:51 +0000 (21:41 +0000)
committerTed Kremenek <kremenek@apple.com>
Tue, 19 Jul 2011 21:41:51 +0000 (21:41 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135525 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/UninitializedValues.cpp
test/Sema/uninit-variables.c

index a64c1db530d0b2f1659dec3fd9551480f9e6facf..b84b4309d9e7bdb943cd8e9202af52e798dec23e 100644 (file)
@@ -464,14 +464,19 @@ void TransferFunctions::VisitDeclStmt(DeclStmt *ds) {
           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;
         }
       }
     }
index 6c3c7c71c84554d5e70dd11fc14878f51a6306d2..914156da8bfa05066d4b00215a5209b8182548d7 100644 (file)
@@ -354,8 +354,8 @@ int test52(int a, int b) {
 }
 
 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.