Skip to content

Commit 4bdf6f7

Browse files
committed
[ObjC] Add pre-commit tests [NFC]
1 parent b17348c commit 4bdf6f7

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

clang/test/CodeGenObjC/constant-non-fragile-ivar-offset.m

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
// RUN: %clang_cc1 -triple x86_64-apple-macosx10.14.0 -emit-llvm %s -o - | FileCheck %s
22

33
// 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
411
// CHECK: @"OBJC_IVAR_$_NotStaticLayout.not_static_layout_ivar" = hidden global i64 12
512

613
@interface NSObject {
@@ -20,6 +27,82 @@ -(void)meth {
2027
}
2128
@end
2229

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+
23106
@interface NotNSObject {
24107
int these, might, change;
25108
}

0 commit comments

Comments
 (0)