summaryrefslogtreecommitdiffstats
path: root/test/Analysis/uninit-vals.c
diff options
context:
space:
mode:
authored <ed@FreeBSD.org>2009-06-02 17:58:47 +0000
committered <ed@FreeBSD.org>2009-06-02 17:58:47 +0000
commitf27e5a09a0d815b8a4814152954ff87dadfdefc0 (patch)
treece7d964cbb5e39695b71481698f10cb099c23d4a /test/Analysis/uninit-vals.c
downloadFreeBSD-src-f27e5a09a0d815b8a4814152954ff87dadfdefc0.zip
FreeBSD-src-f27e5a09a0d815b8a4814152954ff87dadfdefc0.tar.gz
Import Clang, at r72732.
Diffstat (limited to 'test/Analysis/uninit-vals.c')
-rw-r--r--test/Analysis/uninit-vals.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/test/Analysis/uninit-vals.c b/test/Analysis/uninit-vals.c
new file mode 100644
index 0000000..d69250b
--- /dev/null
+++ b/test/Analysis/uninit-vals.c
@@ -0,0 +1,53 @@
+// RUN: clang-cc -analyze -warn-uninit-values -verify %s
+
+int f1() {
+ int x;
+ return x; // expected-warning {{use of uninitialized variable}}
+}
+
+int f2(int x) {
+ int y;
+ int z = x + y; // expected-warning {{use of uninitialized variable}}
+ return z;
+}
+
+
+int f3(int x) {
+ int y;
+ return x ? 1 : y; // expected-warning {{use of uninitialized variable}}
+}
+
+int f4(int x) {
+ int y;
+ if (x) y = 1;
+ return y; // expected-warning {{use of uninitialized variable}}
+}
+
+int f5() {
+ int a;
+ a = 30; // no-warning
+}
+
+void f6(int i) {
+ int x;
+ for (i = 0 ; i < 10; i++)
+ printf("%d",x++); // expected-warning {{use of uninitialized variable}} \
+ // expected-warning{{implicitly declaring C library function 'printf' with type 'int (char const *, ...)'}} \
+ // expected-note{{please include the header <stdio.h> or explicitly provide a declaration for 'printf'}}
+}
+
+void f7(int i) {
+ int x = i;
+ int y;
+ for (i = 0; i < 10; i++ ) {
+ printf("%d",x++); // no-warning
+ x += y; // expected-warning {{use of uninitialized variable}}
+ }
+}
+
+int f8(int j) {
+ int x = 1, y = x + 1;
+ if (y) // no-warning
+ return x;
+ return y;
+}
OpenPOWER on IntegriCloud