1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s |
2 | // RUN: %clang_cc1 -fsyntax-only -Wno-objc-root-class -ast-dump -ast-dump-filter test %s | FileCheck %s |
3 | |
4 | #pragma clang attribute push (__attribute__((annotate("test"))), apply_to = any(objc_interface, objc_protocol, objc_property, field, objc_method, variable)) |
5 | #pragma clang attribute push (__attribute__((objc_subclassing_restricted)), apply_to = objc_interface) |
6 | |
7 | @interface testInterface1 |
8 | // CHECK-LABEL: ObjCInterfaceDecl{{.*}}testInterface1 |
9 | // CHECK-NEXT: ObjCImplementation |
10 | // CHECK-NEXT: AnnotateAttr{{.*}} "test" |
11 | // CHECK-NEXT: ObjCSubclassingRestrictedAttr{{.*}} |
12 | |
13 | // CHECK-NOT: AnnotateAttr |
14 | // CHECK-NOT: ObjCSubclassingRestrictedAttr |
15 | |
16 | { |
17 | int testIvar1; |
18 | // CHECK-LABEL: ObjCIvarDecl{{.*}} testIvar1 |
19 | // CHECK-NEXT: AnnotateAttr{{.*}} "test" |
20 | // CHECK-NOT: ObjCSubclassingRestrictedAttr |
21 | } |
22 | |
23 | @property int testProp1; |
24 | // CHECK-LABEL: ObjCPropertyDecl{{.*}} testProp1 |
25 | // CHECK-NEXT: AnnotateAttr{{.*}} "test" |
26 | // CHECK-NOT: ObjCSubclassingRestrictedAttr |
27 | |
28 | - (void)testIm:(int) x; |
29 | // CHECK-LABEL: ObjCMethodDecl{{.*}}testIm |
30 | // CHECK-NEXT: ParmVarDecl{{.*}} x |
31 | // CHECK-NEXT: AnnotateAttr{{.*}} "test" |
32 | // CHECK-NEXT: AnnotateAttr{{.*}} "test" |
33 | // CHECK-NOT: ObjCSubclassingRestrictedAttr |
34 | |
35 | + (void)testCm; |
36 | // CHECK-LABEL: ObjCMethodDecl{{.*}}testCm |
37 | // CHECK-NEXT: AnnotateAttr{{.*}} "test" |
38 | // CHECK-NOT: ObjCSubclassingRestrictedAttr |
39 | |
40 | // Implicit getters/setters shouldn't receive the attributes. |
41 | // CHECK-LABEL: ObjCMethodDecl{{.*}}testProp1 |
42 | // CHECK-NOT: AnnotateAttr |
43 | // CHECK-LABEL: ObjCMethodDecl{{.*}}setTestProp1 |
44 | // CHECK-NOT: AnnotateAttr |
45 | |
46 | @end |
47 | |
48 | // @implementation can't receive explicit attributes, so don't add the pragma |
49 | // attributes to them. |
50 | @implementation testInterface1 |
51 | // CHECK-LABEL: ObjCImplementationDecl{{.*}}testInterface1 |
52 | // CHECK-NOT: AnnotateAttr |
53 | // CHECK-NOT: ObjCSubclassingRestrictedAttr |
54 | |
55 | { |
56 | int testIvar2; |
57 | // CHECK-LABEL: ObjCIvarDecl{{.*}} testIvar2 |
58 | // CHECK-NEXT: AnnotateAttr{{.*}} "test" |
59 | // CHECK-NOT: ObjCSubclassingRestrictedAttr |
60 | } |
61 | |
62 | // Don't add attributes to implicit parameters! |
63 | - (void)testIm:(int) x { |
64 | // CHECK-LABEL: ObjCMethodDecl{{.*}}testIm |
65 | // CHECK-NEXT: ImplicitParamDecl |
66 | // CHECK-NEXT: ImplicitParamDecl |
67 | // CHECK-NEXT: ParmVarDecl{{.*}} x |
68 | // CHECK-NEXT: AnnotateAttr{{.*}} "test" |
69 | // CHECK-NEXT: CompoundStmt |
70 | // CHECK-NEXT: AnnotateAttr{{.*}} "test" |
71 | // CHECK-NOT: ObjCSubclassingRestrictedAttr |
72 | } |
73 | |
74 | + (void)testCm { |
75 | // CHECK-LABEL: ObjCMethodDecl{{.*}}testCm |
76 | // CHECK: AnnotateAttr{{.*}} "test" |
77 | // CHECK-NOT: ObjCSubclassingRestrictedAttr |
78 | // CHECK-NOT: AnnotateAttr |
79 | _Pragma("clang attribute push (__attribute__((annotate(\"applied at container start\"))), apply_to=objc_interface)"); |
80 | } |
81 | |
82 | // Implicit ivars shouldn't receive the attributes. |
83 | // CHECK-LABEL: ObjCIvarDecl{{.*}}_testProp1 |
84 | // CHECK-NOT: AnnotateAttr |
85 | |
86 | @end |
87 | |
88 | @implementation testImplWithoutInterface // expected-warning {{cannot find interface declaration for 'testImplWithoutInterface'}} |
89 | // CHECK-LABEL: ObjCInterfaceDecl{{.*}}testImplWithoutInterface |
90 | // CHECK-NEXT: ObjCImplementation |
91 | // CHECK-NEXT: AnnotateAttr{{.*}} "test" |
92 | // CHECK-NEXT: ObjCSubclassingRestrictedAttr |
93 | // CHECK-NEXT: AnnotateAttr{{.*}} "applied at container start" |
94 | |
95 | // CHECK-LABEL: ObjCImplementationDecl{{.*}}testImplWithoutInterface |
96 | // CHECK-NOT: AnnotateAttr |
97 | // CHECK-NOT: ObjCSubclassingRestrictedAttr |
98 | |
99 | @end |
100 | |
101 | #pragma clang attribute pop |
102 | |
103 | @protocol testProtocol |
104 | // CHECK-LABEL: ObjCProtocolDecl{{.*}}testProtocol |
105 | // CHECK-NEXT: AnnotateAttr{{.*}} "test" |
106 | // CHECK-NOT: ObjCSubclassingRestrictedAttr |
107 | // CHECK-NOT: AnnotateAttr |
108 | |
109 | - (void)testProtIm; |
110 | // CHECK-LABEL: ObjCMethodDecl{{.*}}testProtIm |
111 | // CHECK-NEXT: AnnotateAttr{{.*}} "test" |
112 | // CHECK-NOT: ObjCSubclassingRestrictedAttr |
113 | |
114 | @end |
115 | |
116 | @protocol testForwardProtocol; |
117 | // CHECK-LABEL: ObjCProtocolDecl{{.*}}testForwardProtocol |
118 | // CHECK-NEXT: AnnotateAttr{{.*}} "test" |
119 | // CHECK-NOT: ObjCSubclassingRestrictedAttr |
120 | |
121 | |
122 | // Categories can't receive explicit attributes, so don't add pragma attributes |
123 | // to them. |
124 | @interface testInterface1(testCat) |
125 | // CHECK-LABEL: ObjCCategoryDecl{{.*}}testCat |
126 | // CHECK-NOT: AnnotateAttr |
127 | // CHECK-NOT: ObjCSubclassingRestrictedAttr |
128 | |
129 | @end |
130 | |
131 | @implementation testInterface1(testCat) |
132 | // CHECK-LABEL: ObjCCategoryImplDecl{{.*}}testCat |
133 | // CHECK-NOT: AnnotateAttr |
134 | // CHECK-NOT: ObjCSubclassingRestrictedAttr |
135 | |
136 | @end |
137 | |
138 | // @class/@compatibility_alias declarations can't receive explicit attributes, |
139 | // so don't add pragma attributes to them. |
140 | @class testClass; |
141 | // CHECK-LABEL: ObjCInterfaceDecl{{.*}}testClass |
142 | // CHECK-NOT: AnnotateAttr |
143 | // CHECK-NOT: ObjCSubclassingRestrictedAttr |
144 | |
145 | @compatibility_alias testCompat testInterface1; |
146 | // CHECK-LABEL: ObjCCompatibleAliasDecl{{.*}}testCompat |
147 | // CHECK-NOT: AnnotateAttr |
148 | // CHECK-NOT: ObjCSubclassingRestrictedAttr |
149 | |
150 | #pragma clang attribute pop // objc_subclassing_restricted |
151 | |
152 | @interface testInterface3 |
153 | // CHECK-LABEL: ObjCInterfaceDecl{{.*}}testInterface3 |
154 | // CHECK-NEXT: AnnotateAttr{{.*}} "test" |
155 | // CHECK-NOT: ObjCSubclassingRestrictedAttr |
156 | @end |
157 | |
158 | #pragma clang attribute pop // annotate("test") |
159 | |
160 | @interface testInterface4 |
161 | // CHECK-LABEL: ObjCInterfaceDecl{{.*}}testInterface4 |
162 | // CHECK-NOT: AnnotateAttr |
163 | // CHECK-NOT: ObjCSubclassingRestrictedAttr |
164 | @end |
165 | |