r214032 - Objective-C. Issue more warning diagnostic when certain
Fariborz Jahanian
fjahanian at apple.com
Sat Jul 26 13:52:26 PDT 2014
Author: fjahanian
Date: Sat Jul 26 15:52:26 2014
New Revision: 214032
URL: http://llvm.org/viewvc/llvm-project?rev=214032&view=rev
Log:
Objective-C. Issue more warning diagnostic when certain
properties are not synthesized in property auto-synthesis,
as it can potentiall lead to runtime errors.
rdar://17774815
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaObjCProperty.cpp
cfe/trunk/test/Analysis/objc_invalidation.m
cfe/trunk/test/SemaObjC/attr-deprecated.m
cfe/trunk/test/SemaObjC/default-synthesize-1.m
cfe/trunk/test/SemaObjC/default-synthesize-3.m
cfe/trunk/test/SemaObjC/default-synthesize.m
cfe/trunk/test/SemaObjC/protocols-suppress-conformance.m
cfe/trunk/test/SemaObjC/super-property-notation.m
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=214032&r1=214031&r2=214032&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sat Jul 26 15:52:26 2014
@@ -783,6 +783,10 @@ def warn_no_autosynthesis_property : War
"%0 because it is 'readwrite' but it will be synthesized 'readonly' "
"via another property">,
InGroup<ObjCNoPropertyAutoSynthesis>;
+def warn_autosynthesis_property_in_superclass : Warning<
+ "auto property synthesis will not synthesize property "
+ "%0 because it will be synthesize by its super class">,
+ InGroup<ObjCNoPropertyAutoSynthesis>;
def warn_autosynthesis_property_ivar_match :Warning<
"autosynthesized property %0 will use %select{|synthesized}1 instance variable "
"%2, not existing instance variable %3">,
Modified: cfe/trunk/lib/Sema/SemaObjCProperty.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaObjCProperty.cpp?rev=214032&r1=214031&r2=214032&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaObjCProperty.cpp (original)
+++ cfe/trunk/lib/Sema/SemaObjCProperty.cpp Sat Jul 26 15:52:26 2014
@@ -1555,20 +1555,23 @@ void Sema::DefaultSynthesizeProperties(S
ObjCPropertyDecl::OBJC_PR_readonly) &&
!IMPDecl->getInstanceMethod(Prop->getSetterName()) &&
!IDecl->HasUserDeclaredSetterMethod(Prop)) {
- Diag(Prop->getLocation(), diag::warn_no_autosynthesis_property)
- << Prop->getIdentifier();
- Diag(PropInSuperClass->getLocation(), diag::note_property_declare);
+ Diag(Prop->getLocation(), diag::warn_no_autosynthesis_property)
+ << Prop->getIdentifier();
+ Diag(PropInSuperClass->getLocation(), diag::note_property_declare);
+ }
+ else {
+ Diag(Prop->getLocation(), diag::warn_autosynthesis_property_in_superclass)
+ << Prop->getIdentifier();
+ Diag(IMPDecl->getLocation(), diag::note_while_in_implementation);
}
continue;
}
if (ObjCPropertyImplDecl *PID =
IMPDecl->FindPropertyImplIvarDecl(Prop->getIdentifier())) {
- if (PID->getPropertyDecl() != Prop) {
- Diag(Prop->getLocation(), diag::warn_no_autosynthesis_shared_ivar_property)
- << Prop->getIdentifier();
- if (!PID->getLocation().isInvalid())
- Diag(PID->getLocation(), diag::note_property_synthesize);
- }
+ Diag(Prop->getLocation(), diag::warn_no_autosynthesis_shared_ivar_property)
+ << Prop->getIdentifier();
+ if (!PID->getLocation().isInvalid())
+ Diag(PID->getLocation(), diag::note_property_synthesize);
continue;
}
if (ObjCProtocolDecl *Proto =
Modified: cfe/trunk/test/Analysis/objc_invalidation.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/objc_invalidation.m?rev=214032&r1=214031&r2=214032&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/objc_invalidation.m (original)
+++ cfe/trunk/test/Analysis/objc_invalidation.m Sat Jul 26 15:52:26 2014
@@ -199,7 +199,7 @@ extern void NSLog(NSString *format, ...)
// synthesized in the parent, let the parent invalidate it.
@protocol IDEBuildable <NSObject>
- at property (readonly, strong) id <Invalidation2> ObjB;
+ at property (readonly, strong) id <Invalidation2> ObjB; // expected-warning {{auto property synthesis will not synthesize property 'ObjB'}}
@end
@interface Parent : NSObject <IDEBuildable, Invalidation2> {
@@ -231,7 +231,7 @@ extern void NSLog(NSString *format, ...)
}
@end
- at implementation Child
+ at implementation Child // expected-note {{detected while default synthesizing properties in class implementation}}
- (void)invalidate{
// no-warning
}
Modified: cfe/trunk/test/SemaObjC/attr-deprecated.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/attr-deprecated.m?rev=214032&r1=214031&r2=214032&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/attr-deprecated.m (original)
+++ cfe/trunk/test/SemaObjC/attr-deprecated.m Sat Jul 26 15:52:26 2014
@@ -201,14 +201,14 @@ expected-note {{'setObject:' has been ex
@end
@interface TestDerived : TestBase
- at property (nonatomic, strong) id object;
+ at property (nonatomic, strong) id object; //expected-warning {{auto property synthesis will not synthesize property 'object' because it will be synthesize by its super class}}
@end
@interface TestUse @end
@implementation TestBase @end
- at implementation TestDerived @end
+ at implementation TestDerived @end // expected-note {{detected while default synthesizing properties in class implementation}}
@implementation TestUse
Modified: cfe/trunk/test/SemaObjC/default-synthesize-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/default-synthesize-1.m?rev=214032&r1=214031&r2=214032&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/default-synthesize-1.m (original)
+++ cfe/trunk/test/SemaObjC/default-synthesize-1.m Sat Jul 26 15:52:26 2014
@@ -124,3 +124,20 @@
// expected-note {{detected while default synthesizing properties in class implementation}}
@synthesize x; // expected-error {{cannot synthesize property 'x' with incomplete type 'enum A'}}
@end
+
+// rdar://17774815
+ at interface ZXParsedResult
+ at property (nonatomic, copy, readonly) NSString *description;
+ at end
+
+ at interface ZXCalendarParsedResult : ZXParsedResult
+
+ at property (nonatomic, copy, readonly) NSString *description; // expected-warning {{auto property synthesis will not synthesize property 'description' because it will be synthesize by its super class}}
+
+ at end
+
+ at implementation ZXCalendarParsedResult // expected-note {{detected while default synthesizing properties in class implementation}}
+- (NSString *) Meth {
+ return _description; // expected-error {{use of undeclared identifier '_description'}}
+}
+ at end
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=214032&r1=214031&r2=214032&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/default-synthesize-3.m (original)
+++ cfe/trunk/test/SemaObjC/default-synthesize-3.m Sat Jul 26 15:52:26 2014
@@ -66,10 +66,10 @@ __attribute ((objc_requires_property_def
@property (readwrite) char isFoo; // expected-warning {{auto property synthesis will not synthesize property 'isFoo' because it is 'readwrite' but it will be synthesized 'readonly' via another property}}
@property char Property1; // expected-warning {{auto property synthesis will not synthesize property 'Property1' because it cannot share an ivar with another synthesized property}}
@property char Property2;
- at property (readwrite) char isNotFree;
+ at property (readwrite) char isNotFree; // expected-warning {{auto property synthesis will not synthesize property 'isNotFree'}}
@end
- at implementation Baz {
+ at implementation Baz { // expected-note {{detected while default synthesizing properties in class implementation}}
char _isFoo;
char _isNotFree;
}
@@ -104,12 +104,12 @@ __attribute ((objc_requires_property_def
@end
@interface S : B<P1>
- at property (assign,readwrite) id prop;
- at property (assign,readwrite) id prop1;
- at property (assign,readwrite) id prop2;
+ at property (assign,readwrite) id prop; // expected-warning {{auto property synthesis will not synthesize property 'prop'}}
+ at property (assign,readwrite) id prop1; // expected-warning {{auto property synthesis will not synthesize property 'prop1'}}
+ at property (assign,readwrite) id prop2; // expected-warning {{auto property synthesis will not synthesize property 'prop2'}}
@end
- at implementation S
+ at implementation S // expected-note 3 {{detected while default synthesizing properties in class implementation}}
@end
// rdar://14085456
Modified: cfe/trunk/test/SemaObjC/default-synthesize.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/default-synthesize.m?rev=214032&r1=214031&r2=214032&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/default-synthesize.m (original)
+++ cfe/trunk/test/SemaObjC/default-synthesize.m Sat Jul 26 15:52:26 2014
@@ -88,7 +88,7 @@
@end
@protocol TopProtocol
- @property (readonly) id myString;
+ @property (readonly) id myString; // expected-warning {{auto property synthesis will not synthesize property 'myString' because it will be synthesize by its super class}}
@end
@interface TopClass <TopProtocol>
@@ -97,10 +97,10 @@
}
@end
- at interface SubClass : TopClass <TopProtocol>
+ at interface SubClass : TopClass <TopProtocol>
@end
- at implementation SubClass @end
+ at implementation SubClass @end // expected-note {{detected while default synthesizing properties in class implementation}}
// rdar://7920807
@interface C @end
Modified: cfe/trunk/test/SemaObjC/protocols-suppress-conformance.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/protocols-suppress-conformance.m?rev=214032&r1=214031&r2=214032&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/protocols-suppress-conformance.m (original)
+++ cfe/trunk/test/SemaObjC/protocols-suppress-conformance.m Sat Jul 26 15:52:26 2014
@@ -5,7 +5,8 @@
__attribute__((objc_protocol_requires_explicit_implementation))
@protocol Protocol
- (void) theBestOfTimes; // expected-note {{method 'theBestOfTimes' declared here}}
- at property (readonly) id theWorstOfTimes; // expected-note {{property declared here}}
+ at property (readonly) id theWorstOfTimes; // expected-note {{property declared here}} \
+ // expected-warning 2 {{auto property synthesis will not synthesize property 'theWorstOfTimes'}}
@end
// In this example, ClassA adopts the protocol. We won't
@@ -20,7 +21,8 @@ __attribute__((objc_protocol_requires_ex
@interface ClassB : ClassA <Protocol>
@end
- at implementation ClassB // expected-warning {{property 'theWorstOfTimes' requires method 'theWorstOfTimes' to be defined - use @synthesize, @dynamic or provide a method implementation in this class implementation}}
+ at implementation ClassB // expected-warning {{property 'theWorstOfTimes' requires method 'theWorstOfTimes' to be defined - use @synthesize, @dynamic or provide a method implementation in this class implementation}} \
+ // expected-note {{detected while default synthesizing properties in class implementation}}
@end
@interface ClassB_Good : ClassA <Protocol>
@@ -32,7 +34,7 @@ __attribute__((objc_protocol_requires_ex
@end
@interface ClassB_AlsoGood : ClassA <Protocol>
- at property (readonly) id theWorstOfTimes;
+ at property (readonly) id theWorstOfTimes; // expected-warning {{auto property synthesis will not synthesize property 'theWorstOfTimes' because it will be synthesize by its super class}}
@end
// Default synthesis acts as if @dynamic
@@ -40,7 +42,7 @@ __attribute__((objc_protocol_requires_ex
// it is declared in ClassA. This is okay, since
// the author of ClassB_AlsoGood needs explicitly
// write @property in the @interface.
- at implementation ClassB_AlsoGood // no-warning
+ at implementation ClassB_AlsoGood // expected-note 2 {{detected while default synthesizing properties in class implementation}}
- (void) theBestOfTimes {}
@end
Modified: cfe/trunk/test/SemaObjC/super-property-notation.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/super-property-notation.m?rev=214032&r1=214031&r2=214032&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/super-property-notation.m (original)
+++ cfe/trunk/test/SemaObjC/super-property-notation.m Sat Jul 26 15:52:26 2014
@@ -41,10 +41,10 @@ __attribute__((objc_root_class)) @interf
@end
@interface ClassDerived : ClassBase
- at property (nonatomic, retain) ClassDerived * foo;
+ at property (nonatomic, retain) ClassDerived * foo; // expected-warning {{auto property synthesis will not synthesize property 'foo' because it will be synthesize by its super class}}
@end
- at implementation ClassDerived
+ at implementation ClassDerived // expected-note {{detected while default synthesizing properties in class implementation}}
- (void) Meth:(ClassBase*)foo {
super.foo = foo; // must work with no warning
[super setFoo:foo]; // works with no warning
More information about the cfe-commits
mailing list