]> git.saurik.com Git - apple/objc4.git/blob - test/badCache.m
b9dfddb1ceee7661a8f2a3b3ae62a73ff9d57839
[apple/objc4.git] / test / badCache.m
1 /*
2 TEST_CRASHES
3 TEST_RUN_OUTPUT
4 objc1
5 OK: badCache.m
6 OR
7 crash now
8 objc\[\d+\]: Method cache corrupted.*
9 objc\[\d+\]: .*
10 objc\[\d+\]: .*
11 objc\[\d+\]: .*
12 objc\[\d+\]: .*
13 objc\[\d+\]: Method cache corrupted\.
14 CRASHED: SIG(ILL|TRAP)
15 END
16 */
17
18
19 #include "test.h"
20
21 #if !__OBJC2__ || __arm__
22
23 int main()
24 {
25 fprintf(stderr, "objc1\n");
26 succeed(__FILE__);
27 }
28
29 #else
30
31 #include "testroot.i"
32
33 #if __LP64__
34 typedef uint32_t mask_t;
35 #else
36 typedef uint16_t mask_t;
37 #endif
38
39 struct bucket_t {
40 void *sel;
41 void *imp;
42 };
43
44 struct cache_t {
45 struct bucket_t *buckets;
46 mask_t mask;
47 mask_t occupied;
48 };
49
50 struct class_t {
51 void *isa;
52 void *supercls;
53 struct cache_t cache;
54 };
55
56 @interface Subclass : TestRoot @end
57 @implementation Subclass @end
58
59 int main()
60 {
61 Class cls = [TestRoot class];
62 id obj = [cls new];
63 [obj self];
64
65 // Test objc_msgSend.
66 struct cache_t *cache = &((__bridge struct class_t *)cls)->cache;
67 cache->mask = 0;
68 cache->buckets[0].sel = (void*)~0;
69 cache->buckets[0].imp = (void*)~0;
70 cache->buckets[1].sel = (void*)(uintptr_t)1;
71 cache->buckets[1].imp = (void*)cache->buckets;
72
73 fprintf(stderr, "crash now\n");
74 [obj self];
75
76 fail("should have crashed");
77 }
78
79 #endif