1*f4a2713aSLionel Sambuc// RUN: %clang_cc1 -fsyntax-only -fobjc-arc -verify %s 2*f4a2713aSLionel Sambuc 3*f4a2713aSLionel Sambuc#if __has_feature(arc_cf_code_audited) 4*f4a2713aSLionel Sambucchar _global[-1]; // expected-error {{declared as an array with a negative size}} 5*f4a2713aSLionel Sambuc#endif 6*f4a2713aSLionel Sambuc 7*f4a2713aSLionel Sambuctypedef const void *CFTypeRef; 8*f4a2713aSLionel SambucCFTypeRef CFBridgingRetain(id X); 9*f4a2713aSLionel Sambucid CFBridgingRelease(CFTypeRef); 10*f4a2713aSLionel Sambuctypedef const struct __CFString *CFStringRef; 11*f4a2713aSLionel Sambuc 12*f4a2713aSLionel Sambucextern CFStringRef CFMakeString0(void); 13*f4a2713aSLionel Sambuc#pragma clang arc_cf_code_audited begin 14*f4a2713aSLionel Sambucextern CFStringRef CFCreateString0(void); 15*f4a2713aSLionel Sambuc#pragma clang arc_cf_code_audited end 16*f4a2713aSLionel Sambucvoid test0() { 17*f4a2713aSLionel Sambuc id x; 18*f4a2713aSLionel Sambuc x = (id) CFMakeString0(); // expected-error {{requires a bridged cast}} expected-note {{__bridge to convert directly}} expected-note {{CFBridgingRelease call to transfer}} 19*f4a2713aSLionel Sambuc x = (id) CFCreateString0(); // expected-error {{requires a bridged cast}} expected-note {{CFBridgingRelease call to transfer}} 20*f4a2713aSLionel Sambuc} 21*f4a2713aSLionel Sambuc 22*f4a2713aSLionel Sambucextern CFStringRef CFMakeString1(void) __attribute__((cf_returns_not_retained)); 23*f4a2713aSLionel Sambucextern CFStringRef CFCreateString1(void) __attribute__((cf_returns_retained)); 24*f4a2713aSLionel Sambucvoid test1() { 25*f4a2713aSLionel Sambuc id x; 26*f4a2713aSLionel Sambuc x = (id) CFMakeString1(); 27*f4a2713aSLionel Sambuc x = (id) CFCreateString1(); // expected-error {{requires a bridged cast}} expected-note {{CFBridgingRelease call to transfer}} 28*f4a2713aSLionel Sambuc} 29*f4a2713aSLionel Sambuc 30*f4a2713aSLionel Sambuc#define CF_AUDIT_BEGIN _Pragma("clang arc_cf_code_audited begin") 31*f4a2713aSLionel Sambuc#define CF_AUDIT_END _Pragma("clang arc_cf_code_audited end") 32*f4a2713aSLionel Sambuc#define CF_RETURNS_RETAINED __attribute__((cf_returns_retained)) 33*f4a2713aSLionel Sambuc#define CF_RETURNS_NOT_RETAINED __attribute__((cf_returns_not_retained)) 34*f4a2713aSLionel Sambuc 35*f4a2713aSLionel SambucCF_AUDIT_BEGIN 36*f4a2713aSLionel Sambucextern CFStringRef CFMakeString2(void); 37*f4a2713aSLionel Sambucextern CFStringRef CFCreateString2(void) CF_RETURNS_NOT_RETAINED; 38*f4a2713aSLionel Sambucextern CFStringRef CFMakeString3(void) CF_RETURNS_RETAINED; 39*f4a2713aSLionel Sambucextern CFStringRef CFCreateString3(void); 40*f4a2713aSLionel SambucCF_AUDIT_END 41*f4a2713aSLionel Sambucvoid test2() { 42*f4a2713aSLionel Sambuc id x; 43*f4a2713aSLionel Sambuc x = (id) CFMakeString2(); 44*f4a2713aSLionel Sambuc x = (id) CFCreateString2(); 45*f4a2713aSLionel Sambuc x = (id) CFMakeString3(); // expected-error {{requires a bridged cast}} expected-note {{CFBridgingRelease call to transfer}} 46*f4a2713aSLionel Sambuc x = (id) CFCreateString3(); // expected-error {{requires a bridged cast}} expected-note {{CFBridgingRelease call to transfer}} 47*f4a2713aSLionel Sambuc} 48*f4a2713aSLionel Sambuc 49*f4a2713aSLionel Sambuc// rdar://14569171 50*f4a2713aSLionel Sambuc@interface NSString @end 51*f4a2713aSLionel Sambuctypedef signed int SInt32; 52*f4a2713aSLionel Sambuc#pragma clang arc_cf_code_audited begin 53*f4a2713aSLionel Sambucextern SInt32 CFStringGetIntValue(CFStringRef str); // expected-note {{passing argument to parameter 'str' here}} 54*f4a2713aSLionel Sambuc#pragma clang arc_cf_code_audited end 55*f4a2713aSLionel Sambuc 56*f4a2713aSLionel Sambucvoid test3() { 57*f4a2713aSLionel Sambuc NSString* answer = @"42"; 58*f4a2713aSLionel Sambuc int ans = CFStringGetIntValue(answer); // expected-error {{incompatible pointer types passing retainable parameter of type 'NSString *__strong'to a CF function expecting 'CFStringRef'}} 59*f4a2713aSLionel Sambuc} 60