arphaman created this revision. Repository: rL LLVM
https://reviews.llvm.org/D31179 Files: include/clang/Basic/DiagnosticParseKinds.td include/clang/Sema/Sema.h lib/Parse/ParseObjc.cpp lib/Sema/SemaDeclObjC.cpp test/SemaObjC/attr-deprecated.m test/SemaObjC/category-attribute.m test/SemaObjC/default-synthesize-3.m
Index: test/SemaObjC/default-synthesize-3.m =================================================================== --- test/SemaObjC/default-synthesize-3.m +++ test/SemaObjC/default-synthesize-3.m @@ -33,8 +33,8 @@ - (id) DeepMustSynthProperty { return 0; } @end -__attribute ((objc_requires_property_definitions)) -@interface Deep(CAT) // expected-error {{attributes may not be specified on a category}} +__attribute ((objc_requires_property_definitions)) // expected-error {{'objc_requires_property_definitions' attribute only applies to Objective-C interfaces}} +@interface Deep(CAT) @end __attribute ((objc_requires_property_definitions)) // expected-error {{'objc_requires_property_definitions' attribute only applies to Objective-C interfaces}} Index: test/SemaObjC/category-attribute.m =================================================================== --- /dev/null +++ test/SemaObjC/category-attribute.m @@ -0,0 +1,24 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -ast-dump %s | FileCheck %s +// expected-no-diagnostics + +__attribute__ ((external_source_symbol(language= "Swift", defined_in="A"))) +@interface TestInterface +@end +// CHECK: ObjCInterfaceDecl {{.*}} TestInterface +// CHECK-NEXT: ExternalSourceSymbolAttr + +__attribute__ ((external_source_symbol(language= "Swift", defined_in="B"))) +@interface TestInterface () +@end +// CHECK: ObjCCategoryDecl +// CHECK-NEXT: ObjCInterface +// CHECK-NEXT: ExternalSourceSymbolAttr {{.*}} "Swift" "B" + +__attribute__ ((external_source_symbol(language= "Swift", defined_in="C"))) +@interface TestInterface (Category) +@end +// CHECK: ObjCCategoryDecl +// CHECK-NEXT: ObjCInterface +// CHECK-NEXT: ExternalSourceSymbolAttr {{.*}} "Swift" "C" + Index: test/SemaObjC/attr-deprecated.m =================================================================== --- test/SemaObjC/attr-deprecated.m +++ test/SemaObjC/attr-deprecated.m @@ -121,9 +121,15 @@ } __attribute__((deprecated)) -@interface A(Blah) // expected-error{{attributes may not be specified on a category}} +@interface A(Blah) // no warning +- (A*)getA; @end +@implementation A(Blah) // no warning +- (A*)getA { + return self; +} +@end typedef struct { int x; Index: lib/Sema/SemaDeclObjC.cpp =================================================================== --- lib/Sema/SemaDeclObjC.cpp +++ lib/Sema/SemaDeclObjC.cpp @@ -1724,7 +1724,8 @@ Decl * const *ProtoRefs, unsigned NumProtoRefs, const SourceLocation *ProtoLocs, - SourceLocation EndProtoLoc) { + SourceLocation EndProtoLoc, + AttributeList *AttrList) { ObjCCategoryDecl *CDecl; ObjCInterfaceDecl *IDecl = getObjCInterfaceDecl(ClassName, ClassLoc, true); @@ -1801,6 +1802,9 @@ NumProtoRefs, Context); } + if (AttrList) + ProcessDeclAttributeList(TUScope, CDecl, AttrList); + CheckObjCDeclScope(CDecl); return ActOnObjCContainerStartDefinition(CDecl); } Index: lib/Parse/ParseObjc.cpp =================================================================== --- lib/Parse/ParseObjc.cpp +++ lib/Parse/ParseObjc.cpp @@ -278,11 +278,6 @@ T.consumeClose(); if (T.getCloseLocation().isInvalid()) return nullptr; - - if (!attrs.empty()) { // categories don't support attributes. - Diag(nameLoc, diag::err_objc_no_attributes_on_category); - attrs.clear(); - } // Next, we need to check for any protocol references. assert(LAngleLoc.isInvalid() && "Cannot have already parsed protocols"); @@ -294,16 +289,11 @@ /*consumeLastToken=*/true)) return nullptr; - Decl *CategoryType = - Actions.ActOnStartCategoryInterface(AtLoc, - nameId, nameLoc, - typeParameterList, - categoryId, categoryLoc, - ProtocolRefs.data(), - ProtocolRefs.size(), - ProtocolLocs.data(), - EndProtoLoc); - + Decl *CategoryType = Actions.ActOnStartCategoryInterface( + AtLoc, nameId, nameLoc, typeParameterList, categoryId, categoryLoc, + ProtocolRefs.data(), ProtocolRefs.size(), ProtocolLocs.data(), + EndProtoLoc, attrs.getList()); + if (Tok.is(tok::l_brace)) ParseObjCClassInstanceVariables(CategoryType, tok::objc_private, AtLoc); Index: include/clang/Sema/Sema.h =================================================================== --- include/clang/Sema/Sema.h +++ include/clang/Sema/Sema.h @@ -7666,7 +7666,8 @@ Decl * const *ProtoRefs, unsigned NumProtoRefs, const SourceLocation *ProtoLocs, - SourceLocation EndProtoLoc); + SourceLocation EndProtoLoc, + AttributeList *AttrList); Decl *ActOnStartClassImplementation( SourceLocation AtClassImplLoc, Index: include/clang/Basic/DiagnosticParseKinds.td =================================================================== --- include/clang/Basic/DiagnosticParseKinds.td +++ include/clang/Basic/DiagnosticParseKinds.td @@ -364,8 +364,6 @@ /// Objective-C parser diagnostics def err_expected_minus_or_plus : Error< "method type specifier must start with '-' or '+'">; -def err_objc_no_attributes_on_category : Error< - "attributes may not be specified on a category">; def err_objc_missing_end : Error<"missing '@end'">; def note_objc_container_start : Note< "%select{class|protocol|category|class extension|implementation"
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits