2011-10-02 09:16:38 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -fobjc-arc -verify %s
|
2011-10-01 09:01:08 +08:00
|
|
|
|
2011-10-19 05:18:53 +08:00
|
|
|
#if __has_feature(arc_cf_code_audited)
|
|
|
|
char _global[-1]; // expected-error {{declared as an array with a negative size}}
|
|
|
|
#endif
|
|
|
|
|
2011-10-01 09:01:08 +08:00
|
|
|
typedef const void *CFTypeRef;
|
2012-02-02 06:56:20 +08:00
|
|
|
CFTypeRef CFBridgingRetain(id X);
|
|
|
|
id CFBridgingRelease(CFTypeRef);
|
2011-10-01 09:01:08 +08:00
|
|
|
typedef const struct __CFString *CFStringRef;
|
|
|
|
|
|
|
|
extern CFStringRef CFMakeString0(void);
|
2012-07-28 07:55:46 +08:00
|
|
|
#pragma clang arc_cf_code_audited begin
|
2011-10-01 09:01:08 +08:00
|
|
|
extern CFStringRef CFCreateString0(void);
|
2012-07-28 07:55:46 +08:00
|
|
|
#pragma clang arc_cf_code_audited end
|
2011-10-01 09:01:08 +08:00
|
|
|
void test0() {
|
|
|
|
id x;
|
2012-07-28 05:34:23 +08:00
|
|
|
x = (id) CFMakeString0(); // expected-error {{requires a bridged cast}} expected-note {{__bridge to convert directly}} expected-note {{CFBridgingRelease call to transfer}}
|
2012-07-28 06:37:07 +08:00
|
|
|
x = (id) CFCreateString0(); // expected-error {{requires a bridged cast}} expected-note {{CFBridgingRelease call to transfer}}
|
2011-10-01 09:01:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
extern CFStringRef CFMakeString1(void) __attribute__((cf_returns_not_retained));
|
|
|
|
extern CFStringRef CFCreateString1(void) __attribute__((cf_returns_retained));
|
|
|
|
void test1() {
|
|
|
|
id x;
|
|
|
|
x = (id) CFMakeString1();
|
2012-07-28 07:55:46 +08:00
|
|
|
x = (id) CFCreateString1(); // expected-error {{requires a bridged cast}} expected-note {{CFBridgingRelease call to transfer}}
|
2011-10-01 09:01:08 +08:00
|
|
|
}
|
2011-10-18 08:44:04 +08:00
|
|
|
|
|
|
|
#define CF_AUDIT_BEGIN _Pragma("clang arc_cf_code_audited begin")
|
|
|
|
#define CF_AUDIT_END _Pragma("clang arc_cf_code_audited end")
|
|
|
|
#define CF_RETURNS_RETAINED __attribute__((cf_returns_retained))
|
|
|
|
#define CF_RETURNS_NOT_RETAINED __attribute__((cf_returns_not_retained))
|
|
|
|
|
|
|
|
CF_AUDIT_BEGIN
|
|
|
|
extern CFStringRef CFMakeString2(void);
|
|
|
|
extern CFStringRef CFCreateString2(void) CF_RETURNS_NOT_RETAINED;
|
|
|
|
extern CFStringRef CFMakeString3(void) CF_RETURNS_RETAINED;
|
|
|
|
extern CFStringRef CFCreateString3(void);
|
|
|
|
CF_AUDIT_END
|
|
|
|
void test2() {
|
|
|
|
id x;
|
|
|
|
x = (id) CFMakeString2();
|
|
|
|
x = (id) CFCreateString2();
|
2012-07-28 07:55:46 +08:00
|
|
|
x = (id) CFMakeString3(); // expected-error {{requires a bridged cast}} expected-note {{CFBridgingRelease call to transfer}}
|
2012-07-28 06:37:07 +08:00
|
|
|
x = (id) CFCreateString3(); // expected-error {{requires a bridged cast}} expected-note {{CFBridgingRelease call to transfer}}
|
2011-10-18 08:44:04 +08:00
|
|
|
}
|
2013-08-01 07:19:34 +08:00
|
|
|
|
|
|
|
// rdar://14569171
|
|
|
|
@interface NSString @end
|
|
|
|
typedef signed int SInt32;
|
|
|
|
#pragma clang arc_cf_code_audited begin
|
|
|
|
extern SInt32 CFStringGetIntValue(CFStringRef str); // expected-note {{passing argument to parameter 'str' here}}
|
|
|
|
#pragma clang arc_cf_code_audited end
|
|
|
|
|
|
|
|
void test3() {
|
|
|
|
NSString* answer = @"42";
|
|
|
|
int ans = CFStringGetIntValue(answer); // expected-error {{incompatible pointer types passing retainable parameter of type 'NSString *__strong'to a CF function expecting 'CFStringRef'}}
|
|
|
|
}
|