summaryrefslogtreecommitdiffstats
path: root/test/Sema/uninit-variables.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/Sema/uninit-variables.c')
-rw-r--r--test/Sema/uninit-variables.c123
1 files changed, 101 insertions, 22 deletions
diff --git a/test/Sema/uninit-variables.c b/test/Sema/uninit-variables.c
index 973e504..60cae80 100644
--- a/test/Sema/uninit-variables.c
+++ b/test/Sema/uninit-variables.c
@@ -1,8 +1,8 @@
-// RUN: %clang_cc1 -fsyntax-only -Wuninitialized-experimental -fsyntax-only -fblocks %s -verify
+// RUN: %clang_cc1 -fsyntax-only -Wuninitialized -Wconditional-uninitialized -fsyntax-only -fblocks %s -verify
int test1() {
int x; // expected-note{{variable 'x' is declared here}} expected-note{{add initialization to silence this warning}}
- return x; // expected-warning{{variable 'x' is possibly uninitialized when used here}}
+ return x; // expected-warning{{variable 'x' is uninitialized when used here}}
}
int test2() {
@@ -18,19 +18,19 @@ int test3() {
int test4() {
int x; // expected-note{{variable 'x' is declared here}} expected-note{{add initialization to silence this warning}}
- ++x; // expected-warning{{variable 'x' is possibly uninitialized when used here}}
+ ++x; // expected-warning{{variable 'x' is uninitialized when used here}}
return x;
}
int test5() {
int x, y; // expected-note{{variable 'y' is declared here}} expected-note{{add initialization to silence this warning}}
- x = y; // expected-warning{{variable 'y' is possibly uninitialized when used here}}
+ x = y; // expected-warning{{variable 'y' is uninitialized when used here}}
return x;
}
int test6() {
int x; // expected-note{{variable 'x' is declared here}} expected-note{{add initialization to silence this warning}}
- x += 2; // expected-warning{{variable 'x' is possibly uninitialized when used here}}
+ x += 2; // expected-warning{{variable 'x' is uninitialized when used here}}
return x;
}
@@ -38,7 +38,7 @@ int test7(int y) {
int x; // expected-note{{variable 'x' is declared here}} expected-note{{add initialization to silence this warning}}
if (y)
x = 1;
- return x; // expected-warning{{variable 'x' is possibly uninitialized when used here}}
+ return x; // expected-warning{{variable 'x' may be uninitialized when used here}}
}
int test8(int y) {
@@ -57,7 +57,7 @@ int test9(int n) {
break;
x = 1;
}
- return x; // expected-warning{{variable 'x' is possibly uninitialized when used here}}
+ return x; // expected-warning{{variable 'x' may be uninitialized when used here}}
}
int test10(unsigned n) {
@@ -65,7 +65,7 @@ int test10(unsigned n) {
for (unsigned i = 0 ; i < n; ++i) {
x = 1;
}
- return x; // expected-warning{{variable 'x' is possibly uninitialized when used here}}
+ return x; // expected-warning{{variable 'x' may be uninitialized when used here}}
}
int test11(unsigned n) {
@@ -73,11 +73,11 @@ int test11(unsigned n) {
for (unsigned i = 0 ; i <= n; ++i) {
x = 1;
}
- return x; // expected-warning{{variable 'x' is possibly uninitialized when used here}}
+ return x; // expected-warning{{variable 'x' may be uninitialized when used here}}
}
void test12(unsigned n) {
- for (unsigned i ; n ; ++i) ; // expected-warning{{variable 'i' is possibly 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() {
@@ -91,8 +91,10 @@ void test14() {
for (;;) {}
}
-void test15() {
- int x = x; // expected-warning{{variable 'x' is possibly uninitialized when used here}} expected-note{{variable 'x' is declared here}} expected-note{{add initialization to silence this warning}}
+int test15() {
+ int x = x; // no-warning: signals intended lack of initialization. \
+ // expected-note{{variable 'x' is declared here}}
+ return x; // expected-warning{{variable 'x' is uninitialized when used here}}
}
// Don't warn in the following example; shows dataflow confluence.
@@ -107,7 +109,7 @@ void test17() {
// Don't warn multiple times about the same uninitialized variable
// along the same path.
int *x; // expected-note{{variable 'x' is declared here}} expected-note{{add initialization to silence this warning}}
- *x = 1; // expected-warning{{variable 'x' is possibly uninitialized when used here}}
+ *x = 1; // expected-warning{{variable 'x' is uninitialized when used here}}
*x = 1; // no-warning
}
@@ -132,14 +134,14 @@ int test19() {
int test20() {
int z; // expected-note{{variable 'z' is declared here}} expected-note{{add initialization to silence this warning}}
if ((test19_aux1() + test19_aux2() && test19_aux1()) || test19_aux3(&z))
- return z; // expected-warning{{variable 'z' is possibly uninitialized when used here}}
+ return z; // expected-warning{{variable 'z' may be uninitialized when used here}}
return 0;
}
int test21(int x, int y) {
int z; // expected-note{{variable 'z' is declared here}} expected-note{{add initialization to silence this warning}}
if ((x && y) || test19_aux3(&z) || test19_aux2())
- return z; // expected-warning{{variable 'z' is possibly uninitialized when used here}}
+ return z; // expected-warning{{variable 'z' may be uninitialized when used here}}
return 0;
}
@@ -167,18 +169,18 @@ int test24(int flag) {
val = 1;
if (!flag)
val = 1;
- return val; // expected-warning{{variable 'val' is possibly uninitialized when used here}}
+ return val; // expected-warning{{variable 'val' may be uninitialized when used here}}
}
float test25() {
float x; // expected-note{{variable 'x' is declared here}} expected-note{{add initialization to silence this warning}}
- return x; // expected-warning{{variable 'x' is possibly uninitialized when used here}}
+ return x; // expected-warning{{variable 'x' is uninitialized when used here}}
}
typedef int MyInt;
MyInt test26() {
MyInt x; // expected-note{{variable 'x' is declared here}} expected-note{{add initialization to silence this warning}}
- return x; // expected-warning{{variable 'x' is possibly uninitialized when used here}}
+ return x; // expected-warning{{variable 'x' is uninitialized when used here}}
}
// Test handling of sizeof().
@@ -189,12 +191,12 @@ int test27() {
int test28() {
int len; // expected-note{{variable 'len' is declared here}} expected-note{{add initialization to silence this warning}}
- return sizeof(int[len]); // expected-warning{{variable 'len' is possibly uninitialized when used here}}
+ return sizeof(int[len]); // expected-warning{{variable 'len' is uninitialized when used here}}
}
void test29() {
int x; // expected-note{{variable 'x' is declared here}} expected-note{{add initialization to silence this warning}}
- (void) ^{ (void) x; }; // expected-warning{{variable 'x' is possibly uninitialized when captured by block}}
+ (void) ^{ (void) x; }; // expected-warning{{variable 'x' is uninitialized when captured by block}}
}
void test30() {
@@ -220,7 +222,7 @@ void test_33() {
int test_34() {
int x; // expected-note{{variable 'x' is declared here}} expected-note{{add initialization to silence this warning}}
(void) x;
- return x; // expected-warning{{variable 'x' is possibly uninitialized when used here}}
+ return x; // expected-warning{{variable 'x' is uninitialized when used here}}
}
// Test that this case doesn't crash.
@@ -235,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 possibly uninitialized when used here}}
+ goto *pc; // expected-warning{{variable 'pc' may be uninitialized when used here}}
L2:
goto *pc;
}
@@ -260,3 +262,80 @@ int test38(int r, int x, int y)
return ((r < 0) || ((r == 0) && (x < y)));
}
+int test39(int x) {
+ int y; // expected-note {{variable 'y' is declared here}} expected-note{{add initialization to silence this warning}}
+ int z = x + y; // expected-warning {{variable 'y' is uninitialized when used here}}
+ return z;
+}
+
+
+int test40(int x) {
+ int y; // expected-note {{variable 'y' is declared here}} expected-note{{add initialization to silence this warning}}
+ return x ? 1 : y; // expected-warning {{variable 'y' is uninitialized when used here}}
+}
+
+int test41(int x) {
+ int y; // expected-note {{variable 'y' is declared here}} expected-note{{add initialization to silence this warning}}
+ if (x) y = 1; // no-warning
+ return y; // expected-warning {{variable 'y' may be uninitialized when used here}}
+}
+
+void test42() {
+ int a;
+ a = 30; // no-warning
+}
+
+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' may be uninitialized when used here}}
+}
+
+void test44(int i) {
+ int x = 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' may be uninitialized when used here}}
+ }
+}
+
+int test45(int j) {
+ int x = 1, y = x + 1;
+ if (y) // no-warning
+ return x;
+ return y;
+}
+
+void test46()
+{
+ int i; // expected-note {{variable 'i' is declared here}} expected-note{{add initialization to silence this warning}}
+ int j = i ? : 1; // expected-warning {{variable 'i' is uninitialized when used here}}
+}
+
+void *test47(int *i)
+{
+ return i ? : 0; // no-warning
+}
+
+void *test49(int *i)
+{
+ int a;
+ return &a ? : i; // no-warning
+}
+
+void test50()
+{
+ char c[1 ? : 2]; // no-warning
+}
+
+int test51(void)
+{
+ __block int a;
+ ^(void) {
+ a = 42;
+ }();
+ return a; // no-warning
+}
+
OpenPOWER on IntegriCloud