Skip to content

Commit 3844dfd

Browse files
authored
Merge pull request #21435 from zneak/objc-static-ivars
[IRGen] Do not write out ObjC property ivar field for static properties
2 parents 8eac45e + 7fbb40b commit 3844dfd

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

lib/IRGen/GenClass.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1908,8 +1908,9 @@ namespace {
19081908
else
19091909
(void)0;
19101910

1911-
// If the property has storage, emit the ivar name last.
1912-
if (prop->hasStorage())
1911+
// If the property is an instance property and has storage, emit the ivar
1912+
// name last.
1913+
if (!prop->isStatic() && prop->hasStorage())
19131914
outs << ",V" << prop->getName();
19141915
}
19151916

test/IRGen/objc_properties.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ extension SomeObject {
4747
@objc class var extensionClassProp : SomeObject.Type {
4848
return self
4949
}
50+
51+
@objc static var extensionStoredStaticProp: Int64 = 0
5052
}
5153

5254
// <rdar://problem/16952186> Crash with @lazy in @objc class
@@ -77,14 +79,14 @@ class Class17127126 {
7779
}
7880

7981
// CHECK-NEW: [[SHARED_NAME:@.*]] = private unnamed_addr constant [11 x i8] c"sharedProp\00"
80-
// CHECK-NEW: [[SHARED_ATTRS:@.*]] = private unnamed_addr constant [17 x i8] c"Tq,N,VsharedProp\00"
82+
// CHECK-NEW: [[SHARED_ATTRS:@.*]] = private unnamed_addr constant [5 x i8] c"Tq,N\00"
8183

8284
// CHECK-NEW: @_CLASS_PROPERTIES__TtC15objc_properties10SomeObject = private constant { {{.*}}] } {
8385
// CHECK-NEW: i32 16,
8486
// CHECK-NEW: i32 1,
8587
// CHECK-NEW: [1 x { i8*, i8* }] [{
8688
// CHECK-NEW: i8* getelementptr inbounds ([11 x i8], [11 x i8]* [[SHARED_NAME]], i64 0, i64 0),
87-
// CHECK-NEW: i8* getelementptr inbounds ([17 x i8], [17 x i8]* [[SHARED_ATTRS]], i64 0, i64 0)
89+
// CHECK-NEW: i8* getelementptr inbounds ([5 x i8], [5 x i8]* [[SHARED_ATTRS]], i64 0, i64 0)
8890
// CHECK-NEW: }]
8991
// CHECK-NEW: }, section "__DATA, __objc_const", align 8
9092

@@ -209,14 +211,17 @@ class Class17127126 {
209211

210212
// CHECK-NEW: [[EXTENSIONCLASSPROPERTY_NAME:@.*]] = private unnamed_addr constant [19 x i8] c"extensionClassProp\00"
211213
// CHECK-NEW: [[EXTENSIONCLASSPROPERTY_ATTRS:@.*]] = private unnamed_addr constant [7 x i8] c"T#,N,R\00"
214+
// CHECK-NEW: [[EXTENSIONSTATICPROPERTY_NAME:@.*]] = private unnamed_addr constant [26 x i8] c"extensionStoredStaticProp\00"
212215

213216
// CHECK-NEW: @"_CATEGORY_CLASS_PROPERTIES__TtC15objc_properties10SomeObject_$_objc_properties" = private constant { {{.*}}] } {
214217
// CHECK-NEW: i32 16,
215-
// CHECK-NEW: i32 1,
216-
// CHECK-NEW: [1 x { i8*, i8* }] [{
218+
// CHECK-NEW: i32 2,
219+
// CHECK-NEW: [2 x { i8*, i8* }] [{
217220
// CHECK-NEW: i8* getelementptr inbounds ([19 x i8], [19 x i8]* [[EXTENSIONCLASSPROPERTY_NAME]], i64 0, i64 0),
218221
// CHECK-NEW: i8* getelementptr inbounds ([7 x i8], [7 x i8]* [[EXTENSIONCLASSPROPERTY_ATTRS]], i64 0, i64 0)
219-
// CHECK-NEW: }]
222+
// CHECK-NEW: }, {
223+
// CHECK-NEW: i8* getelementptr inbounds ([26 x i8], [26 x i8]* [[EXTENSIONSTATICPROPERTY_NAME]], i64 0, i64 0),
224+
// CHECK-NEW: i8* getelementptr inbounds ([5 x i8], [5 x i8]* [[SHARED_ATTRS]], i64 0, i64 0) }]
220225
// CHECK-NEW: }, section "__DATA, __objc_const", align 8
221226

222227
// CHECK: @"_CATEGORY__TtC15objc_properties10SomeObject_$_objc_properties" = private constant { {{.+}} } {

0 commit comments

Comments
 (0)