annotate clang/test/SemaObjCXX/arc-unbridged-cast.mm @ 206:f17a3b42b08b

Added tag before-12 for changeset b7591485f4cd
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 07 Jun 2021 21:25:57 +0900
parents 1d019706d866
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -verify %s
anatofuz
parents:
diff changeset
2
anatofuz
parents:
diff changeset
3 typedef const struct __CFString * CFStringRef;
anatofuz
parents:
diff changeset
4 typedef const void * CFTypeRef;
anatofuz
parents:
diff changeset
5 extern "C" CFTypeRef CFBridgingRetain(id X);
anatofuz
parents:
diff changeset
6 extern "C" id CFBridgingRelease(CFTypeRef);
anatofuz
parents:
diff changeset
7
anatofuz
parents:
diff changeset
8
anatofuz
parents:
diff changeset
9 @interface Object
anatofuz
parents:
diff changeset
10 @property CFStringRef property;
anatofuz
parents:
diff changeset
11 - (CFStringRef) implicitProperty;
anatofuz
parents:
diff changeset
12 - (CFStringRef) newString;
anatofuz
parents:
diff changeset
13 - (CFStringRef) makeString;
anatofuz
parents:
diff changeset
14 @end
anatofuz
parents:
diff changeset
15
anatofuz
parents:
diff changeset
16 extern Object *object;
anatofuz
parents:
diff changeset
17
anatofuz
parents:
diff changeset
18 // rdar://9744349
anatofuz
parents:
diff changeset
19 id test0(void) {
anatofuz
parents:
diff changeset
20 id p1 = (id)[object property];
anatofuz
parents:
diff changeset
21 id p2 = (__bridge_transfer id)[object property];
anatofuz
parents:
diff changeset
22 id p3 = (__bridge id)[object property];
anatofuz
parents:
diff changeset
23 return (id) object.property;
anatofuz
parents:
diff changeset
24 }
anatofuz
parents:
diff changeset
25
anatofuz
parents:
diff changeset
26 // rdar://10140692
anatofuz
parents:
diff changeset
27 CFStringRef unauditedString(void);
anatofuz
parents:
diff changeset
28 CFStringRef plusOneString(void) __attribute__((cf_returns_retained));
anatofuz
parents:
diff changeset
29
anatofuz
parents:
diff changeset
30 #pragma clang arc_cf_code_audited begin
anatofuz
parents:
diff changeset
31 CFStringRef auditedString(void);
anatofuz
parents:
diff changeset
32 CFStringRef auditedCreateString(void);
anatofuz
parents:
diff changeset
33 #pragma clang arc_cf_code_audited end
anatofuz
parents:
diff changeset
34
anatofuz
parents:
diff changeset
35 void test1(int cond) {
anatofuz
parents:
diff changeset
36 id x;
anatofuz
parents:
diff changeset
37 x = (id) auditedString();
anatofuz
parents:
diff changeset
38 x = (id) (cond ? auditedString() : (void*) 0);
anatofuz
parents:
diff changeset
39 x = (id) (cond ? (void*) 0 : auditedString());
anatofuz
parents:
diff changeset
40 x = (id) (cond ? (CFStringRef) @"help" : auditedString());
anatofuz
parents:
diff changeset
41
anatofuz
parents:
diff changeset
42 x = (id) unauditedString(); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRelease call to}}
anatofuz
parents:
diff changeset
43 x = (id) (cond ? unauditedString() : (void*) 0); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRelease call to}}
anatofuz
parents:
diff changeset
44 x = (id) (cond ? (void*) 0 : unauditedString()); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRelease call to}}
anatofuz
parents:
diff changeset
45 x = (id) (cond ? (CFStringRef) @"help" : unauditedString()); // expected-error {{requires a bridged cast}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRelease call to}}
anatofuz
parents:
diff changeset
46
anatofuz
parents:
diff changeset
47 x = (id) auditedCreateString(); // expected-error {{requires a bridged cast}} expected-note {{use CFBridgingRelease call to}}
anatofuz
parents:
diff changeset
48 x = (id) (cond ? auditedCreateString() : (void*) 0); // expected-error {{requires a bridged cast}} expected-note {{use CFBridgingRelease call to}}
anatofuz
parents:
diff changeset
49 x = (id) (cond ? (void*) 0 : auditedCreateString()); // expected-error {{requires a bridged cast}} expected-note {{use CFBridgingRelease call to}}
anatofuz
parents:
diff changeset
50 x = (id) (cond ? (CFStringRef) @"help" : auditedCreateString()); // expected-error {{requires a bridged cast}} expected-note {{use CFBridgingRelease call to}}
anatofuz
parents:
diff changeset
51
anatofuz
parents:
diff changeset
52 x = (id) [object property];
anatofuz
parents:
diff changeset
53 x = (id) (cond ? [object property] : (void*) 0);
anatofuz
parents:
diff changeset
54 x = (id) (cond ? (void*) 0 : [object property]);
anatofuz
parents:
diff changeset
55 x = (id) (cond ? (CFStringRef) @"help" : [object property]);
anatofuz
parents:
diff changeset
56
anatofuz
parents:
diff changeset
57 x = (id) object.property;
anatofuz
parents:
diff changeset
58 x = (id) (cond ? object.property : (void*) 0);
anatofuz
parents:
diff changeset
59 x = (id) (cond ? (void*) 0 : object.property);
anatofuz
parents:
diff changeset
60 x = (id) (cond ? (CFStringRef) @"help" : object.property);
anatofuz
parents:
diff changeset
61
anatofuz
parents:
diff changeset
62 x = (id) object.implicitProperty;
anatofuz
parents:
diff changeset
63 x = (id) (cond ? object.implicitProperty : (void*) 0);
anatofuz
parents:
diff changeset
64 x = (id) (cond ? (void*) 0 : object.implicitProperty);
anatofuz
parents:
diff changeset
65 x = (id) (cond ? (CFStringRef) @"help" : object.implicitProperty);
anatofuz
parents:
diff changeset
66
anatofuz
parents:
diff changeset
67 x = (id) [object makeString];
anatofuz
parents:
diff changeset
68 x = (id) (cond ? [object makeString] : (void*) 0);
anatofuz
parents:
diff changeset
69 x = (id) (cond ? (void*) 0 : [object makeString]);
anatofuz
parents:
diff changeset
70 x = (id) (cond ? (CFStringRef) @"help" : [object makeString]);
anatofuz
parents:
diff changeset
71
anatofuz
parents:
diff changeset
72 x = (id) [object newString];
anatofuz
parents:
diff changeset
73 x = (id) (cond ? [object newString] : (void*) 0);
anatofuz
parents:
diff changeset
74 x = (id) (cond ? (void*) 0 : [object newString]);
anatofuz
parents:
diff changeset
75 x = (id) (cond ? (CFStringRef) @"help" : [object newString]); // a bit questionable
anatofuz
parents:
diff changeset
76 }
anatofuz
parents:
diff changeset
77
anatofuz
parents:
diff changeset
78 // rdar://problem/10246264
anatofuz
parents:
diff changeset
79 @interface CFTaker
anatofuz
parents:
diff changeset
80 - (void) takeOrdinary: (CFStringRef) arg;
anatofuz
parents:
diff changeset
81 - (void) takeVariadic: (int) n, ...;
anatofuz
parents:
diff changeset
82 - (void) takeConsumed: (CFStringRef __attribute__((cf_consumed))) arg;
anatofuz
parents:
diff changeset
83 @end
anatofuz
parents:
diff changeset
84 void testCFTaker(CFTaker *taker, id string) {
anatofuz
parents:
diff changeset
85 [taker takeOrdinary: (CFStringRef) string];
anatofuz
parents:
diff changeset
86 [taker takeVariadic: 1, (CFStringRef) string];
anatofuz
parents:
diff changeset
87 [taker takeConsumed: (CFStringRef) string]; // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRetain call to}}
anatofuz
parents:
diff changeset
88 }
anatofuz
parents:
diff changeset
89
anatofuz
parents:
diff changeset
90 void takeCFOrdinaryUnaudited(CFStringRef arg);
anatofuz
parents:
diff changeset
91 void takeCFVariadicUnaudited(int n, ...);
anatofuz
parents:
diff changeset
92 void takeCFConsumedUnaudited(CFStringRef __attribute__((cf_consumed)) arg);
anatofuz
parents:
diff changeset
93 #pragma clang arc_cf_code_audited begin
anatofuz
parents:
diff changeset
94 void takeCFOrdinaryAudited(CFStringRef arg);
anatofuz
parents:
diff changeset
95 void takeCFVariadicAudited(int n, ...);
anatofuz
parents:
diff changeset
96 void takeCFConsumedAudited(CFStringRef __attribute__((cf_consumed)) arg);
anatofuz
parents:
diff changeset
97 #pragma clang arc_cf_code_audited end
anatofuz
parents:
diff changeset
98
anatofuz
parents:
diff changeset
99 void testTakerFunctions(id string) {
anatofuz
parents:
diff changeset
100 takeCFOrdinaryUnaudited((CFStringRef) string); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRetain call to}}
anatofuz
parents:
diff changeset
101 takeCFVariadicUnaudited(1, (CFStringRef) string); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRetain call to}}
anatofuz
parents:
diff changeset
102 takeCFConsumedUnaudited((CFStringRef) string); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRetain call to}}
anatofuz
parents:
diff changeset
103
anatofuz
parents:
diff changeset
104 void (*taker)(CFStringRef) = 0;
anatofuz
parents:
diff changeset
105 taker((CFStringRef) string); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRetain call to}}
anatofuz
parents:
diff changeset
106
anatofuz
parents:
diff changeset
107 takeCFOrdinaryAudited((CFStringRef) string);
anatofuz
parents:
diff changeset
108 takeCFVariadicAudited(1, (CFStringRef) string);
anatofuz
parents:
diff changeset
109 takeCFConsumedAudited((CFStringRef) string); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRetain call to}}
anatofuz
parents:
diff changeset
110 }
anatofuz
parents:
diff changeset
111
anatofuz
parents:
diff changeset
112 // rdar://12788838
anatofuz
parents:
diff changeset
113 id obj;
anatofuz
parents:
diff changeset
114
anatofuz
parents:
diff changeset
115 void rdar12788838() {
anatofuz
parents:
diff changeset
116 void *foo = reinterpret_cast<void *>(obj); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'void *' requires a bridged cast}} \
anatofuz
parents:
diff changeset
117 // expected-note {{use __bridge with C-style cast to convert directly}} \
anatofuz
parents:
diff changeset
118 // expected-note {{use CFBridgingRetain call to make an ARC object available as a +1 'void *'}}
anatofuz
parents:
diff changeset
119 }