Index: cfe/trunk/include/clang/Basic/Attr.td =================================================================== --- cfe/trunk/include/clang/Basic/Attr.td +++ cfe/trunk/include/clang/Basic/Attr.td @@ -1767,7 +1767,7 @@ 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]; } Index: cfe/trunk/include/clang/Basic/AttrDocs.td =================================================================== --- cfe/trunk/include/clang/Basic/AttrDocs.td +++ cfe/trunk/include/clang/Basic/AttrDocs.td @@ -3711,14 +3711,14 @@ 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. }]; } Index: cfe/trunk/lib/CodeGen/CGObjCMac.cpp =================================================================== --- cfe/trunk/lib/CodeGen/CGObjCMac.cpp +++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp @@ -6262,7 +6262,8 @@ bool CGObjCNonFragileABIMac::ImplementationIsNonLazy( const ObjCImplDecl *OD) const { return OD->getClassMethod(GetNullarySelector("load")) != nullptr || - OD->getClassInterface()->hasAttr(); + OD->getClassInterface()->hasAttr() || + OD->hasAttr(); } void CGObjCNonFragileABIMac::GetClassSizeInfo(const ObjCImplementationDecl *OID, Index: cfe/trunk/test/CodeGenObjC/non-lazy-classes.m =================================================================== --- cfe/trunk/test/CodeGenObjC/non-lazy-classes.m +++ cfe/trunk/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 @@ @interface D @end @implementation D @end + +@interface E @end + +__attribute__((objc_nonlazy_class)) +@implementation E @end + +__attribute__((objc_nonlazy_class)) +@implementation E (MyCat) @end Index: cfe/trunk/test/Misc/pragma-attribute-supported-attributes-list.test =================================================================== --- cfe/trunk/test/Misc/pragma-attribute-supported-attributes-list.test +++ cfe/trunk/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) Index: cfe/trunk/test/SemaObjC/attr-objc-non-lazy.m =================================================================== --- cfe/trunk/test/SemaObjC/attr-objc-non-lazy.m +++ cfe/trunk/test/SemaObjC/attr-objc-non-lazy.m @@ -29,7 +29,11 @@ @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