diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2011-07-16 22:27:02 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2011-07-16 22:27:02 +0000 |
commit | 8435069798b5621615f9f65c471c7e7808316b20 (patch) | |
tree | 7ce0e2eb5f8f73ed043956cd0cb30cb1f92ca588 | |
parent | a6c2b3a648913d47703625acb17671dd2d926bbc (diff) |
Revert r135217, which wasn't the correct fix for PR10358. With this
patch, we actually move the state-machine for the value set backwards
one step. This can pretty easily lead to infinite loops where we
continually try to propagate a bit, succeed for one iteration, but then
back up because we find an uninitialized use.
A reduced test case from PR10379 is included.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135359 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Analysis/UninitializedValues.cpp | 10 | ||||
-rw-r--r-- | test/Sema/uninit-variables.c | 23 |
2 files changed, 23 insertions, 10 deletions
diff --git a/lib/Analysis/UninitializedValues.cpp b/lib/Analysis/UninitializedValues.cpp index 5e00eebec8..1d6959d81b 100644 --- a/lib/Analysis/UninitializedValues.cpp +++ b/lib/Analysis/UninitializedValues.cpp @@ -495,11 +495,9 @@ void TransferFunctions::VisitBinaryOperator(clang::BinaryOperator *bo) { ValueVector::reference val = vals[vd]; if (isUninitialized(val)) { - if (bo->getOpcode() != BO_Assign) { + if (bo->getOpcode() != BO_Assign) reportUninit(res.getDeclRefExpr(), vd, isAlwaysUninit(val)); - val = Unknown; - } else - val = Initialized; + val = Initialized; } return; } @@ -528,7 +526,7 @@ void TransferFunctions::VisitUnaryOperator(clang::UnaryOperator *uo) { if (isUninitialized(val)) { reportUninit(res.getDeclRefExpr(), vd, isAlwaysUninit(val)); // Don't cascade warnings. - val = Unknown; + val = Initialized; } return; } @@ -560,7 +558,7 @@ void TransferFunctions::VisitCastExpr(clang::CastExpr *ce) { if (isUninitialized(val)) { reportUninit(res.getDeclRefExpr(), vd, isAlwaysUninit(val)); // Don't cascade warnings. - vals[vd] = Unknown; + vals[vd] = Initialized; } } return; diff --git a/test/Sema/uninit-variables.c b/test/Sema/uninit-variables.c index 06abc76019..0caab3df18 100644 --- a/test/Sema/uninit-variables.c +++ b/test/Sema/uninit-variables.c @@ -77,7 +77,7 @@ int test11(unsigned n) { } void test12(unsigned n) { - 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}} + 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}} } int test13() { @@ -237,7 +237,7 @@ void test36() 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' is uninitialized when used here}} + goto *pc; // expected-warning{{variable 'pc' may be uninitialized when used here}} L2: goto *pc; } @@ -289,7 +289,7 @@ void test43_aux(int x); 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' is uninitialized when used here}} + test43_aux(x++); // expected-warning {{variable 'x' may be uninitialized when used here}} } void test44(int i) { @@ -297,7 +297,7 @@ void test44(int i) { 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' is uninitialized when used here}} + x += y; // expected-warning {{variable 'y' may be uninitialized when used here}} } } @@ -352,3 +352,18 @@ int test52(int a, int b) { } return x; // expected-warning {{variable 'x' may be uninitialized when used here}} } + +// This CFG caused the uninitialized values warning to inf-loop. +extern int PR10379_g(); +void PR10379_f(int *len) { + int new_len; // expected-note {{variable 'new_len' is declared here}} expected-note{{add initialization to silence this warning}} + for (int i = 0; i < 42 && PR10379_g() == 0; i++) { + if (PR10379_g() == 1) + continue; + if (PR10379_g() == 2) + PR10379_f(&new_len); + else if (PR10379_g() == 3) + PR10379_f(&new_len); + *len += new_len; // expected-warning {{variable 'new_len' may be uninitialized when used here}} + } +} |