From eb4f2c56c298071d58b441ccf801b039be93788a Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Tue, 3 Jan 2012 19:46:00 +0000 Subject: [PATCH] objc: use objc_suppress_autosynthesis attribute on classes which should not be default synthesized. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@147468 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDeclObjC.cpp | 7 +++--- lib/Sema/SemaObjCProperty.cpp | 6 +++-- test/SemaObjC/default-synthesize-3.m | 33 ++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 test/SemaObjC/default-synthesize-3.m diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index bc35055722..ad230b4713 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -1665,9 +1665,10 @@ void Sema::ImplMethodsVsClassMethods(Scope *S, ObjCImplDecl* IMPDecl, // Check and see if properties declared in the interface have either 1) // an implementation or 2) there is a @synthesize/@dynamic implementation // of the property in the @implementation. - if (isa(CDecl) && - !(LangOpts.ObjCDefaultSynthProperties && LangOpts.ObjCNonFragileABI2)) - DiagnoseUnimplementedProperties(S, IMPDecl, CDecl, InsMap); + if (const ObjCInterfaceDecl *IDecl = dyn_cast(CDecl)) + if (!(LangOpts.ObjCDefaultSynthProperties && LangOpts.ObjCNonFragileABI2) || + IDecl->isObjCSuppressAutosynthesis()) + DiagnoseUnimplementedProperties(S, IMPDecl, CDecl, InsMap); llvm::DenseSet ClsMap; for (ObjCImplementationDecl::classmeth_iterator diff --git a/lib/Sema/SemaObjCProperty.cpp b/lib/Sema/SemaObjCProperty.cpp index c60d1b8f5e..a15fc7dd8d 100644 --- a/lib/Sema/SemaObjCProperty.cpp +++ b/lib/Sema/SemaObjCProperty.cpp @@ -856,7 +856,8 @@ Decl *Sema::ActOnPropertyImplDecl(Scope *S, } IC->addPropertyImplementation(PIDecl); if (getLangOptions().ObjCDefaultSynthProperties && - getLangOptions().ObjCNonFragileABI2) { + getLangOptions().ObjCNonFragileABI2 && + !IDecl->isObjCSuppressAutosynthesis()) { // Diagnose if an ivar was lazily synthesdized due to a previous // use and if 1) property is @dynamic or 2) property is synthesized // but it requires an ivar of different name. @@ -1355,7 +1356,8 @@ void Sema::DefaultSynthesizeProperties(Scope *S, Decl *D) { if (!IC) return; if (ObjCInterfaceDecl* IDecl = IC->getClassInterface()) - DefaultSynthesizeProperties(S, IC, IDecl); + if (!IDecl->isObjCSuppressAutosynthesis()) + DefaultSynthesizeProperties(S, IC, IDecl); } void Sema::DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl* IMPDecl, diff --git a/test/SemaObjC/default-synthesize-3.m b/test/SemaObjC/default-synthesize-3.m new file mode 100644 index 0000000000..7b07cb9aa1 --- /dev/null +++ b/test/SemaObjC/default-synthesize-3.m @@ -0,0 +1,33 @@ +// RUN: %clang_cc1 -x objective-c -fsyntax-only -fobjc-default-synthesize-properties -verify %s +// RUN: %clang_cc1 -x objective-c++ -fsyntax-only -fobjc-default-synthesize-properties -verify %s + +__attribute ((objc_suppress_autosynthesis)) +@interface NoAuto +@property int NoAutoProp; // expected-note 2 {{property declared here}} +@end + +@implementation NoAuto // expected-warning {{property 'NoAutoProp' requires method 'NoAutoProp' to be defined}} \ + // expected-warning {{property 'NoAutoProp' requires method 'setNoAutoProp:'}} +@end + +__attribute ((objc_suppress_autosynthesis)) // redundant, just for testing +@interface Sub : NoAuto +@property (copy) id SubProperty; // expected-note 2 {{property declared here}} +@end + +@implementation Sub // expected-warning {{property 'SubProperty' requires method 'SubProperty' to be defined}} \ + // expected-warning {{property 'SubProperty' requires method 'setSubProperty:' to be defined}} +@end + +@interface Deep : Sub +@property (copy) id DeepProperty; +@property (copy) id DeepSynthProperty; +@property (copy) id DeepMustSynthProperty; // expected-note {{property declared here}} +@end + +@implementation Deep // expected-warning {{property 'DeepMustSynthProperty' requires method 'setDeepMustSynthProperty:' to be defined}} +@dynamic DeepProperty; +@synthesize DeepSynthProperty; +- (id) DeepMustSynthProperty { return 0; } +@end +