aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2011-07-19 21:41:51 +0000
committerTed Kremenek <kremenek@apple.com>2011-07-19 21:41:51 +0000
commit62d126e942f9f420c6f398d32deb914d413226a3 (patch)
tree0d08bbc823aac3c857b84e5cc8bd633ced75ac97
parentd626ec404fd0f27244363200f1a85a7db219cd11 (diff)
Fix false negative in -Wuninitialized involving a () wrapping an lvalue-to-rvalue conversion in a DeclStmt.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135525 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Analysis/UninitializedValues.cpp17
-rw-r--r--test/Sema/uninit-variables.c4
2 files changed, 13 insertions, 8 deletions
diff --git a/lib/Analysis/UninitializedValues.cpp b/lib/Analysis/UninitializedValues.cpp
index a64c1db530..b84b4309d9 100644
--- a/lib/Analysis/UninitializedValues.cpp
+++ b/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/test/Sema/uninit-variables.c b/test/Sema/uninit-variables.c
index 6c3c7c71c8..914156da8b 100644
--- a/test/Sema/uninit-variables.c
+++ b/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.