]> git.saurik.com Git - apple/objc4.git/blob - test/badCache.m
objc4-680.tar.gz
[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 uintptr_t sel;
41 uintptr_t 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 struct cache_t *cache = &((__bridge struct class_t *)cls)->cache;
66
67 # define COUNT 4
68 struct bucket_t *buckets = calloc(sizeof(struct bucket_t), COUNT+1);
69 for (int i = 0; i < COUNT; i++) {
70 buckets[i].sel = ~0;
71 buckets[i].imp = ~0;
72 }
73 buckets[COUNT].sel = 1;
74 buckets[COUNT].imp = (uintptr_t)buckets;
75
76 cache->mask = COUNT-1;
77 cache->occupied = 0;
78 cache->buckets = buckets;
79
80 fprintf(stderr, "crash now\n");
81 [obj self];
82
83 fail("should have crashed");
84 }
85
86 #endif