diff options
author | Ted Kremenek <kremenek@apple.com> | 2011-07-19 21:41:51 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2011-07-19 21:41:51 +0000 |
commit | 65b3e0649cdcc2c51d57e1ee193bf49e4145438a (patch) | |
tree | 4fbcb4d07d81140e65f0887ba679ee7a6c155c78 | |
parent | c78e03c39a8233893e28b021eb1f6f1294522b35 (diff) | |
download | bcm5719-llvm-65b3e0649cdcc2c51d57e1ee193bf49e4145438a.tar.gz bcm5719-llvm-65b3e0649cdcc2c51d57e1ee193bf49e4145438a.zip |
Fix false negative in -Wuninitialized involving a () wrapping an lvalue-to-rvalue conversion in a DeclStmt.
llvm-svn: 135525
-rw-r--r-- | clang/lib/Analysis/UninitializedValues.cpp | 17 | ||||
-rw-r--r-- | clang/test/Sema/uninit-variables.c | 4 |
2 files changed, 13 insertions, 8 deletions
diff --git a/clang/lib/Analysis/UninitializedValues.cpp b/clang/lib/Analysis/UninitializedValues.cpp index a64c1db530d..b84b4309d9e 100644 --- a/clang/lib/Analysis/UninitializedValues.cpp +++ b/clang/lib/Analysis/UninitializedValues.cpp @@ -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; } } } diff --git a/clang/test/Sema/uninit-variables.c b/clang/test/Sema/uninit-variables.c index 6c3c7c71c84..914156da8bf 100644 --- a/clang/test/Sema/uninit-variables.c +++ b/clang/test/Sema/uninit-variables.c @@ -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. |