aboutsummaryrefslogtreecommitdiff
path: root/test/Sema/uninit-variables.c
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2012-06-16 23:34:14 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2012-06-16 23:34:14 +0000
commit8f40dcc4ddbe4ef796dd1bf0696ac66d4e40e99a (patch)
tree882d72f180144e92dc4d7c6d3575229657d052b3 /test/Sema/uninit-variables.c
parentd3cb28bef1e1d397b35126029465f2b7e8e8dc1f (diff)
-Wuninitialized bugfix: when entering the scope of a variable with no
initializer, it is uninitialized, even if we may be coming from somewhere where it was initialized. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@158611 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Sema/uninit-variables.c')
-rw-r--r--test/Sema/uninit-variables.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/test/Sema/uninit-variables.c b/test/Sema/uninit-variables.c
index ef03d44d97..180d60cbce 100644
--- a/test/Sema/uninit-variables.c
+++ b/test/Sema/uninit-variables.c
@@ -437,3 +437,28 @@ void test54() {
int c; // expected-note {{initialize the variable 'c' to silence this warning}}
ASSIGN(int, c, d); // expected-warning {{variable 'c' is uninitialized when used here}}
}
+
+void uninit_in_loop() {
+ int produce(void);
+ void consume(int);
+ for (int n = 0; n < 100; ++n) {
+ int k; // expected-note {{initialize}}
+ consume(k); // expected-warning {{variable 'k' is uninitialized}}
+ k = produce();
+ }
+}
+
+void uninit_in_loop_goto() {
+ int produce(void);
+ void consume(int);
+ for (int n = 0; n < 100; ++n) {
+ goto skip_decl;
+ int k; // expected-note {{initialize}}
+skip_decl:
+ // FIXME: This should produce the 'is uninitialized' diagnostic, but we
+ // don't have enough information in the CFG to easily tell that the
+ // variable's scope has been left and re-entered.
+ consume(k); // expected-warning {{variable 'k' may be uninitialized}}
+ k = produce();
+ }
+}