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