Debian Codegraph @

clang/test/SemaObjC/arc-cf.m

raw
1 // RUN: %clang_cc1 -fsyntax-only -fobjc-arc -verify %s
2
3 #if __has_feature(arc_cf_code_audited)
4 char _global[-1]; // expected-error {{declared as an array with a negative size}}
5 #endif
6
7 typedef const void *CFTypeRef;
8 CFTypeRef CFBridgingRetain(id X);
9 id CFBridgingRelease(CFTypeRef);
10 typedef const struct __CFString *CFStringRef;
11
12 extern CFStringRef CFMakeString0(void);
13 #pragma clang arc_cf_code_audited begin
14 extern CFStringRef CFCreateString0(void);
15 #pragma clang arc_cf_code_audited end
16 void test0(void) {
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
22 extern CFStringRef CFMakeString1(void) __attribute__((cf_returns_not_retained));
23 extern CFStringRef CFCreateString1(void) __attribute__((cf_returns_retained));
24 void test1(void) {
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
35 CF_AUDIT_BEGIN
36 extern CFStringRef CFMakeString2(void);
37 extern CFStringRef CFCreateString2(void) CF_RETURNS_NOT_RETAINED;
38 extern CFStringRef CFMakeString3(void) CF_RETURNS_RETAINED;
39 extern CFStringRef CFCreateString3(void);
40 CF_AUDIT_END
41 void test2(void) {
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 @interface NSString @end
50 typedef signed int SInt32;
51 #pragma clang arc_cf_code_audited begin
52 extern SInt32 CFStringGetIntValue(CFStringRef str); // expected-note {{passing argument to parameter 'str' here}}
53 #pragma clang arc_cf_code_audited end
54
55 void test3(void) {
56 NSString* answer = @"42";
57 int ans = CFStringGetIntValue(answer); // expected-error {{incompatible pointer types passing retainable parameter of type 'NSString *__strong'to a CF function expecting 'CFStringRef'}}
58 }