3 .*runtime.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\](\n.* note: expanded from macro 'testassert')?
4 .*runtime.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\](\n.* note: expanded from macro 'testassert')?
5 .*runtime.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\](\n.* note: expanded from macro 'testassert')?
9 objc\[\d+\]: class `SwiftV1Class\' not linked into application
10 objc\[\d+\]: class `DoesNotExist\' not linked into application
13 confused by Foundation
23 #include <mach-o/ldsyms.h>
24 #include <objc/objc-runtime.h>
26 #if __has_feature(objc_arc)
30 // provoke the same nullability warnings as the real test
35 testwarn("rdar://11368528 confused by Foundation");
36 fprintf(stderr, "confused by Foundation\n");
42 @interface Sub : TestRoot @end
43 @implementation Sub @end
45 #define SwiftV1MangledName "_TtC6Module12SwiftV1Class"
46 #define SwiftV1MangledName2 "_TtC2Sw13SwiftV1Class2"
47 #define SwiftV1MangledName3 "_TtCs13SwiftV1Class3"
48 #define SwiftV1MangledName4 "_TtC6Swiftt13SwiftV1Class4"
50 __attribute__((objc_runtime_name(SwiftV1MangledName)))
51 @interface SwiftV1Class : TestRoot @end
52 @implementation SwiftV1Class @end
54 __attribute__((objc_runtime_name(SwiftV1MangledName2)))
55 @interface SwiftV1Class2 : TestRoot @end
56 @implementation SwiftV1Class2 @end
58 __attribute__((objc_runtime_name(SwiftV1MangledName3)))
59 @interface SwiftV1Class3 : TestRoot @end
60 @implementation SwiftV1Class3 @end
62 __attribute__((objc_runtime_name(SwiftV1MangledName4)))
63 @interface SwiftV1Class4 : TestRoot @end
64 @implementation SwiftV1Class4 @end
71 unsigned int count, count0, count2;
76 int foundSwiftV1class2;
77 int foundSwiftV1class3;
78 int foundSwiftV1class4;
80 const char **namesFromHeader;
85 // This shouldn't touch any classes.
86 dladdr(&_mh_execute_header, &info);
87 names = objc_copyClassNamesForImage(info.dli_fname, &count);
89 testassert(count == 6);
90 testassert(names[count] == NULL);
94 foundSwiftV1class2 = 0;
95 foundSwiftV1class3 = 0;
96 foundSwiftV1class4 = 0;
97 for (i = 0; i < count; i++) {
98 if (0 == strcmp(names[i], "TestRoot")) foundTestRoot++;
99 if (0 == strcmp(names[i], "Sub")) foundSub++;
100 if (0 == strcmp(names[i], "Module.SwiftV1Class")) foundSwiftV1++;
101 if (0 == strcmp(names[i], "Sw.SwiftV1Class2")) foundSwiftV1class2++;
102 if (0 == strcmp(names[i], "Swift.SwiftV1Class3")) foundSwiftV1class3++;
103 if (0 == strcmp(names[i], "Swiftt.SwiftV1Class4")) foundSwiftV1class4++;
105 testassert(foundTestRoot == 1);
106 testassert(foundSub == 1);
107 testassert(foundSwiftV1 == 1);
108 testassert(foundSwiftV1class2 == 1);
109 testassert(foundSwiftV1class3 == 1);
110 testassert(foundSwiftV1class4 == 1);
112 // Getting the names using the header should give us the same list.
113 namesFromHeader = objc_copyClassNamesForImage(info.dli_fname, &count0);
114 testassert(namesFromHeader);
115 testassert(count == count0);
116 for (i = 0; i < count; i++) {
117 testassert(!strcmp(names[i], namesFromHeader[i]));
121 // class Sub hasn't been touched - make sure it's in the class list too
122 count0 = objc_getClassList(NULL, 0);
123 testassert(count0 >= 2 && count0 < 100);
125 list[count0-1] = NULL;
126 count = objc_getClassList(list, count0-1);
127 testassert(list[count0-1] == NULL);
128 testassert(count == count0);
130 // So that demangling works, fake what would have happened with Swift
131 // and force the "Swift" bit on the class
132 ((uintptr_t *)objc_getClass(SwiftV1MangledName))[4] |= 2;
133 ((uintptr_t *)objc_getClass(SwiftV1MangledName2))[4] |= 2;
134 ((uintptr_t *)objc_getClass(SwiftV1MangledName3))[4] |= 2;
135 ((uintptr_t *)objc_getClass(SwiftV1MangledName4))[4] |= 2;
137 count = objc_getClassList(list, count0);
138 testassert(count == count0);
140 for (i = 0; i < count; i++) {
141 testprintf("%s\n", class_getName(list[i]));
147 foundSwiftV1class2 = 0;
148 foundSwiftV1class3 = 0;
149 foundSwiftV1class4 = 0;
150 for (i = 0; i < count; i++) {
151 if (0 == strcmp(class_getName(list[i]), "TestRoot")) foundTestRoot++;
152 if (0 == strcmp(class_getName(list[i]), "Sub")) foundSub++;
153 if (0 == strcmp(class_getName(list[i]), "Module.SwiftV1Class")) foundSwiftV1++;
154 if (0 == strcmp(class_getName(list[i]), "Sw.SwiftV1Class2")) foundSwiftV1class2++;
155 if (0 == strcmp(class_getName(list[i]), "Swift.SwiftV1Class3")) foundSwiftV1class3++;
156 if (0 == strcmp(class_getName(list[i]), "Swiftt.SwiftV1Class4")) foundSwiftV1class4++;
157 // list should be non-meta classes only
158 testassert(!class_isMetaClass(list[i]));
160 testassert(foundTestRoot == 1);
161 testassert(foundSub == 1);
162 testassert(foundSwiftV1 == 1);
163 testassert(foundSwiftV1class2 == 1);
164 testassert(foundSwiftV1class3 == 1);
165 testassert(foundSwiftV1class4 == 1);
167 // fixme check class handler
168 testassert(objc_getClass("TestRoot") == [TestRoot class]);
169 testassert(objc_getClass("Module.SwiftV1Class") == [SwiftV1Class class]);
170 testassert(objc_getClass(SwiftV1MangledName) == [SwiftV1Class class]);
171 testassert(objc_getClass("Sw.SwiftV1Class2") == [SwiftV1Class2 class]);
172 testassert(objc_getClass(SwiftV1MangledName2) == [SwiftV1Class2 class]);
173 testassert(objc_getClass("Swift.SwiftV1Class3") == [SwiftV1Class3 class]);
174 testassert(objc_getClass(SwiftV1MangledName3) == [SwiftV1Class3 class]);
175 testassert(objc_getClass("Swiftt.SwiftV1Class4") == [SwiftV1Class4 class]);
176 testassert(objc_getClass(SwiftV1MangledName4) == [SwiftV1Class4 class]);
177 testassert(objc_getClass("SwiftV1Class") == nil);
178 testassert(objc_getClass("DoesNotExist") == nil);
179 testassert(objc_getClass(NULL) == nil);
181 testassert(objc_getMetaClass("TestRoot") == object_getClass([TestRoot class]));
182 testassert(objc_getMetaClass("Module.SwiftV1Class") == object_getClass([SwiftV1Class class]));
183 testassert(objc_getMetaClass(SwiftV1MangledName) == object_getClass([SwiftV1Class class]));
184 testassert(objc_getMetaClass("SwiftV1Class") == nil);
185 testassert(objc_getMetaClass("DoesNotExist") == nil);
186 testassert(objc_getMetaClass(NULL) == nil);
188 // fixme check class no handler
189 testassert(objc_lookUpClass("TestRoot") == [TestRoot class]);
190 testassert(objc_lookUpClass("Module.SwiftV1Class") == [SwiftV1Class class]);
191 testassert(objc_lookUpClass(SwiftV1MangledName) == [SwiftV1Class class]);
192 testassert(objc_lookUpClass("SwiftV1Class") == nil);
193 testassert(objc_lookUpClass("DoesNotExist") == nil);
194 testassert(objc_lookUpClass(NULL) == nil);
196 testassert(! object_isClass(nil));
197 testassert(! object_isClass([TestRoot new]));
198 testassert(object_isClass([TestRoot class]));
199 testassert(object_isClass(object_getClass([TestRoot class])));
200 testassert(object_isClass([Sub class]));
201 testassert(object_isClass(object_getClass([Sub class])));
202 testassert(object_isClass([SwiftV1Class class]));
203 testassert(object_isClass(object_getClass([SwiftV1Class class])));
205 list2 = objc_copyClassList(&count2);
206 testassert(count2 == count);
208 testassert(malloc_size(list2) >= (1+count2) * sizeof(Class));
209 for (i = 0; i < count; i++) {
210 testassert(list[i] == list2[i]);
212 testassert(list2[count] == NULL);
214 free(objc_copyClassList(NULL));
216 // Make sure metaclasses get demangled too.
217 testassert(strcmp(class_getName([TestRoot class]), class_getName(object_getClass([TestRoot class]))) == 0);
218 testassert(strcmp(class_getName([Sub class]), class_getName(object_getClass([Sub class]))) == 0);
219 testassert(strcmp(class_getName([SwiftV1Class class]), class_getName(object_getClass([SwiftV1Class class]))) == 0);
220 testassert(strcmp(class_getName([SwiftV1Class2 class]), class_getName(object_getClass([SwiftV1Class2 class]))) == 0);
221 testassert(strcmp(class_getName([SwiftV1Class3 class]), class_getName(object_getClass([SwiftV1Class3 class]))) == 0);
222 testassert(strcmp(class_getName([SwiftV1Class4 class]), class_getName(object_getClass([SwiftV1Class4 class]))) == 0);
224 testassert(!_class_isSwift([TestRoot class]));
225 testassert(!_class_isSwift([Sub class]));
226 testassert(_class_isSwift([SwiftV1Class class]));
227 testassert(_class_isSwift([SwiftV1Class2 class]));
228 testassert(_class_isSwift([SwiftV1Class3 class]));
229 testassert(_class_isSwift([SwiftV1Class4 class]));