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