xref: /llvm-project/clang/test/CodeGenObjC/non-runtime-protocol.m (revision 9466b49171dc4b21f56a48594fc82b1e52f5358a)
1// RUN: not %clang_cc1 -emit-llvm -fobjc-arc -triple x86_64-apple-darwin10 %s -DPROTOEXPR -o - 2>&1 \
2// RUN:     | FileCheck -check-prefix=PROTOEXPR %s
3
4// RUN: %clang_cc1 -emit-llvm -fobjc-arc -triple x86_64-apple-darwin10 %s -DREDUNDANCY -o - \
5// RUN:     | FileCheck -check-prefix=REDUNDANCY1 %s
6// RUN: %clang_cc1 -emit-llvm -fobjc-arc -triple x86_64-apple-darwin10 %s -DREDUNDANCY -o - \
7// RUN:     | FileCheck -check-prefix=REDUNDANCY2 %s
8
9// RUN: %clang_cc1 -emit-llvm -fobjc-arc -triple x86_64-apple-darwin10 %s -DBASE -o - \
10// RUN:     | FileCheck -check-prefix=NONFRAGILE %s
11// RUN: %clang_cc1 -emit-llvm -fobjc-arc -triple x86_64-apple-darwin10 %s -DINHERITANCE -o - \
12// RUN:     | FileCheck -check-prefix=INHERITANCE %s
13
14// RUN: %clang_cc1 -emit-llvm -triple x86_64-apple-darwin -fobjc-runtime=macosx-fragile-10.5 %s -DBASE -o - \
15// RUN:     | FileCheck -check-prefix=FRAGILE %s
16// RUN: %clang_cc1 -emit-llvm -triple x86_64-apple-darwin -fobjc-runtime=macosx-fragile-10.5 %s -DINHERITANCE -o - \
17// RUN:     | FileCheck -check-prefix=FRAGILEINHERITANCE %s
18
19// RUN: %clang_cc1 -emit-llvm -triple x86_64-linux-gnu -fobjc-runtime=gnustep %s -DBASE -o - \
20// RUN:     | FileCheck -check-prefix=GNU %s
21// RUN: %clang_cc1 -emit-llvm -triple x86_64-linux-gnu -fobjc-runtime=gnustep %s -DINHERITANCE -o - \
22// RUN:     | FileCheck -check-prefix=GNUINHERITANCE %s
23//
24// RUN: %clang_cc1 -emit-llvm -triple x86_64-linux-gnu -fobjc-runtime=gnustep-2 %s -DBASE -o - \
25// RUN:     | FileCheck -check-prefix=GNU2 %s
26// RUN: %clang_cc1 -emit-llvm -triple x86_64-linux-gnu -fobjc-runtime=gnustep-2 %s -DINHERITANCE -o - \
27// RUN:     | FileCheck -check-prefix=GNU2INHERITANCE %s
28
29__attribute__((objc_root_class))
30@interface Root
31@end
32@implementation Root
33@end
34
35#ifdef REDUNDANCY
36// REDUNDANCY1-NOT: _OBJC_CLASS_PROTOCOLS_$_Implementer{{.*}}_OBJC_PROTOCOL_$_B
37// REDUNDANCY2:     _OBJC_CLASS_PROTOCOLS_$_Implementer{{.*}}_OBJC_PROTOCOL_$_C{{.*}}_OBJC_PROTOCOL_$_A
38@protocol C
39@end
40@protocol B <C>
41@end
42@protocol A <B>
43@end
44__attribute__((objc_non_runtime_protocol)) @protocol Alpha<A>
45@end
46__attribute__((objc_non_runtime_protocol)) @protocol Beta<B>
47@end
48@interface Implementer : Root <Alpha, Beta, C>
49@end
50@implementation Implementer
51@end
52#endif
53
54#ifdef BASE
55// Confirm that we're not emitting protocol information for the
56// NONFRAGILE-NOT: OBJC_CLASS_NAME{{.*}}NonRuntimeProtocol
57// NONFRAGILE-NOT: _OBJC_$_PROTOCOL_INSTANCE_METHODS_NonRuntimeProtocol
58// NONFRAGILE-NOT: _OBJC_$_PROTOCOL_CLASS_METHODS_NonRuntimeProtocol
59// NONFRAGILE-NOT: _OBJC_PROTOCOL_$_NonRuntimeProtocol
60// NONFRAGILE-NOT: _OBJC_LABEL_PROTOCOL_$_NonRuntimeProtocol
61// NONFRAGILE-NOT: _OBJC_CLASS_PROTOCOLS_$_NonRuntimeImplementer
62// FRAGILE-NOT: OBJC_CLASS_NAME_.{{.*}}"Runtime\00"
63// FRAGILE-NOT: OBJC_PROTOCOL_NonRuntime
64// FRAGILE-NOT: OBJC_PROTOCOLS_NonRuntimeImplementer
65// GNU-NOT: private unnamed_addr constant {{.*}} c"NonRuntimeProtocol\00"
66// GNU-NOT: @.objc_protocol {{.*}}
67// GNU2-NOT: private unnamed_addr constant {{.*}} c"NonRuntimeProtocol\00"
68// GNU2-NOT: @.objc_protocol {{.*}}
69__attribute__((objc_non_runtime_protocol))
70@protocol NonRuntimeProtocol
71- (void)doThing;
72+ (void)doClassThing;
73@end
74// NONFRAGILE: @"_OBJC_METACLASS_RO_$_NonRuntimeImplementer" {{.*}} ptr null
75// NONFRAGILE: @"_OBJC_CLASS_RO_$_NonRuntimeImplementer" {{.*}} ptr null
76@interface NonRuntimeImplementer : Root <NonRuntimeProtocol>
77- (void)doThing;
78+ (void)doClassThing;
79@end
80
81@implementation NonRuntimeImplementer
82- (void)doThing {
83}
84+ (void)doClassThing {
85}
86@end
87#endif
88
89#ifdef PROTOEXPR
90__attribute__((objc_non_runtime_protocol))
91@protocol NonRuntimeProtocol
92@end
93void use() {
94  // PROTOEXPR: cannot use a protocol declared 'objc_non_runtime_protocol' in a @protocol expression
95  Protocol *p = @protocol(NonRuntimeProtocol);
96}
97#endif
98
99#ifdef INHERITANCE
100// Confirm that we only emit references to the non-runtime protocols and
101// properly walk the DAG to find the right protocols.
102// INHERITANCE: OBJC_PROTOCOL_$_R2{{.*}}
103// INHERITANCE: OBJC_PROTOCOL_$_R3{{.*}}
104// INHERITANCE: @"_OBJC_CLASS_PROTOCOLS_$_Implementer" {{.*}}_OBJC_PROTOCOL_$_R2{{.*}}_OBJC_PROTOCOL_$_R3
105
106// FRAGILEINHERITANCE: OBJC_PROTOCOL_R2
107// FRAGILEINHERITANCE: OBJC_PROTOCOL_R3
108// FRAGILEINHERITANCE: OBJC_CLASS_PROTOCOLS_Implementer{{.*}}OBJC_PROTOCOL_R2{{.*}}OBJC_PROTOCOL_R3
109
110// GNUINHERITANCE-DAG: @[[Proto1:[0-9]]]{{.*}}c"R1\00"
111// GNUINHERITANCE-DAG: [[P1Name:@.objc_protocol.[0-9]*]]{{.*}}@[[Proto1]]
112// GNUINHERITANCE-DAG: @[[Proto2:[0-9]]]{{.*}}c"R2\00"
113// GNUINHERITANCE-DAG: [[P2Name:@.objc_protocol.[0-9]+]]{{.*}}@[[Proto2]]
114// GNUINHERITANCE-DAG: @[[Proto3:[0-9]]]{{.*}}c"R3\00"
115// GNUINHERITANCE-DAG: [[P3Name:@.objc_protocol.[0-9]+]]{{.*}}@[[Proto3]]
116// GNUINHERITANCE-DAG: @.objc_protocol_list{{.*}}
117// GNUINHERITANCE: @.objc_protocol_list{{.*}}[[Proto3]]{{.*}}[[Proto2]]
118
119// GNU2INHERITANCE-DAG: @[[Proto1:[0-9]]]{{.*}}c"R1\00"
120// GNU2INHERITANCE-DAG: _OBJC_PROTOCOL_R1{{.*}}@[[Proto1]]
121// GNU2INHERITANCE-DAG: @[[Proto2:[0-9]]]{{.*}}c"R2\00"
122// GNU2INHERITANCE-DAG: _OBJC_PROTOCOL_R2{{.*}}@[[Proto2]]
123// GNU2INHERITANCE-DAG: @[[Proto3:[0-9]]]{{.*}}c"R3\00"
124// GNU2INHERITANCE-DAG: _OBJC_PROTOCOL_R3{{.*}}@[[Proto3]]
125// GNU2INHERITANCE: @.objc_protocol_list{{.*}}_OBJC_PROTOCOL_R2{{.*}}_OBJC_PROTOCOL_R3
126@protocol R1
127@end
128@protocol R2
129@end
130@protocol R3 <R1>
131@end
132__attribute__((objc_non_runtime_protocol)) @protocol N3
133@end
134__attribute__((objc_non_runtime_protocol)) @protocol N1<R3, R2, N3>
135@end
136__attribute__((objc_non_runtime_protocol)) @protocol N2<N1, R2>
137@end
138@interface Implementer : Root <N2, R2>
139@end
140@implementation Implementer
141@end
142#endif
143