annotate clang/test/SemaObjC/objcbridge-attribute.m @ 207:2e18cbf3894f

LLVM12
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 08 Jun 2021 06:07:14 +0900
parents 1d019706d866
children c4bab56944e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s
anatofuz
parents:
diff changeset
2 // rdar://15454846
anatofuz
parents:
diff changeset
3
anatofuz
parents:
diff changeset
4 typedef struct __attribute__ ((objc_bridge(NSError))) __CFErrorRef * CFErrorRef; // expected-note 3 {{declared here}}
anatofuz
parents:
diff changeset
5
anatofuz
parents:
diff changeset
6 typedef struct __attribute__ ((objc_bridge(MyError))) __CFMyErrorRef * CFMyErrorRef; // expected-note 1 {{declared here}}
anatofuz
parents:
diff changeset
7
anatofuz
parents:
diff changeset
8 typedef struct __attribute__((objc_bridge(12))) __CFMyColor *CFMyColorRef; // expected-error {{parameter of 'objc_bridge' attribute must be a single name of an Objective-C class}}
anatofuz
parents:
diff changeset
9
anatofuz
parents:
diff changeset
10 typedef struct __attribute__ ((objc_bridge)) __CFArray *CFArrayRef; // expected-error {{'objc_bridge' attribute takes one argument}}
anatofuz
parents:
diff changeset
11
anatofuz
parents:
diff changeset
12 typedef void * __attribute__ ((objc_bridge(NSURL))) CFURLRef; // expected-error {{parameter of 'objc_bridge' attribute must be 'id' when used on a typedef}}
anatofuz
parents:
diff changeset
13
anatofuz
parents:
diff changeset
14 typedef void * CFStringRef __attribute__ ((objc_bridge(NSString))); // expected-error {{parameter of 'objc_bridge' attribute must be 'id' when used on a typedef}}
anatofuz
parents:
diff changeset
15
anatofuz
parents:
diff changeset
16 typedef struct __attribute__((objc_bridge(NSLocale, NSError))) __CFLocale *CFLocaleRef;// expected-error {{use of undeclared identifier 'NSError'}}
anatofuz
parents:
diff changeset
17
anatofuz
parents:
diff changeset
18 typedef struct __CFData __attribute__((objc_bridge(NSData))) CFDataRef; // expected-error {{parameter of 'objc_bridge' attribute must be 'id' when used on a typedef}}
anatofuz
parents:
diff changeset
19
anatofuz
parents:
diff changeset
20 typedef struct __attribute__((objc_bridge(NSDictionary))) __CFDictionary * CFDictionaryRef; // expected-note {{declared here}}
anatofuz
parents:
diff changeset
21
anatofuz
parents:
diff changeset
22 typedef struct __CFSetRef * CFSetRef __attribute__((objc_bridge(NSSet))); // expected-error {{parameter of 'objc_bridge' attribute must be 'id' when used on a typedef}}
anatofuz
parents:
diff changeset
23
anatofuz
parents:
diff changeset
24 typedef union __CFUColor __attribute__((objc_bridge(NSUColor))) * CFUColorRef; // expected-error {{parameter of 'objc_bridge' attribute must be 'id' when used on a typedef}}
anatofuz
parents:
diff changeset
25
anatofuz
parents:
diff changeset
26 typedef union __CFUColor __attribute__((objc_bridge(NSUColor))) *CFUColor1Ref; // expected-error {{parameter of 'objc_bridge' attribute must be 'id' when used on a typedef}}
anatofuz
parents:
diff changeset
27
anatofuz
parents:
diff changeset
28 typedef union __attribute__((objc_bridge(NSUColor))) __CFUPrimeColor XXX;
anatofuz
parents:
diff changeset
29 typedef XXX *CFUColor2Ref;
anatofuz
parents:
diff changeset
30
anatofuz
parents:
diff changeset
31 typedef const void *ConstVoidRef __attribute__((objc_bridge(id)));
anatofuz
parents:
diff changeset
32 typedef void *VoidRef __attribute__((objc_bridge(id)));
anatofuz
parents:
diff changeset
33 typedef struct Opaque *OpaqueRef __attribute__((objc_bridge(id))); // expected-error {{'objc_bridge(id)' is only allowed on structs and typedefs of void pointers}}
anatofuz
parents:
diff changeset
34
anatofuz
parents:
diff changeset
35 #if !__has_feature(objc_bridge_id_on_typedefs)
anatofuz
parents:
diff changeset
36 #error objc_bridge(id) on typedefs feature not found!
anatofuz
parents:
diff changeset
37 #endif
anatofuz
parents:
diff changeset
38
anatofuz
parents:
diff changeset
39 @interface I
anatofuz
parents:
diff changeset
40 {
anatofuz
parents:
diff changeset
41 __attribute__((objc_bridge(NSError))) void * color; // expected-error {{'objc_bridge' attribute only applies to structs, unions, classes, and typedefs}};
anatofuz
parents:
diff changeset
42 }
anatofuz
parents:
diff changeset
43 @end
anatofuz
parents:
diff changeset
44
anatofuz
parents:
diff changeset
45 @protocol NSTesting @end
anatofuz
parents:
diff changeset
46 @class NSString;
anatofuz
parents:
diff changeset
47
anatofuz
parents:
diff changeset
48 typedef struct __attribute__((objc_bridge(NSTesting))) __CFError *CFTestingRef; // expected-note {{declared here}}
anatofuz
parents:
diff changeset
49
anatofuz
parents:
diff changeset
50 id Test1(CFTestingRef cf) {
anatofuz
parents:
diff changeset
51 return (NSString *)cf; // expected-error {{CF object of type 'CFTestingRef' (aka 'struct __CFError *') is bridged to 'NSTesting', which is not an Objective-C class}}
anatofuz
parents:
diff changeset
52 }
anatofuz
parents:
diff changeset
53
anatofuz
parents:
diff changeset
54 typedef CFErrorRef CFErrorRef1;
anatofuz
parents:
diff changeset
55
anatofuz
parents:
diff changeset
56 typedef CFErrorRef1 CFErrorRef2; // expected-note {{declared here}}
anatofuz
parents:
diff changeset
57
anatofuz
parents:
diff changeset
58 @protocol P1 @end
anatofuz
parents:
diff changeset
59 @protocol P2 @end
anatofuz
parents:
diff changeset
60 @protocol P3 @end
anatofuz
parents:
diff changeset
61 @protocol P4 @end
anatofuz
parents:
diff changeset
62 @protocol P5 @end
anatofuz
parents:
diff changeset
63
anatofuz
parents:
diff changeset
64 @interface NSError<P1, P2, P3> @end // expected-note 3 {{declared here}}
anatofuz
parents:
diff changeset
65
anatofuz
parents:
diff changeset
66 @interface MyError : NSError // expected-note 1 {{declared here}}
anatofuz
parents:
diff changeset
67 @end
anatofuz
parents:
diff changeset
68
anatofuz
parents:
diff changeset
69 @interface NSUColor @end
anatofuz
parents:
diff changeset
70
anatofuz
parents:
diff changeset
71 @class NSString;
anatofuz
parents:
diff changeset
72
anatofuz
parents:
diff changeset
73 void Test2(CFErrorRef2 cf, NSError *ns, NSString *str, Class c, CFUColor2Ref cf2) {
anatofuz
parents:
diff changeset
74 (void)(NSString *)cf; // expected-warning {{'CFErrorRef2' (aka 'struct __CFErrorRef *') bridges to NSError, not 'NSString'}}
anatofuz
parents:
diff changeset
75 (void)(NSError *)cf; // okay
anatofuz
parents:
diff changeset
76 (void)(MyError*)cf; // expected-warning {{'CFErrorRef2' (aka 'struct __CFErrorRef *') bridges to NSError, not 'MyError'}}
anatofuz
parents:
diff changeset
77 (void)(NSUColor *)cf2; // okay
anatofuz
parents:
diff changeset
78 (void)(CFErrorRef)ns; // okay
anatofuz
parents:
diff changeset
79 (void)(CFErrorRef)str; // expected-warning {{'NSString' cannot bridge to 'CFErrorRef' (aka 'struct __CFErrorRef *')}}
anatofuz
parents:
diff changeset
80 (void)(Class)cf; // expected-warning {{'CFErrorRef2' (aka 'struct __CFErrorRef *') bridges to NSError, not 'Class'}}
anatofuz
parents:
diff changeset
81 (void)(CFErrorRef)c; // expected-warning {{'Class' cannot bridge to 'CFErrorRef'}}
anatofuz
parents:
diff changeset
82 }
anatofuz
parents:
diff changeset
83
anatofuz
parents:
diff changeset
84
anatofuz
parents:
diff changeset
85 void Test3(CFErrorRef cf, NSError *ns) {
anatofuz
parents:
diff changeset
86 (void)(id)cf; // okay
anatofuz
parents:
diff changeset
87 (void)(id<P1, P2>)cf; // okay
anatofuz
parents:
diff changeset
88 (void)(id<P1, P2, P4>)cf; // expected-warning {{'CFErrorRef' (aka 'struct __CFErrorRef *') bridges to NSError, not 'id<P1,P2,P4>'}}
anatofuz
parents:
diff changeset
89 }
anatofuz
parents:
diff changeset
90
anatofuz
parents:
diff changeset
91 void Test4(CFMyErrorRef cf) {
anatofuz
parents:
diff changeset
92 (void)(id)cf; // okay
anatofuz
parents:
diff changeset
93 (void)(id<P1, P2>)cf; // ok
anatofuz
parents:
diff changeset
94 (void)(id<P1, P2, P3>)cf; // ok
anatofuz
parents:
diff changeset
95 (void)(id<P2, P3>)cf; // ok
anatofuz
parents:
diff changeset
96 (void)(id<P1, P2, P4>)cf; // expected-warning {{'CFMyErrorRef' (aka 'struct __CFMyErrorRef *') bridges to MyError, not 'id<P1,P2,P4>'}}
anatofuz
parents:
diff changeset
97 }
anatofuz
parents:
diff changeset
98
anatofuz
parents:
diff changeset
99 void Test5(id<P1, P2, P3> P123, id ID, id<P1, P2, P3, P4> P1234, id<P1, P2> P12, id<P2, P3> P23) {
anatofuz
parents:
diff changeset
100 (void)(CFErrorRef)ID; // ok
anatofuz
parents:
diff changeset
101 (void)(CFErrorRef)P123; // ok
anatofuz
parents:
diff changeset
102 (void)(CFErrorRef)P1234; // ok
anatofuz
parents:
diff changeset
103 (void)(CFErrorRef)P12; // ok
anatofuz
parents:
diff changeset
104 (void)(CFErrorRef)P23; // ok
anatofuz
parents:
diff changeset
105 }
anatofuz
parents:
diff changeset
106
anatofuz
parents:
diff changeset
107 void Test6(id<P1, P2, P3> P123, id ID, id<P1, P2, P3, P4> P1234, id<P1, P2> P12, id<P2, P3> P23) {
anatofuz
parents:
diff changeset
108
anatofuz
parents:
diff changeset
109 (void)(CFMyErrorRef)ID; // ok
anatofuz
parents:
diff changeset
110 (void)(CFMyErrorRef)P123; // ok
anatofuz
parents:
diff changeset
111 (void)(CFMyErrorRef)P1234; // ok
anatofuz
parents:
diff changeset
112 (void)(CFMyErrorRef)P12; // ok
anatofuz
parents:
diff changeset
113 (void)(CFMyErrorRef)P23; // ok
anatofuz
parents:
diff changeset
114 }
anatofuz
parents:
diff changeset
115
anatofuz
parents:
diff changeset
116 typedef struct __attribute__ ((objc_bridge(MyPersonalError))) __CFMyPersonalErrorRef * CFMyPersonalErrorRef; // expected-note 1 {{declared here}}
anatofuz
parents:
diff changeset
117
anatofuz
parents:
diff changeset
118 @interface MyPersonalError : NSError <P4> // expected-note 1 {{declared here}}
anatofuz
parents:
diff changeset
119 @end
anatofuz
parents:
diff changeset
120
anatofuz
parents:
diff changeset
121 void Test7(id<P1, P2, P3> P123, id ID, id<P1, P2, P3, P4> P1234, id<P1, P2> P12, id<P2, P3> P23) {
anatofuz
parents:
diff changeset
122 (void)(CFMyPersonalErrorRef)ID; // ok
anatofuz
parents:
diff changeset
123 (void)(CFMyPersonalErrorRef)P123; // ok
anatofuz
parents:
diff changeset
124 (void)(CFMyPersonalErrorRef)P1234; // ok
anatofuz
parents:
diff changeset
125 (void)(CFMyPersonalErrorRef)P12; // ok
anatofuz
parents:
diff changeset
126 (void)(CFMyPersonalErrorRef)P23; // ok
anatofuz
parents:
diff changeset
127 }
anatofuz
parents:
diff changeset
128
anatofuz
parents:
diff changeset
129 void Test8(CFMyPersonalErrorRef cf) {
anatofuz
parents:
diff changeset
130 (void)(id)cf; // ok
anatofuz
parents:
diff changeset
131 (void)(id<P1>)cf; // ok
anatofuz
parents:
diff changeset
132 (void)(id<P1, P2>)cf; // ok
anatofuz
parents:
diff changeset
133 (void)(id<P1, P2, P3>)cf; // ok
anatofuz
parents:
diff changeset
134 (void)(id<P1, P2, P3, P4>)cf; // ok
anatofuz
parents:
diff changeset
135 (void)(id<P1, P2, P3, P4, P5>)cf; // expected-warning {{'CFMyPersonalErrorRef' (aka 'struct __CFMyPersonalErrorRef *') bridges to MyPersonalError, not 'id<P1,P2,P3,P4,P5>'}}
anatofuz
parents:
diff changeset
136 }
anatofuz
parents:
diff changeset
137
anatofuz
parents:
diff changeset
138 CFDictionaryRef bar() __attribute__((cf_returns_not_retained));
anatofuz
parents:
diff changeset
139 @class NSNumber;
anatofuz
parents:
diff changeset
140
anatofuz
parents:
diff changeset
141 void Test9() {
anatofuz
parents:
diff changeset
142 NSNumber *w2 = (NSNumber*) bar(); // expected-error {{CF object of type 'CFDictionaryRef' (aka 'struct __CFDictionary *') is bridged to 'NSDictionary', which is not an Objective-C class}}
anatofuz
parents:
diff changeset
143 }
anatofuz
parents:
diff changeset
144
anatofuz
parents:
diff changeset
145 // rdar://18311183
anatofuz
parents:
diff changeset
146 @interface NSObject @end
anatofuz
parents:
diff changeset
147
anatofuz
parents:
diff changeset
148 @interface NSFont : NSObject @end
anatofuz
parents:
diff changeset
149
anatofuz
parents:
diff changeset
150 typedef struct __attribute__ ((objc_bridge(NSFont))) __CFFontRef * CFFontRef;
anatofuz
parents:
diff changeset
151
anatofuz
parents:
diff changeset
152 void Test10(CFFontRef cf) {
anatofuz
parents:
diff changeset
153 (void)(__bridge NSObject *)cf;
anatofuz
parents:
diff changeset
154 }