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