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
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)
7 @interface testInterface1
8 // CHECK-LABEL: ObjCInterfaceDecl{{.*}}testInterface1
9 // CHECK-NEXT: ObjCImplementation
10 // CHECK-NEXT: AnnotateAttr{{.*}} "test"
11 // CHECK-NEXT: ObjCSubclassingRestrictedAttr{{.*}}
13 // CHECK-NOT: AnnotateAttr
14 // CHECK-NOT: ObjCSubclassingRestrictedAttr
18 // CHECK-LABEL: ObjCIvarDecl{{.*}} testIvar1
19 // CHECK-NEXT: AnnotateAttr{{.*}} "test"
20 // CHECK-NOT: ObjCSubclassingRestrictedAttr
23 @property int testProp1;
24 // CHECK-LABEL: ObjCPropertyDecl{{.*}} testProp1
25 // CHECK-NEXT: AnnotateAttr{{.*}} "test"
26 // CHECK-NOT: ObjCSubclassingRestrictedAttr
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
36 // CHECK-LABEL: ObjCMethodDecl{{.*}}testCm
37 // CHECK-NEXT: AnnotateAttr{{.*}} "test"
38 // CHECK-NOT: ObjCSubclassingRestrictedAttr
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
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
57 // CHECK-LABEL: ObjCIvarDecl{{.*}} testIvar2
58 // CHECK-NEXT: AnnotateAttr{{.*}} "test"
59 // CHECK-NOT: ObjCSubclassingRestrictedAttr
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
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)");
82 // Implicit ivars shouldn't receive the attributes.
83 // CHECK-LABEL: ObjCIvarDecl{{.*}}_testProp1
84 // CHECK-NOT: AnnotateAttr
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"
95 // CHECK-LABEL: ObjCImplementationDecl{{.*}}testImplWithoutInterface
96 // CHECK-NOT: AnnotateAttr
97 // CHECK-NOT: ObjCSubclassingRestrictedAttr
101 #pragma clang attribute pop
103 @protocol testProtocol
104 // CHECK-LABEL: ObjCProtocolDecl{{.*}}testProtocol
105 // CHECK-NEXT: AnnotateAttr{{.*}} "test"
106 // CHECK-NOT: ObjCSubclassingRestrictedAttr
107 // CHECK-NOT: AnnotateAttr
110 // CHECK-LABEL: ObjCMethodDecl{{.*}}testProtIm
111 // CHECK-NEXT: AnnotateAttr{{.*}} "test"
112 // CHECK-NOT: ObjCSubclassingRestrictedAttr
116 @protocol testForwardProtocol;
117 // CHECK-LABEL: ObjCProtocolDecl{{.*}}testForwardProtocol
118 // CHECK-NEXT: AnnotateAttr{{.*}} "test"
119 // CHECK-NOT: ObjCSubclassingRestrictedAttr
122 // Categories can't receive explicit attributes, so don't add pragma attributes
124 @interface testInterface1(testCat)
125 // CHECK-LABEL: ObjCCategoryDecl{{.*}}testCat
126 // CHECK-NOT: AnnotateAttr
127 // CHECK-NOT: ObjCSubclassingRestrictedAttr
131 @implementation testInterface1(testCat)
132 // CHECK-LABEL: ObjCCategoryImplDecl{{.*}}testCat
133 // CHECK-NOT: AnnotateAttr
134 // CHECK-NOT: ObjCSubclassingRestrictedAttr
138 // @class/@compatibility_alias declarations can't receive explicit attributes,
139 // so don't add pragma attributes to them.
141 // CHECK-LABEL: ObjCInterfaceDecl{{.*}}testClass
142 // CHECK-NOT: AnnotateAttr
143 // CHECK-NOT: ObjCSubclassingRestrictedAttr
145 @compatibility_alias testCompat testInterface1;
146 // CHECK-LABEL: ObjCCompatibleAliasDecl{{.*}}testCompat
147 // CHECK-NOT: AnnotateAttr
148 // CHECK-NOT: ObjCSubclassingRestrictedAttr
150 #pragma clang attribute pop // objc_subclassing_restricted
152 @interface testInterface3
153 // CHECK-LABEL: ObjCInterfaceDecl{{.*}}testInterface3
154 // CHECK-NEXT: AnnotateAttr{{.*}} "test"
155 // CHECK-NOT: ObjCSubclassingRestrictedAttr
158 #pragma clang attribute pop // annotate("test")
160 @interface testInterface4
161 // CHECK-LABEL: ObjCInterfaceDecl{{.*}}testInterface4
162 // CHECK-NOT: AnnotateAttr
163 // CHECK-NOT: ObjCSubclassingRestrictedAttr