1 | // RUN: %clang_cc1 -fsyntax-only -Wuninitialized -fsyntax-only -fblocks %s -verify |
2 | |
3 | #include <stdarg.h> |
4 | |
5 | @interface NSObject {} @end |
6 | @class NSString; |
7 | |
8 | @interface NSException |
9 | + (void)raise:(NSString *)name format:(NSString *)format, ...; |
10 | + (void)raise:(NSString *)name format:(NSString *)format arguments:(va_list)argList; |
11 | - (void)raise; |
12 | @end |
13 | |
14 | // Duplicated from uninit-variables.c. |
15 | // Test just to ensure the analysis is working. |
16 | int test1() { |
17 | int x; // expected-note{{initialize the variable 'x' to silence this warning}} |
18 | return x; // expected-warning{{variable 'x' is uninitialized when used here}} |
19 | } |
20 | |
21 | // Test ObjC fast enumeration. |
22 | void test2() { |
23 | id collection = 0; |
24 | for (id obj in collection) { |
25 | if (0 == obj) // no-warning |
26 | break; |
27 | } |
28 | } |
29 | |
30 | void test3() { |
31 | id collection = 0; |
32 | id obj; |
33 | for (obj in collection) { // no-warning |
34 | if (0 == obj) // no-warning |
35 | break; |
36 | } |
37 | } |
38 | |
39 | int test_abort_on_exceptions(int y, NSException *e, NSString *s, int *z, ...) { |
40 | int x; // expected-note {{initialize the variable 'x' to silence this warning}} |
41 | if (y == 1) { |
42 | va_list alist; |
43 | va_start(alist, z); |
44 | [NSException raise:@"Blah" format:@"Blah %@" arguments:alist]; |
45 | return x; |
46 | } |
47 | else if (y == 2) { |
48 | [NSException raise:@"Blah" format:s]; |
49 | return x; |
50 | } |
51 | else if (y == 3) { |
52 | [e raise]; |
53 | return x; |
54 | } |
55 | return x; // expected-warning {{variable 'x' is uninitialized when used here}} |
56 | } |
57 | |