[objc_direct] do not add direct properties to the serialization array
authorPierre Habouzit <phabouzit@apple.com>
Wed, 22 Jan 2020 20:08:19 +0000 (12:08 -0800)
committerPierre Habouzit <phabouzit@apple.com>
Fri, 24 Jan 2020 06:39:47 +0000 (22:39 -0800)
If we do, then the property_list_t length is wrong
and class_getProperty gets very sad.

Signed-off-by: Pierre Habouzit <phabouzit@apple.com>
Radar-Id: rdar://problem/58804805
Differential Revision: https://reviews.llvm.org/D73219

clang/lib/CodeGen/CGObjCMac.cpp
clang/test/CodeGenObjC/direct-properties.m [new file with mode: 0644]

index f36c28a..b36d973 100644 (file)
@@ -3291,6 +3291,8 @@ llvm::Constant *CGObjCCommonMac::EmitPropertyList(Twine Name,
       for (auto *PD : ClassExt->properties()) {
         if (IsClassProperty != PD->isClassProperty())
           continue;
+        if (PD->isDirectProperty())
+          continue;
         PropertySet.insert(PD->getIdentifier());
         Properties.push_back(PD);
       }
@@ -3302,6 +3304,8 @@ llvm::Constant *CGObjCCommonMac::EmitPropertyList(Twine Name,
     // class extension.
     if (!PropertySet.insert(PD->getIdentifier()).second)
       continue;
+    if (PD->isDirectProperty())
+      continue;
     Properties.push_back(PD);
   }
 
@@ -3327,8 +3331,6 @@ llvm::Constant *CGObjCCommonMac::EmitPropertyList(Twine Name,
   values.addInt(ObjCTypes.IntTy, Properties.size());
   auto propertiesArray = values.beginArray(ObjCTypes.PropertyTy);
   for (auto PD : Properties) {
-    if (PD->isDirectProperty())
-      continue;
     auto property = propertiesArray.beginStruct(ObjCTypes.PropertyTy);
     property.add(GetPropertyName(PD->getIdentifier()));
     property.add(GetPropertyTypeString(PD, Container));
diff --git a/clang/test/CodeGenObjC/direct-properties.m b/clang/test/CodeGenObjC/direct-properties.m
new file mode 100644 (file)
index 0000000..113ac12
--- /dev/null
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -emit-llvm -fobjc-arc -triple x86_64-apple-darwin10 %s -o - | FileCheck %s
+
+__attribute__((objc_root_class))
+@interface A
+@property(direct, readonly) int i;
+@end
+
+__attribute__((objc_root_class))
+@interface B
+@property(direct, readonly) int i;
+@property(readonly) int j;
+@end
+
+// CHECK-NOT: @"__OBJC_$_PROP_LIST_A"
+@implementation A
+@synthesize i = _i;
+@end
+
+// CHECK: @"_OBJC_$_PROP_LIST_B" = internal global { i32, i32, [1 x %struct._prop_t] } { i32 16, i32 1
+@implementation B
+@synthesize i = _i;
+@synthesize j = _j;
+@end