r254622 - Fix Objective-C metadata for properties from class extensions after r251874
Nico Weber via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 3 09:44:52 PST 2015
Author: nico
Date: Thu Dec 3 11:44:51 2015
New Revision: 254622
URL: http://llvm.org/viewvc/llvm-project?rev=254622&view=rev
Log:
Fix Objective-C metadata for properties from class extensions after r251874
After, properties from class extensions no longer show up in
ObjCInterfaceDecl::properties(). Make ObjCCommonMac::EmitPropertyList()
explicitly look for properties in class extensions before looking at
direct properties.
Also add a test that passes both with clang before r251874 and after this
patch (but fails with r251874 and without this patch).
Added:
cfe/trunk/test/CodeGenObjC/property-list-in-extension.m
Modified:
cfe/trunk/lib/CodeGen/CGObjCMac.cpp
Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=254622&r1=254621&r2=254622&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Thu Dec 3 11:44:51 2015
@@ -2908,15 +2908,26 @@ llvm::Constant *CGObjCCommonMac::EmitPro
const ObjCCommonTypesHelper &ObjCTypes) {
SmallVector<llvm::Constant *, 16> Properties;
llvm::SmallPtrSet<const IdentifierInfo*, 16> PropertySet;
+
+ auto AddProperty = [&](const ObjCPropertyDecl *PD) {
+ llvm::Constant *Prop[] = {GetPropertyName(PD->getIdentifier()),
+ GetPropertyTypeString(PD, Container)};
+ Properties.push_back(llvm::ConstantStruct::get(ObjCTypes.PropertyTy, Prop));
+ };
+ if (const ObjCInterfaceDecl *OID = dyn_cast<ObjCInterfaceDecl>(OCD))
+ for (const ObjCCategoryDecl *ClassExt : OID->known_extensions())
+ for (auto *PD : ClassExt->properties()) {
+ PropertySet.insert(PD->getIdentifier());
+ AddProperty(PD);
+ }
for (const auto *PD : OCD->properties()) {
- PropertySet.insert(PD->getIdentifier());
- llvm::Constant *Prop[] = {
- GetPropertyName(PD->getIdentifier()),
- GetPropertyTypeString(PD, Container)
- };
- Properties.push_back(llvm::ConstantStruct::get(ObjCTypes.PropertyTy,
- Prop));
+ // Don't emit duplicate metadata for properties that were already in a
+ // class extension.
+ if (!PropertySet.insert(PD->getIdentifier()).second)
+ continue;
+ AddProperty(PD);
}
+
if (const ObjCInterfaceDecl *OID = dyn_cast<ObjCInterfaceDecl>(OCD)) {
for (const auto *P : OID->all_referenced_protocols())
PushProtocolProperties(PropertySet, Properties, Container, P, ObjCTypes);
Added: cfe/trunk/test/CodeGenObjC/property-list-in-extension.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/property-list-in-extension.m?rev=254622&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenObjC/property-list-in-extension.m (added)
+++ cfe/trunk/test/CodeGenObjC/property-list-in-extension.m Thu Dec 3 11:44:51 2015
@@ -0,0 +1,39 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm %s -o - | FileCheck %s
+
+// Checks metadata for properties in a few cases.
+
+
+// Property from a class extension:
+ at interface Foo
+ at end
+
+ at interface Foo()
+ at property int myprop;
+ at end
+
+ at implementation Foo
+ at synthesize myprop = _myprop;
+ at end
+// Metadata for _myprop should be present, and PROP_LIST for Foo should have
+// only one entry.
+// CHECK: = private global [12 x i8] c"Ti,V_myprop\00",
+// CHECK: @"\01l_OBJC_$_PROP_LIST_Foo" = private global { i32, i32, [1 x %struct._prop_t] }
+
+// Readonly property in interface made readwrite in a category:
+ at interface FooRO
+ at property (readonly) int evolvingprop;
+ at end
+
+ at interface FooRO ()
+ at property int evolvingprop;
+ at end
+
+ at implementation FooRO
+ at synthesize evolvingprop = _evolvingprop;
+ at end
+// Metadata for _evolvingprop should be present, and PROP_LIST for FooRO should
+// still have only one entry, and the one entry should point to the version of
+// the property with a getter and setter.
+// CHECK: [[getter:@OBJC_PROP_NAME_ATTR[^ ]+]] = private global [13 x i8] c"evolvingprop\00"
+// CHECK: [[setter:@OBJC_PROP_NAME_ATTR[^ ]+]] = private global [18 x i8] c"Ti,V_evolvingprop\00",
+// CHECK: @"\01l_OBJC_$_PROP_LIST_FooRO" = private global { i32, i32, [1 x %struct._prop_t] }{{.*}}[[getter]]{{.*}}[[setter]]
More information about the cfe-commits
mailing list