Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / SemaObjC / potentially-direct-selector.m
blobc5c9f39718bfc29104f6c58e9b28cbb5ac375bcd
1 // RUN: %clang_cc1 %s -Wpotentially-direct-selector -verify
2 // RUN: %clang_cc1 %s -Wstrict-potentially-direct-selector -verify=expected,strict
4 #define NS_DIRECT __attribute__((objc_direct))
6 __attribute__((objc_root_class))
7 @interface Dummies
8 -(void)inBase;
9 -(void)inBaseImpl;
10 -(void)inBaseCat;
11 -(void)inBaseCatImpl;
12 -(void)inDerived;
13 -(void)inDerivedImpl;
14 -(void)inDerivedCat;
15 -(void)inDerivedCatImpl;
16 +(void)inBaseClass;
17 +(void)inDerivedClass;
18 +(void)inDerivedCatClass;
19 @end
21 __attribute__((objc_root_class))
22 @interface Base
23 -(void)inBase NS_DIRECT; // expected-note + {{direct method}}
24 +(void)inBaseClass NS_DIRECT;  // expected-note + {{direct method}}
25 @end
27 @implementation Base
28 -(void)inBaseImpl NS_DIRECT { // expected-note + {{direct method}}
30 -(void)inBase {}
31 +(void)inBaseClass {}
32 @end
34 @interface Base (Cat)
35 -(void)inBaseCat NS_DIRECT; // expected-note + {{direct method}}
36 @end
38 @implementation Base (Cat)
39 -(void)inBaseCatImpl NS_DIRECT { // expected-note + {{direct method}}
41 -(void)inBaseCat {}
42 @end
44 @interface Derived : Base
45 -(void)inDerived NS_DIRECT; // expected-note + {{direct method}}
46 +(void)inDerivedClass NS_DIRECT;  // expected-note + {{direct method}}
47 @end
49 @implementation Derived
50 -(void)inDerivedImpl NS_DIRECT { // expected-note + {{direct method}}
52 -(void)inDerived {}
53 +(void)inDerivedClass {}
54 @end
56 @interface Derived (Cat)
57 -(void)inDerivedCat NS_DIRECT; // expected-note + {{direct method}}
58 +(void)inDerivedCatClass NS_DIRECT; // expected-note + {{direct method}}
59 @end
61 @implementation Derived (Cat)
62 -(void)inDerivedCatImpl NS_DIRECT { // expected-note + {{direct method}}
64 -(void)inDerivedCat {}
65 +(void)inDerivedCatClass {}
67 -(void)test1 {
68   (void)@selector(inBase); // expected-warning{{@selector expression formed with potentially direct selector}}
69   (void)@selector(inBaseImpl); // expected-warning{{@selector expression formed with potentially direct selector}}
70   (void)@selector(inBaseCat); // expected-warning{{@selector expression formed with potentially direct selector}}
71   (void)@selector(inBaseCatImpl); // expected-warning{{@selector expression formed with potentially direct selector}}
72   (void)@selector(inDerived); // expected-warning{{@selector expression formed with potentially direct selector}}
73   (void)@selector(inDerivedImpl); // expected-warning{{@selector expression formed with potentially direct selector}}
74   (void)@selector(inDerivedCat); // expected-warning{{@selector expression formed with potentially direct selector}}
75   (void)@selector(inDerivedCatImpl); // expected-warning{{@selector expression formed with potentially direct selector}}
76   (void)@selector(inDerivedClass); // expected-warning{{@selector expression formed with potentially direct selector}}
77   (void)@selector(inBaseClass); // expected-warning{{@selector expression formed with potentially direct selector}}
78   (void)@selector(inDerivedCatClass); // expected-warning{{@selector expression formed with potentially direct selector}}
80 @end
82 void test2(void) {
83   (void)@selector(inBase); // strict-warning{{@selector expression formed with potentially direct selector}}
84   (void)@selector(inBaseImpl); // strict-warning{{@selector expression formed with potentially direct selector}}
85   (void)@selector(inBaseCat); // strict-warning{{@selector expression formed with potentially direct selector}}
86   (void)@selector(inBaseCatImpl); // strict-warning{{@selector expression formed with potentially direct selector}}
87   (void)@selector(inDerived); // strict-warning{{@selector expression formed with potentially direct selector}}
88   (void)@selector(inDerivedImpl); // strict-warning{{@selector expression formed with potentially direct selector}}
89   (void)@selector(inDerivedCat); // strict-warning{{@selector expression formed with potentially direct selector}}
90   (void)@selector(inDerivedCatImpl); // strict-warning{{@selector expression formed with potentially direct selector}}
91   (void)@selector(inDerivedClass); // strict-warning{{@selector expression formed with potentially direct selector}}
92   (void)@selector(inBaseClass); // strict-warning{{@selector expression formed with potentially direct selector}}
93   (void)@selector(inDerivedCatClass); // strict-warning{{@selector expression formed with potentially direct selector}}
96 @interface OnlyBase : Base @end
97 @implementation OnlyBase
98 -(void)test3 {
99   (void)@selector(inBase); // expected-warning{{@selector expression formed with potentially direct selector}}
100   (void)@selector(inBaseImpl); // expected-warning{{@selector expression formed with potentially direct selector}}
101   (void)@selector(inBaseCat); // expected-warning{{@selector expression formed with potentially direct selector}}
102   (void)@selector(inBaseCatImpl); // expected-warning{{@selector expression formed with potentially direct selector}}
103   (void)@selector(inDerived); // strict-warning{{@selector expression formed with potentially direct selector}}
104   (void)@selector(inDerivedImpl); // strict-warning{{@selector expression formed with potentially direct selector}}
105   (void)@selector(inDerivedCat); // strict-warning{{@selector expression formed with potentially direct selector}}
106   (void)@selector(inDerivedCatImpl); // strict-warning{{@selector expression formed with potentially direct selector}}
107   (void)@selector(inDerivedClass); // strict-warning{{@selector expression formed with potentially direct selector}}
108   (void)@selector(inBaseClass); // expected-warning{{@selector expression formed with potentially direct selector}}
109   (void)@selector(inDerivedCatClass); // strict-warning{{@selector expression formed with potentially direct selector}}
111 @end
113 __attribute__((objc_root_class))
114 @interface Unrelated @end
115 @implementation Unrelated
116 -(void)test4 {
117   (void)@selector(inBase); // strict-warning{{@selector expression formed with potentially direct selector}}
118   (void)@selector(inBaseImpl); // strict-warning{{@selector expression formed with potentially direct selector}}
119   (void)@selector(inBaseCat); // strict-warning{{@selector expression formed with potentially direct selector}}
120   (void)@selector(inBaseCatImpl); // strict-warning{{@selector expression formed with potentially direct selector}}
121   (void)@selector(inDerived); // strict-warning{{@selector expression formed with potentially direct selector}}
122   (void)@selector(inDerivedImpl); // strict-warning{{@selector expression formed with potentially direct selector}}
123   (void)@selector(inDerivedCat); // strict-warning{{@selector expression formed with potentially direct selector}}
124   (void)@selector(inDerivedCatImpl); // strict-warning{{@selector expression formed with potentially direct selector}}
125   (void)@selector(inDerivedClass); // strict-warning{{@selector expression formed with potentially direct selector}}
126   (void)@selector(inBaseClass); // strict-warning{{@selector expression formed with potentially direct selector}}
127   (void)@selector(inDerivedCatClass); // strict-warning{{@selector expression formed with potentially direct selector}}
129 @end
131 @implementation Dummies
132 -(void)inBase {}
133 -(void)inBaseImpl {}
134 -(void)inBaseCat {}
135 -(void)inBaseCatImpl {}
136 -(void)inDerived {}
137 -(void)inDerivedImpl {}
138 -(void)inDerivedCat {}
139 -(void)inDerivedCatImpl {}
140 +(void)inBaseClass {}
141 +(void)inDerivedClass {}
142 +(void)inDerivedCatClass {}
144 -(void)test5 {
145   (void)@selector(inBase);
146   (void)@selector(inBaseImpl);
147   (void)@selector(inBaseCat);
148   (void)@selector(inBaseCatImpl);
149   (void)@selector(inDerived);
150   (void)@selector(inDerivedImpl);
151   (void)@selector(inDerivedCat);
152   (void)@selector(inDerivedCatImpl);
153   (void)@selector(inDerivedClass);
154   (void)@selector(inBaseClass);
155   (void)@selector(inDerivedCatClass);
157 @end