summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErik Pilkington <erik.pilkington@gmail.com>2019-04-11 17:55:34 +0000
committerErik Pilkington <erik.pilkington@gmail.com>2019-04-11 17:55:34 +0000
commit765bbb23ecd4d62a84e932c8f23f867fcd3c1850 (patch)
tree93dcac144e822dcaced8077cd9cde1dcdb961e59
parenta12e071469fbd8ab16d06f7c99543cfec92284ee (diff)
Support objc_nonlazy_class attribute on Objective-C implementations
Fixes rdar://49523079 Differential revision: https://reviews.llvm.org/D60544 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@358201 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Basic/Attr.td2
-rw-r--r--include/clang/Basic/AttrDocs.td16
-rw-r--r--lib/CodeGen/CGObjCMac.cpp3
-rw-r--r--test/CodeGenObjC/non-lazy-classes.m16
-rw-r--r--test/Misc/pragma-attribute-supported-attributes-list.test2
-rw-r--r--test/SemaObjC/attr-objc-non-lazy.m6
6 files changed, 29 insertions, 16 deletions
diff --git a/include/clang/Basic/Attr.td b/include/clang/Basic/Attr.td
index c9086ee22b..67011ebdf8 100644
--- a/include/clang/Basic/Attr.td
+++ b/include/clang/Basic/Attr.td
@@ -1767,7 +1767,7 @@ def ObjCRootClass : InheritableAttr {
def ObjCNonLazyClass : Attr {
let Spellings = [Clang<"objc_nonlazy_class">];
- let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
+ let Subjects = SubjectList<[ObjCInterface, ObjCImpl], ErrorDiag>;
let LangOpts = [ObjC];
let Documentation = [ObjCNonLazyClassDocs];
}
diff --git a/include/clang/Basic/AttrDocs.td b/include/clang/Basic/AttrDocs.td
index b1ca3e5c22..9990be3364 100644
--- a/include/clang/Basic/AttrDocs.td
+++ b/include/clang/Basic/AttrDocs.td
@@ -3711,14 +3711,14 @@ ensure that this class cannot be subclassed.
def ObjCNonLazyClassDocs : Documentation {
let Category = DocCatDecl;
let Content = [{
-This attribute can be added to an Objective-C ``@interface`` declaration to
-add the class to the list of non-lazily initialized classes. A non-lazy class
-will be initialized eagerly when the Objective-C runtime is loaded. This is
-required for certain system classes which have instances allocated in
-non-standard ways, such as the classes for blocks and constant strings. Adding
-this attribute is essentially equivalent to providing a trivial `+load` method
-but avoids the (fairly small) load-time overheads associated with defining and
-calling such a method.
+This attribute can be added to an Objective-C ``@interface`` or
+``@implementation`` declaration to add the class to the list of non-lazily
+initialized classes. A non-lazy class will be initialized eagerly when the
+Objective-C runtime is loaded. This is required for certain system classes which
+have instances allocated in non-standard ways, such as the classes for blocks
+and constant strings. Adding this attribute is essentially equivalent to
+providing a trivial `+load` method but avoids the (fairly small) load-time
+overheads associated with defining and calling such a method.
}];
}
diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp
index 7d760bde99..ad141d6191 100644
--- a/lib/CodeGen/CGObjCMac.cpp
+++ b/lib/CodeGen/CGObjCMac.cpp
@@ -6262,7 +6262,8 @@ CGObjCNonFragileABIMac::BuildClassObject(const ObjCInterfaceDecl *CI,
bool CGObjCNonFragileABIMac::ImplementationIsNonLazy(
const ObjCImplDecl *OD) const {
return OD->getClassMethod(GetNullarySelector("load")) != nullptr ||
- OD->getClassInterface()->hasAttr<ObjCNonLazyClassAttr>();
+ OD->getClassInterface()->hasAttr<ObjCNonLazyClassAttr>() ||
+ OD->hasAttr<ObjCNonLazyClassAttr>();
}
void CGObjCNonFragileABIMac::GetClassSizeInfo(const ObjCImplementationDecl *OID,
diff --git a/test/CodeGenObjC/non-lazy-classes.m b/test/CodeGenObjC/non-lazy-classes.m
index aeb2a0dd9c..dbfc54d408 100644
--- a/test/CodeGenObjC/non-lazy-classes.m
+++ b/test/CodeGenObjC/non-lazy-classes.m
@@ -1,7 +1,7 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -Wno-objc-root-class -emit-llvm -o - %s | \
-// RUN: FileCheck %s
-// CHECK: @"OBJC_LABEL_NONLAZY_CLASS_$" = private global [2 x {{.*}}]{{.*}}@"OBJC_CLASS_$_A"{{.*}},{{.*}}@"OBJC_CLASS_$_D"{{.*}} section "__DATA,__objc_nlclslist,regular,no_dead_strip", align 8
-// CHECK: @"OBJC_LABEL_NONLAZY_CATEGORY_$" = private global [1 x {{.*}}] {{.*}}@"\01l_OBJC_$_CATEGORY_A_$_Cat"{{.*}}, section "__DATA,__objc_nlcatlist,regular,no_dead_strip", align 8
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -Wno-objc-root-class -emit-llvm -o - %s | FileCheck %s
+
+// CHECK: @"OBJC_LABEL_NONLAZY_CLASS_$" = private global [3 x {{.*}}]{{.*}}@"OBJC_CLASS_$_A"{{.*}},{{.*}}@"OBJC_CLASS_$_D"{{.*}},{{.*}}"OBJC_CLASS_$_E"{{.*}} section "__DATA,__objc_nlclslist,regular,no_dead_strip", align 8
+// CHECK: @"OBJC_LABEL_NONLAZY_CATEGORY_$" = private global [2 x {{.*}}] {{.*}}@"\01l_OBJC_$_CATEGORY_A_$_Cat"{{.*}},{{.*}}@"\01l_OBJC_$_CATEGORY_E_$_MyCat"{{.*}}, section "__DATA,__objc_nlcatlist,regular,no_dead_strip", align 8
@interface A @end
@implementation A
@@ -35,3 +35,11 @@ __attribute__((objc_nonlazy_class))
@interface D @end
@implementation D @end
+
+@interface E @end
+
+__attribute__((objc_nonlazy_class))
+@implementation E @end
+
+__attribute__((objc_nonlazy_class))
+@implementation E (MyCat) @end
diff --git a/test/Misc/pragma-attribute-supported-attributes-list.test b/test/Misc/pragma-attribute-supported-attributes-list.test
index d083f10acc..f138deac57 100644
--- a/test/Misc/pragma-attribute-supported-attributes-list.test
+++ b/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -102,7 +102,7 @@
// CHECK-NEXT: ObjCExplicitProtocolImpl (SubjectMatchRule_objc_protocol)
// CHECK-NEXT: ObjCExternallyRetained (SubjectMatchRule_variable_not_is_parameter, SubjectMatchRule_function, SubjectMatchRule_block, SubjectMatchRule_objc_method)
// CHECK-NEXT: ObjCMethodFamily (SubjectMatchRule_objc_method)
-// CHECK-NEXT: ObjCNonLazyClass (SubjectMatchRule_objc_interface)
+// CHECK-NEXT: ObjCNonLazyClass (SubjectMatchRule_objc_interface, SubjectMatchRule_objc_implementation)
// CHECK-NEXT: ObjCPreciseLifetime (SubjectMatchRule_variable)
// CHECK-NEXT: ObjCRequiresPropertyDefs (SubjectMatchRule_objc_interface)
// CHECK-NEXT: ObjCRequiresSuper (SubjectMatchRule_objc_method)
diff --git a/test/SemaObjC/attr-objc-non-lazy.m b/test/SemaObjC/attr-objc-non-lazy.m
index e5de24e422..bbbbd74145 100644
--- a/test/SemaObjC/attr-objc-non-lazy.m
+++ b/test/SemaObjC/attr-objc-non-lazy.m
@@ -29,7 +29,11 @@ void foo();
@interface E
@end
-// expected-error@+1 {{'objc_nonlazy_class' attribute only applies to Objective-C interfaces}}
+
__attribute__((objc_nonlazy_class))
@implementation E
@end
+
+__attribute__((objc_nonlazy_class))
+@implementation E (MyCat)
+@end