annotate clang/test/SemaObjC/deprecated-objc-introspection.m @ 180:680fa57a2f20

fix compile errors.
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 30 May 2020 17:44:06 +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 -triple=x86_64-apple-darwin -fsyntax-only -verify %s
anatofuz
parents:
diff changeset
2
anatofuz
parents:
diff changeset
3 //====------------------------------------------------------------====//
anatofuz
parents:
diff changeset
4 // Test deprecated direct usage of the 'isa' pointer.
anatofuz
parents:
diff changeset
5 //====------------------------------------------------------------====//
anatofuz
parents:
diff changeset
6
anatofuz
parents:
diff changeset
7 typedef unsigned long NSUInteger;
anatofuz
parents:
diff changeset
8
anatofuz
parents:
diff changeset
9 typedef struct objc_object {
anatofuz
parents:
diff changeset
10 struct objc_class *isa;
anatofuz
parents:
diff changeset
11 } *id;
anatofuz
parents:
diff changeset
12
anatofuz
parents:
diff changeset
13 @interface NSObject {
anatofuz
parents:
diff changeset
14 id firstobj;
anatofuz
parents:
diff changeset
15 struct objc_class *isa;
anatofuz
parents:
diff changeset
16 }
anatofuz
parents:
diff changeset
17 - (id)performSelector:(SEL)aSelector;;
anatofuz
parents:
diff changeset
18 @end
anatofuz
parents:
diff changeset
19 @interface Whatever : NSObject
anatofuz
parents:
diff changeset
20 +self;
anatofuz
parents:
diff changeset
21 -(id)foo;
anatofuz
parents:
diff changeset
22 @end
anatofuz
parents:
diff changeset
23
anatofuz
parents:
diff changeset
24 static void func() {
anatofuz
parents:
diff changeset
25
anatofuz
parents:
diff changeset
26 id x;
anatofuz
parents:
diff changeset
27
anatofuz
parents:
diff changeset
28 // rdar://8290002
anatofuz
parents:
diff changeset
29 [(*x).isa self]; // expected-warning {{direct access to Objective-C's isa is deprecated in favor of object_getClass()}}
anatofuz
parents:
diff changeset
30 [x->isa self]; // expected-warning {{direct access to Objective-C's isa is deprecated in favor of object_getClass()}}
anatofuz
parents:
diff changeset
31
anatofuz
parents:
diff changeset
32 Whatever *y;
anatofuz
parents:
diff changeset
33
anatofuz
parents:
diff changeset
34 // GCC allows this, with the following warning:
anatofuz
parents:
diff changeset
35 // instance variable 'isa' is @protected; this will be a hard error in the future
anatofuz
parents:
diff changeset
36 //
anatofuz
parents:
diff changeset
37 // FIXME: see if we can avoid the warning that follows the error.
anatofuz
parents:
diff changeset
38 [(*y).isa self]; // expected-error {{instance variable 'isa' is protected}} \
anatofuz
parents:
diff changeset
39 expected-warning{{receiver type 'struct objc_class *' is not 'id' or interface pointer, consider casting it to 'id'}}
anatofuz
parents:
diff changeset
40 [y->isa self]; // expected-error {{instance variable 'isa' is protected}} \
anatofuz
parents:
diff changeset
41 expected-warning{{receiver type 'struct objc_class *' is not 'id' or interface pointer, consider casting it to 'id'}}
anatofuz
parents:
diff changeset
42 }
anatofuz
parents:
diff changeset
43
anatofuz
parents:
diff changeset
44 // rdar://11702488
anatofuz
parents:
diff changeset
45 // If an ivar is (1) the first ivar in a root class and (2) named `isa`,
anatofuz
parents:
diff changeset
46 // then it should get the same warnings that id->isa gets.
anatofuz
parents:
diff changeset
47
anatofuz
parents:
diff changeset
48 @interface BaseClass {
anatofuz
parents:
diff changeset
49 @public
anatofuz
parents:
diff changeset
50 Class isa; // expected-note 4 {{instance variable is declared here}}
anatofuz
parents:
diff changeset
51 }
anatofuz
parents:
diff changeset
52 @end
anatofuz
parents:
diff changeset
53
anatofuz
parents:
diff changeset
54 @interface OtherClass {
anatofuz
parents:
diff changeset
55 @public
anatofuz
parents:
diff changeset
56 id firstIvar;
anatofuz
parents:
diff changeset
57 Class isa; // note, not first ivar;
anatofuz
parents:
diff changeset
58 }
anatofuz
parents:
diff changeset
59 @end
anatofuz
parents:
diff changeset
60
anatofuz
parents:
diff changeset
61 @interface Subclass : BaseClass @end
anatofuz
parents:
diff changeset
62
anatofuz
parents:
diff changeset
63 @interface SiblingClass : BaseClass @end
anatofuz
parents:
diff changeset
64
anatofuz
parents:
diff changeset
65 @interface Root @end
anatofuz
parents:
diff changeset
66
anatofuz
parents:
diff changeset
67 @interface hasIsa : Root {
anatofuz
parents:
diff changeset
68 @public
anatofuz
parents:
diff changeset
69 Class isa; // note, isa is not in root class
anatofuz
parents:
diff changeset
70 }
anatofuz
parents:
diff changeset
71 @end
anatofuz
parents:
diff changeset
72
anatofuz
parents:
diff changeset
73 @implementation Subclass
anatofuz
parents:
diff changeset
74 -(void)method {
anatofuz
parents:
diff changeset
75 hasIsa *u;
anatofuz
parents:
diff changeset
76 id v;
anatofuz
parents:
diff changeset
77 BaseClass *w;
anatofuz
parents:
diff changeset
78 Subclass *x;
anatofuz
parents:
diff changeset
79 SiblingClass *y;
anatofuz
parents:
diff changeset
80 OtherClass *z;
anatofuz
parents:
diff changeset
81 (void)v->isa; // expected-warning {{direct access to Objective-C's isa is deprecated in favor of object_getClass()}}
anatofuz
parents:
diff changeset
82 (void)w->isa; // expected-warning {{direct access to Objective-C's isa is deprecated in favor of object_getClass()}}
anatofuz
parents:
diff changeset
83 (void)x->isa; // expected-warning {{direct access to Objective-C's isa is deprecated in favor of object_getClass()}}
anatofuz
parents:
diff changeset
84 (void)y->isa; // expected-warning {{direct access to Objective-C's isa is deprecated in favor of object_getClass()}}
anatofuz
parents:
diff changeset
85 (void)z->isa;
anatofuz
parents:
diff changeset
86 (void)u->isa;
anatofuz
parents:
diff changeset
87
anatofuz
parents:
diff changeset
88 w->isa = 0; // expected-warning {{assignment to Objective-C's isa is deprecated in favor of object_setClass()}}
anatofuz
parents:
diff changeset
89 }
anatofuz
parents:
diff changeset
90 @end
anatofuz
parents:
diff changeset
91
anatofuz
parents:
diff changeset
92 // Test for introspection of Objective-C pointers via bitmasking.
anatofuz
parents:
diff changeset
93
anatofuz
parents:
diff changeset
94 void testBitmasking(NSObject *p) {
anatofuz
parents:
diff changeset
95 (void) (((NSUInteger) p) & 0x1); // expected-warning {{bitmasking for introspection of Objective-C object pointers is strongly discouraged}}
anatofuz
parents:
diff changeset
96 (void) (0x1 & ((NSUInteger) p)); // expected-warning {{bitmasking for introspection of Objective-C object pointers is strongly discouraged}}
anatofuz
parents:
diff changeset
97 (void) (((NSUInteger) p) ^ 0x1); // no-warning
anatofuz
parents:
diff changeset
98 (void) (0x1 ^ ((NSUInteger) p)); // no-warning
anatofuz
parents:
diff changeset
99 (void) (0x1 & ((NSUInteger) [p performSelector:@selector(foo)])); // expected-warning {{bitmasking for introspection of Objective-C object pointers is strongly discouraged}}
anatofuz
parents:
diff changeset
100 #pragma clang diagnostic push
anatofuz
parents:
diff changeset
101 #pragma clang diagnostic ignored "-Wdeprecated-objc-pointer-introspection-performSelector"
anatofuz
parents:
diff changeset
102 (void) (0x1 & ((NSUInteger) [p performSelector:@selector(foo)])); // no-warning
anatofuz
parents:
diff changeset
103 #pragma clang diagnostic pop
anatofuz
parents:
diff changeset
104 }