xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenObjC/ivar-invariant.m (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc// RUN: %clang_cc1 -triple x86_64-apple-darwin -fblocks -emit-llvm -o - %s | FileCheck %s
2*f4a2713aSLionel Sambuc
3*f4a2713aSLionel Sambuc@interface NSObject
4*f4a2713aSLionel Sambuc+ (id) new;
5*f4a2713aSLionel Sambuc- (id) init;
6*f4a2713aSLionel Sambuc@end
7*f4a2713aSLionel Sambuc
8*f4a2713aSLionel Sambuc@interface Base : NSObject @end
9*f4a2713aSLionel Sambuc
10*f4a2713aSLionel Sambuc// @implementation Base
11*f4a2713aSLionel Sambuc// {
12*f4a2713aSLionel Sambuc//     int dummy;
13*f4a2713aSLionel Sambuc// }
14*f4a2713aSLionel Sambuc// @end
15*f4a2713aSLionel Sambuc
16*f4a2713aSLionel Sambuc@interface Derived : Base
17*f4a2713aSLionel Sambuc{
18*f4a2713aSLionel Sambuc    @public int member;
19*f4a2713aSLionel Sambuc}
20*f4a2713aSLionel Sambuc@end
21*f4a2713aSLionel Sambuc
22*f4a2713aSLionel Sambuc@implementation Derived
23*f4a2713aSLionel Sambuc- (id) init
24*f4a2713aSLionel Sambuc{
25*f4a2713aSLionel Sambuc    self = [super init];
26*f4a2713aSLionel Sambuc    member = 42;
27*f4a2713aSLionel Sambuc    return self;
28*f4a2713aSLionel Sambuc}
29*f4a2713aSLionel Sambuc@end
30*f4a2713aSLionel Sambuc
31*f4a2713aSLionel Sambuc// CHECK: define internal i8* @"\01-[Derived init]"
32*f4a2713aSLionel Sambuc// CHECK: [[IVAR:%.*]] = load i64* @"OBJC_IVAR_$_Derived.member", !invariant.load
33*f4a2713aSLionel Sambuc
34*f4a2713aSLionel Sambucvoid * variant_load_1(int i) {
35*f4a2713aSLionel Sambuc    void *ptr;
36*f4a2713aSLionel Sambuc    while (i--) {
37*f4a2713aSLionel Sambuc        Derived *d = [Derived new];
38*f4a2713aSLionel Sambuc        ptr = &d->member;
39*f4a2713aSLionel Sambuc    }
40*f4a2713aSLionel Sambuc    return ptr;
41*f4a2713aSLionel Sambuc}
42*f4a2713aSLionel Sambuc
43*f4a2713aSLionel Sambuc// CHECK-LABEL: define i8* @variant_load_1(i32 %i)
44*f4a2713aSLionel Sambuc// CHECK: [[IVAR:%.*]] = load i64* @"OBJC_IVAR_$_Derived.member"{{$}}
45*f4a2713aSLionel Sambuc
46*f4a2713aSLionel Sambuc@interface Container : Derived @end
47*f4a2713aSLionel Sambuc@implementation Container
48*f4a2713aSLionel Sambuc- (void *) invariant_load_1
49*f4a2713aSLionel Sambuc{
50*f4a2713aSLionel Sambuc    return &self->member;
51*f4a2713aSLionel Sambuc}
52*f4a2713aSLionel Sambuc@end
53*f4a2713aSLionel Sambuc
54*f4a2713aSLionel Sambuc// CHECK: define internal i8* @"\01-[Container invariant_load_1]"
55*f4a2713aSLionel Sambuc// CHECK: [[IVAR:%.*]] = load i64* @"OBJC_IVAR_$_Derived.member", !invariant.load
56*f4a2713aSLionel Sambuc
57*f4a2713aSLionel Sambuc@interface ForBlock
58*f4a2713aSLionel Sambuc{
59*f4a2713aSLionel Sambuc@public
60*f4a2713aSLionel Sambuc  id foo;
61*f4a2713aSLionel Sambuc}
62*f4a2713aSLionel Sambuc@end
63*f4a2713aSLionel Sambuc
64*f4a2713aSLionel Sambuc// CHECK-LABEL: define internal i8* @block_block_invoke
65*f4a2713aSLionel Sambuc// CHECK: load i64* @"OBJC_IVAR_$_ForBlock.foo"
66*f4a2713aSLionel Sambucid (^block)(ForBlock*) = ^(ForBlock* a) {
67*f4a2713aSLionel Sambuc  return a->foo;
68*f4a2713aSLionel Sambuc};
69