[cfe-commits] r158828 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaObjCProperty.cpp test/SemaObjC/default-synthesize-2.m
Fariborz Jahanian
fjahanian at apple.com
Wed Jun 20 10:18:31 PDT 2012
Author: fjahanian
Date: Wed Jun 20 12:18:31 2012
New Revision: 158828
URL: http://llvm.org/viewvc/llvm-project?rev=158828&view=rev
Log:
objc: improved diagnostic when property autosynthesis may cause
change in behavior. // rdar://11671080
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaObjCProperty.cpp
cfe/trunk/test/SemaObjC/default-synthesize-2.m
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=158828&r1=158827&r2=158828&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Jun 20 12:18:31 2012
@@ -631,7 +631,8 @@
" declared in a protocol">,
InGroup<DiagGroup<"objc-protocol-property-synthesis">>;
def warn_autosynthesis_property_ivar_match :Warning<
- "auto autosynthesized property has same name as an existing ivar">,
+ "autosynthesized property %0 will use %select{|synthesized}1 instance variable "
+ "%2, not existing instance variable %3">,
InGroup<DiagGroup<"objc-autosynthesis-property-ivar-name-match">>;
def warn_missing_explicit_synthesis : Warning <
"auto property synthesis is synthesizing property not explicitly synthesized">,
Modified: cfe/trunk/lib/Sema/SemaObjCProperty.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaObjCProperty.cpp?rev=158828&r1=158827&r2=158828&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaObjCProperty.cpp (original)
+++ cfe/trunk/lib/Sema/SemaObjCProperty.cpp Wed Jun 20 12:18:31 2012
@@ -753,24 +753,26 @@
Context.getObjCGCQualType(PropertyIvarType, Qualifiers::Weak);
}
}
-
- if (!Ivar) {
- if (AtLoc.isInvalid()) {
- // Check when default synthesizing a property that there is
- // an ivar matching property name and issue warning; since this
- // is the most common case of not using an ivar used for backing
- // property in non-default synthesis case.
- ObjCInterfaceDecl *ClassDeclared=0;
- ObjCIvarDecl *originalIvar =
- IDecl->lookupInstanceVariable(property->getIdentifier(),
- ClassDeclared);
- if (originalIvar) {
- Diag(PropertyDiagLoc,
- diag::warn_autosynthesis_property_ivar_match);
- Diag(property->getLocation(), diag::note_property_declare);
- Diag(originalIvar->getLocation(), diag::note_ivar_decl);
- }
+ if (AtLoc.isInvalid()) {
+ // Check when default synthesizing a property that there is
+ // an ivar matching property name and issue warning; since this
+ // is the most common case of not using an ivar used for backing
+ // property in non-default synthesis case.
+ ObjCInterfaceDecl *ClassDeclared=0;
+ ObjCIvarDecl *originalIvar =
+ IDecl->lookupInstanceVariable(property->getIdentifier(),
+ ClassDeclared);
+ if (originalIvar) {
+ Diag(PropertyDiagLoc,
+ diag::warn_autosynthesis_property_ivar_match)
+ << property->getName() << (Ivar == 0) << PropertyIvar->getName()
+ << originalIvar->getName();
+ Diag(property->getLocation(), diag::note_property_declare);
+ Diag(originalIvar->getLocation(), diag::note_ivar_decl);
}
+ }
+
+ if (!Ivar) {
// In ARC, give the ivar a lifetime qualifier based on the
// property attributes.
if (getLangOpts().ObjCAutoRefCount &&
Modified: cfe/trunk/test/SemaObjC/default-synthesize-2.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/default-synthesize-2.m?rev=158828&r1=158827&r2=158828&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/default-synthesize-2.m (original)
+++ cfe/trunk/test/SemaObjC/default-synthesize-2.m Wed Jun 20 12:18:31 2012
@@ -47,7 +47,7 @@
@end
// rdar://11671080
- at implementation Test3 // expected-warning {{auto autosynthesized property has same name as an existing ivar}}
+ at implementation Test3 // expected-warning {{autosynthesized property uid will use synthesized instance variable _uid, not existing instance variable uid}}
// Oops, forgot to write @synthesize! will be default synthesized
- (void) myMethod {
self.uid = 0; // Use of the âsetterâ
@@ -115,3 +115,15 @@
}
@end
+// rdar://11671080
+ at interface Test8
+{
+ id _y;
+ id y; // expected-note {{ivar is declared here}}
+}
+ at property(copy) id y; // expected-note {{property declared here}}
+ at end
+
+
+ at implementation Test8 @end // expected-warning {{autosynthesized property y will use instance variable _y, not existing instance variable y}}
+
More information about the cfe-commits
mailing list