Author: arphaman Date: Mon Jul 3 03:12:24 2017 New Revision: 307014 URL: http://llvm.org/viewvc/llvm-project?rev=307014&view=rev Log: Add a fixit for -Wobjc-protocol-property-synthesis
rdar://32132756 Differential Revision: https://reviews.llvm.org/D34886 Added: cfe/trunk/test/FixIt/fixit-add-synthesize-to-property.m Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/include/clang/Sema/Sema.h cfe/trunk/lib/Parse/ParseObjc.cpp cfe/trunk/lib/Sema/SemaObjCProperty.cpp cfe/trunk/test/SemaObjC/default-synthesize-3.m cfe/trunk/test/SemaObjC/default-synthesize.m cfe/trunk/test/SemaObjC/forward-protocol-incomplete-impl-warn.m Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=307014&r1=307013&r2=307014&view=diff ============================================================================== --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Jul 3 03:12:24 2017 @@ -1029,6 +1029,8 @@ def warn_auto_synthesizing_protocol_prop "auto property synthesis will not synthesize property %0" " declared in protocol %1">, InGroup<DiagGroup<"objc-protocol-property-synthesis">>; +def note_add_synthesize_directive : Note< + "add a '@synthesize' directive">; def warn_no_autosynthesis_shared_ivar_property : Warning < "auto property synthesis will not synthesize property " "%0 because it cannot share an ivar with another synthesized property">, Modified: cfe/trunk/include/clang/Sema/Sema.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=307014&r1=307013&r2=307014&view=diff ============================================================================== --- cfe/trunk/include/clang/Sema/Sema.h (original) +++ cfe/trunk/include/clang/Sema/Sema.h Mon Jul 3 03:12:24 2017 @@ -3358,9 +3358,10 @@ public: /// DefaultSynthesizeProperties - This routine default synthesizes all /// properties which must be synthesized in the class's \@implementation. - void DefaultSynthesizeProperties (Scope *S, ObjCImplDecl* IMPDecl, - ObjCInterfaceDecl *IDecl); - void DefaultSynthesizeProperties(Scope *S, Decl *D); + void DefaultSynthesizeProperties(Scope *S, ObjCImplDecl *IMPDecl, + ObjCInterfaceDecl *IDecl, + SourceLocation AtEnd); + void DefaultSynthesizeProperties(Scope *S, Decl *D, SourceLocation AtEnd); /// IvarBacksCurrentMethodAccessor - This routine returns 'true' if 'IV' is /// an ivar synthesized for 'Method' and 'Method' is a property accessor Modified: cfe/trunk/lib/Parse/ParseObjc.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=307014&r1=307013&r2=307014&view=diff ============================================================================== --- cfe/trunk/lib/Parse/ParseObjc.cpp (original) +++ cfe/trunk/lib/Parse/ParseObjc.cpp Mon Jul 3 03:12:24 2017 @@ -2255,7 +2255,7 @@ Parser::ObjCImplParsingDataRAII::~ObjCIm void Parser::ObjCImplParsingDataRAII::finish(SourceRange AtEnd) { assert(!Finished); - P.Actions.DefaultSynthesizeProperties(P.getCurScope(), Dcl); + P.Actions.DefaultSynthesizeProperties(P.getCurScope(), Dcl, AtEnd.getBegin()); for (size_t i = 0; i < LateParsedObjCMethods.size(); ++i) P.ParseLexedObjCMethodDefs(*LateParsedObjCMethods[i], true/*Methods*/); Modified: cfe/trunk/lib/Sema/SemaObjCProperty.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaObjCProperty.cpp?rev=307014&r1=307013&r2=307014&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaObjCProperty.cpp (original) +++ cfe/trunk/lib/Sema/SemaObjCProperty.cpp Mon Jul 3 03:12:24 2017 @@ -1676,8 +1676,9 @@ static bool SuperClassImplementsProperty /// \brief Default synthesizes all properties which must be synthesized /// in class's \@implementation. -void Sema::DefaultSynthesizeProperties(Scope *S, ObjCImplDecl* IMPDecl, - ObjCInterfaceDecl *IDecl) { +void Sema::DefaultSynthesizeProperties(Scope *S, ObjCImplDecl *IMPDecl, + ObjCInterfaceDecl *IDecl, + SourceLocation AtEnd) { ObjCInterfaceDecl::PropertyMap PropMap; ObjCInterfaceDecl::PropertyDeclOrder PropertyOrder; IDecl->collectPropertiesToImplement(PropMap, PropertyOrder); @@ -1725,6 +1726,10 @@ void Sema::DefaultSynthesizeProperties(S diag::warn_auto_synthesizing_protocol_property) << Prop << Proto; Diag(Prop->getLocation(), diag::note_property_declare); + std::string FixIt = + (Twine("@synthesize ") + Prop->getName() + ";\n\n").str(); + Diag(AtEnd, diag::note_add_synthesize_directive) + << FixItHint::CreateInsertion(AtEnd, FixIt); } continue; } @@ -1764,7 +1769,8 @@ void Sema::DefaultSynthesizeProperties(S } } -void Sema::DefaultSynthesizeProperties(Scope *S, Decl *D) { +void Sema::DefaultSynthesizeProperties(Scope *S, Decl *D, + SourceLocation AtEnd) { if (!LangOpts.ObjCDefaultSynthProperties || LangOpts.ObjCRuntime.isFragile()) return; ObjCImplementationDecl *IC=dyn_cast_or_null<ObjCImplementationDecl>(D); @@ -1772,7 +1778,7 @@ void Sema::DefaultSynthesizeProperties(S return; if (ObjCInterfaceDecl* IDecl = IC->getClassInterface()) if (!IDecl->isObjCRequiresPropertyDefs()) - DefaultSynthesizeProperties(S, IC, IDecl); + DefaultSynthesizeProperties(S, IC, IDecl, AtEnd); } static void DiagnoseUnimplementedAccessor( Added: cfe/trunk/test/FixIt/fixit-add-synthesize-to-property.m URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/fixit-add-synthesize-to-property.m?rev=307014&view=auto ============================================================================== --- cfe/trunk/test/FixIt/fixit-add-synthesize-to-property.m (added) +++ cfe/trunk/test/FixIt/fixit-add-synthesize-to-property.m Mon Jul 3 03:12:24 2017 @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s + +@protocol P1 + +@property int prop; + +@end + +@interface I <P1> + +@end + +@implementation I +@end // CHECK: fix-it:{{.*}}:{[[@LINE]]:1-[[@LINE]]:1}:"@synthesize prop;\n\n" Modified: cfe/trunk/test/SemaObjC/default-synthesize-3.m URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/default-synthesize-3.m?rev=307014&r1=307013&r2=307014&view=diff ============================================================================== --- cfe/trunk/test/SemaObjC/default-synthesize-3.m (original) +++ cfe/trunk/test/SemaObjC/default-synthesize-3.m Mon Jul 3 03:12:24 2017 @@ -173,13 +173,13 @@ typedef NSObject<Fooing> FooObject; @end @implementation Okay // expected-warning {{auto property synthesis will not synthesize property 'muahahaha' declared in protocol 'Fooing'}} expected-warning {{auto property synthesis will not synthesize property 'hoho' declared in protocol 'SubFooling'}} -@end +@end // expected-note 2 {{add a '@synthesize' directive}} @interface Fail : FooObject @end @implementation Fail // expected-warning {{auto property synthesis will not synthesize property 'muahahaha' declared in protocol 'Fooing'}} expected-warning {{auto property synthesis will not synthesize property 'hoho' declared in protocol 'SubFooling'}} -@end +@end // expected-note 2 {{add a '@synthesize' directive}} // rdar://16089191 @class NSURL; Modified: cfe/trunk/test/SemaObjC/default-synthesize.m URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/default-synthesize.m?rev=307014&r1=307013&r2=307014&view=diff ============================================================================== --- cfe/trunk/test/SemaObjC/default-synthesize.m (original) +++ cfe/trunk/test/SemaObjC/default-synthesize.m Mon Jul 3 03:12:24 2017 @@ -137,7 +137,7 @@ @end @implementation MyClass // expected-warning {{auto property synthesis will not synthesize property 'requiredString' declared in protocol 'MyProtocol'}} -@end +@end // expected-note {{add a '@synthesize' directive}} // rdar://18152478 @protocol NSObject @end Modified: cfe/trunk/test/SemaObjC/forward-protocol-incomplete-impl-warn.m URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/forward-protocol-incomplete-impl-warn.m?rev=307014&r1=307013&r2=307014&view=diff ============================================================================== --- cfe/trunk/test/SemaObjC/forward-protocol-incomplete-impl-warn.m (original) +++ cfe/trunk/test/SemaObjC/forward-protocol-incomplete-impl-warn.m Mon Jul 3 03:12:24 2017 @@ -17,4 +17,4 @@ @implementation IBImageCatalogDocument // expected-warning {{auto property synthesis will not synthesize property 'Prop' declared in protocol 'DVTInvalidation'}} \ // expected-warning {{method 'invalidate' in protocol 'DVTInvalidation' not implemented}} -@end +@end // expected-note {{add a '@synthesize' directive}} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits