1
1
// RUN: %clang_cc1 -triple x86_64-apple-macosx10.14.0 -emit-llvm %s -o - | FileCheck %s
2
2
3
3
// CHECK: @"OBJC_IVAR_$_StaticLayout.static_layout_ivar" = hidden constant i64 20
4
+ // CHECK: @"OBJC_IVAR_$_StaticLayoutSubClass.static_layout_ivar2" = hidden constant i64 24
5
+ // CHECK: @"OBJC_IVAR_$_MyClass.myIvar" = constant i64 20
6
+ // CHECK: @"OBJC_IVAR_$_MyClass._myProperty" = hidden constant i64 24
7
+ // CHECK: @"OBJC_IVAR_$_AnotherClass.privateId" = constant i64 24
8
+ // CHECK: @"OBJC_IVAR_$_AnotherClass.anotherPrivateId" = hidden constant i64 32
9
+ // CHECK: @"OBJC_IVAR_$_SuperClass.superClassIvar" = constant i64 20
10
+ // CHECK: @"OBJC_IVAR_$_SubClass.subClassIvar" = global i64 24
4
11
// CHECK: @"OBJC_IVAR_$_NotStaticLayout.not_static_layout_ivar" = hidden global i64 12
5
12
6
13
@interface NSObject {
@@ -20,6 +27,82 @@ -(void)meth {
20
27
}
21
28
@end
22
29
30
+ // Scenario 1: Ivars declared in the @interface
31
+ @interface MyClass : NSObject
32
+ {
33
+ int myIvar; // Declare an ivar
34
+ }
35
+
36
+ @property (nonatomic , assign ) int myProperty; // Synthesize a property
37
+
38
+ @end
39
+
40
+ @implementation MyClass
41
+
42
+ - (void )exampleMethod {
43
+ self.myProperty = 42 ; // Access the property
44
+ myIvar = 10 ; // Access the ivar directly
45
+ }
46
+
47
+ @end
48
+
49
+ // Scenario 2: Ivars declared directly in the @implementation
50
+ @interface AnotherClass : NSObject
51
+ {
52
+ id privateId;
53
+ }
54
+
55
+ @end
56
+
57
+ @implementation AnotherClass
58
+ {
59
+ id anotherPrivateId; // Declare an ivar directly in the implementation
60
+ }
61
+
62
+ - (void )doSomething {
63
+ privateId = anotherPrivateId;
64
+ }
65
+
66
+ @end
67
+
68
+ // Scenario 3: Inheritance and Ivars
69
+ @interface SuperClass : NSObject
70
+ {
71
+ int superClassIvar;
72
+ }
73
+ @end
74
+
75
+ @implementation SuperClass
76
+ @end
77
+
78
+ @interface SubClass : SuperClass
79
+ {
80
+ double subClassIvar;
81
+ }
82
+ @end
83
+
84
+ @implementation SubClass
85
+ - (void )exampleMethod {
86
+ // CHECK: load i64, ptr @"OBJC_IVAR_$SuperClass
87
+ superClassIvar = 100 ; // Access superclass ivar
88
+ subClassIvar = 3.14 ; // Access subclass ivar
89
+ }
90
+ @end
91
+
92
+ // Scenario 4: Custom Getter/Setter Methods
93
+ @interface CustomPropertyClass : NSObject
94
+ @property (nonatomic , strong , getter =myCustomGetter, setter =myCustomSetter:) id customProperty;
95
+ @end
96
+
97
+ @implementation CustomPropertyClass
98
+ - (id ) myCustomGetter {
99
+ return 0 ;
100
+ }
101
+
102
+ - (void )myCustomSetter : (id )newValue {
103
+ }
104
+ @end
105
+
23
106
@interface NotNSObject {
24
107
int these, might, change;
25
108
}
0 commit comments