]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/CodeGenObjC/id-isa-codegen.m
Vendor import of clang release_34 branch r197841 (effectively, 3.4 RC3):
[FreeBSD/FreeBSD.git] / test / CodeGenObjC / id-isa-codegen.m
1 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-runtime=macosx-fragile-10.5  -emit-llvm -o - %s | FileCheck -check-prefix CHECK-LP64 %s
2 // RUN: %clang_cc1 -triple i386-apple-darwin9 -fobjc-runtime=macosx-fragile-10.5  -emit-llvm -o - %s | FileCheck -check-prefix CHECK-LP32 %s
3
4 typedef struct objc_class *Class;
5
6 typedef struct objc_object {
7     Class isa;
8 } *id;
9
10 @interface I
11 + (Class) class;
12 - (void)meth : (id)object : (id)src_object;
13 + (unsigned char) isSubclassOfClass:(Class)aClass ;
14 @end
15
16 @implementation I
17 + (Class) class {return 0;}
18 + (unsigned char) isSubclassOfClass:(Class)aClass {return 0;}
19 - (void)meth : (id)object  : (id)src_object {
20     [object->isa isSubclassOfClass:[I class]];
21
22     [(*object).isa isSubclassOfClass:[I class]];
23
24     object->isa = src_object->isa;
25     (*src_object).isa = (*object).isa;
26 }
27 @end
28
29
30 // rdar 7470820
31 static Class MyClass;
32
33 Class Test(const void *inObject1) {
34   if(((id)inObject1)->isa == MyClass)
35    return ((id)inObject1)->isa;
36   return (id)0;
37 }
38
39 // rdar 7609722
40 @interface Foo { 
41 @public 
42   id isa; 
43
44 +(id)method;
45 @end
46
47 id Test2() {
48     if([Foo method]->isa)
49       return (*[Foo method]).isa;
50     return [Foo method]->isa;
51 }
52
53 // rdar 7709015
54 @interface Cat   {}
55 @end
56
57 @interface SuperCat : Cat {}
58 +(void)geneticallyAlterCat:(Cat *)cat;
59 @end
60
61 @implementation SuperCat
62 + (void)geneticallyAlterCat:(Cat *)cat {
63     Class dynamicSubclass;
64     ((id)cat)->isa = dynamicSubclass;
65 }
66 @end
67 // CHECK-LP64: %{{.*}} = load i8** %
68 // CHECK-NEXT: %{{.*}} = bitcast i8* %{{.*}} to i8**
69 // CHECK-NEXT: store i8* %{{.*}}, i8** %{{.*}}
70
71 // CHECK-LP32: %{{.*}} = load i8** %
72 // CHECK-NEXT: %{{.*}} = bitcast i8* %{{.*}} to i8**
73 // CHECK-NEXT: store i8* %{{.*}}, i8** %{{.*}}