r198367 - ObjectiveC. Remove false positive warning for missing property
Fariborz Jahanian
fjahanian at apple.com
Thu Jan 2 14:42:09 PST 2014
Author: fjahanian
Date: Thu Jan 2 16:42:09 2014
New Revision: 198367
URL: http://llvm.org/viewvc/llvm-project?rev=198367&view=rev
Log:
ObjectiveC. Remove false positive warning for missing property
backing ivar by not issuing this warning if ivar is referenced
somewhere and accessor makes method calls. // rdar://15727325
Added:
cfe/trunk/test/SemaObjC/unused-backing-ivar-warning.m
- copied, changed from r198346, cfe/trunk/test/SemaObjC/unsued-backing-ivar-warning.m
Removed:
cfe/trunk/test/SemaObjC/unsued-backing-ivar-warning.m
Modified:
cfe/trunk/include/clang/AST/DeclObjC.h
cfe/trunk/lib/Sema/SemaDeclObjC.cpp
cfe/trunk/lib/Sema/SemaExprObjC.cpp
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
Modified: cfe/trunk/include/clang/AST/DeclObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=198367&r1=198366&r2=198367&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Thu Jan 2 16:42:09 2014
@@ -161,6 +161,9 @@ private:
/// \brief Indicates if the method was a definition but its body was skipped.
unsigned HasSkippedBody : 1;
+
+ /// \brief True if method body makes a method call.
+ unsigned MethodCallsMethod : 1;
// Result type of this method.
QualType MethodDeclType;
@@ -242,7 +245,7 @@ private:
DeclImplementation(impControl), objcDeclQualifier(OBJC_TQ_None),
RelatedResultType(HasRelatedResultType),
SelLocsKind(SelLoc_StandardNoSpace), IsOverriding(0), HasSkippedBody(0),
- MethodDeclType(T), ResultTInfo(ResultTInfo),
+ MethodCallsMethod(0), MethodDeclType(T), ResultTInfo(ResultTInfo),
ParamsAndSelLocs(0), NumParams(0),
DeclEndLoc(endLoc), Body(), SelfDecl(0), CmdDecl(0) {
setImplicit(isImplicitlyDeclared);
@@ -436,6 +439,9 @@ public:
bool hasSkippedBody() const { return HasSkippedBody; }
void setHasSkippedBody(bool Skipped = true) { HasSkippedBody = Skipped; }
+ bool getMethodCallsMethod() const { return MethodCallsMethod; }
+ void setMethodCallsMethod(bool val = true) { MethodCallsMethod = val; }
+
/// \brief Returns the property associated with this method's selector.
///
/// Note that even if this particular method is not marked as a property
Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=198367&r1=198366&r2=198367&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Thu Jan 2 16:42:09 2014
@@ -3521,8 +3521,13 @@ void Sema::DiagnoseUnusedBackingIvarInAc
const ObjCPropertyDecl *PDecl;
const ObjCIvarDecl *IV = GetIvarBackingPropertyAccessor(CurMethod, PDecl);
if (IV && !IV->getBackingIvarReferencedInAccessor()) {
- Diag(getCurMethodDecl()->getLocation(), diag::warn_unused_property_backing_ivar)
- << IV->getDeclName();
- Diag(PDecl->getLocation(), diag::note_property_declare);
+ // Do not issue this warning if backing ivar is used somewhere and accessor
+ // implementation makes a call to a method. This is to prevent false positive in
+ // some corner cases.
+ if (!IV->isReferenced() || !CurMethod->getMethodCallsMethod()) {
+ Diag(getCurMethodDecl()->getLocation(), diag::warn_unused_property_backing_ivar)
+ << IV->getDeclName();
+ Diag(PDecl->getLocation(), diag::note_property_declare);
+ }
}
}
Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=198367&r1=198366&r2=198367&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Thu Jan 2 16:42:09 2014
@@ -2643,7 +2643,9 @@ ExprResult Sema::BuildInstanceMessage(Ex
}
}
}
-
+ if (ObjCMethodDecl *CurMeth = getCurMethodDecl())
+ CurMeth->setMethodCallsMethod(true);
+
return MaybeBindToTemporary(Result);
}
Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=198367&r1=198366&r2=198367&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Thu Jan 2 16:42:09 2014
@@ -702,6 +702,7 @@ void ASTDeclReader::VisitObjCMethodDecl(
MD->setDefined(Record[Idx++]);
MD->IsOverriding = Record[Idx++];
MD->HasSkippedBody = Record[Idx++];
+ MD->MethodCallsMethod = Record[Idx++];
MD->IsRedeclaration = Record[Idx++];
MD->HasRedeclaration = Record[Idx++];
Modified: cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterDecl.cpp?rev=198367&r1=198366&r2=198367&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriterDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriterDecl.cpp Thu Jan 2 16:42:09 2014
@@ -438,6 +438,7 @@ void ASTDeclWriter::VisitObjCMethodDecl(
Record.push_back(D->isDefined());
Record.push_back(D->IsOverriding);
Record.push_back(D->HasSkippedBody);
+ Record.push_back(D->MethodCallsMethod);
Record.push_back(D->IsRedeclaration);
Record.push_back(D->HasRedeclaration);
Removed: cfe/trunk/test/SemaObjC/unsued-backing-ivar-warning.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/unsued-backing-ivar-warning.m?rev=198366&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/unsued-backing-ivar-warning.m (original)
+++ cfe/trunk/test/SemaObjC/unsued-backing-ivar-warning.m (removed)
@@ -1,106 +0,0 @@
-// RUN: %clang_cc1 -fsyntax-only -Wunused-property-ivar -verify -Wno-objc-root-class %s
-// rdar://14989999
-
- at interface NSObject @end
-
- at interface Example : NSObject
- at property (nonatomic, copy) id t; // expected-note {{property declared here}}
- at property (nonatomic, copy) id u; // expected-note {{property declared here}}
- at property (nonatomic, copy) id v; // expected-note {{property declared here}}
- at property (nonatomic, copy) id w;
- at property (nonatomic, copy) id x; // expected-note {{property declared here}}
- at property (nonatomic, copy) id y; // expected-note {{property declared here}}
- at property (nonatomic, copy) id z;
- at property (nonatomic, copy) id ok;
- at end
-
- at implementation Example
-- (void) setX:(id)newX { // expected-warning {{ivar '_x' which backs the property is not referenced in this property's accessor}}
- _y = newX;
-}
-- (id) y { // expected-warning {{ivar '_y' which backs the property is not referenced in this property's accessor}}
- return _v;
-}
-
-- (void) setV:(id)newV { // expected-warning {{ivar '_v' which backs the property is not referenced in this property's accessor}}
- _y = newV;
-}
-
-// No warning here because there is no backing ivar.
-// both setter/getter are user defined.
-- (void) setW:(id)newW {
- _y = newW;
-}
-- (id) w {
- return _v;
-}
-
-- (id) u { // expected-warning {{ivar '_u' which backs the property is not referenced in this property's accessor}}
- return _v;
-}
-
- at synthesize ok = okIvar;
-- (void) setOk:(id)newOk {
- okIvar = newOk;
-}
-
- at synthesize t = tIvar;
-- (void) setT:(id)newT { // expected-warning {{ivar 'tIvar' which backs the property is not referenced in this property's accessor}}
- okIvar = newT;
-}
- at end
-
-// rdar://15473432
-typedef char BOOL;
- at interface CalDAVServerVersion {
- BOOL _supportsTimeRangeFilterWithoutEndDate;
-}
- at property (nonatomic, readonly,nonatomic) BOOL supportsTimeRangeFilterWithoutEndDate;
- at end
-
- at interface CalDAVConcreteServerVersion : CalDAVServerVersion {
-}
- at end
-
- at interface CalendarServerVersion : CalDAVConcreteServerVersion
- at end
-
- at implementation CalDAVServerVersion
- at synthesize supportsTimeRangeFilterWithoutEndDate=_supportsTimeRangeFilterWithoutEndDate;
- at end
-
- at implementation CalendarServerVersion
--(BOOL)supportsTimeRangeFilterWithoutEndDate {
- return 0;
-}
- at end
-
-// rdar://15630719
- at interface CDBModifyRecordsOperation : NSObject
- at property (nonatomic, assign) BOOL atomic;
- at end
-
- at class NSString;
-
- at implementation CDBModifyRecordsOperation
-- (void)setAtomic:(BOOL)atomic {
- if (atomic == __objc_yes) {
- NSString *recordZoneID = 0;
- }
- _atomic = atomic;
-}
- at end
-
-// rdar://15728901
- at interface GATTOperation : NSObject {
- long operation;
-}
- at property(assign) long operation;
- at end
-
- at implementation GATTOperation
- at synthesize operation;
-+ (id) operation {
- return 0;
-}
- at end
Copied: cfe/trunk/test/SemaObjC/unused-backing-ivar-warning.m (from r198346, cfe/trunk/test/SemaObjC/unsued-backing-ivar-warning.m)
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/unused-backing-ivar-warning.m?p2=cfe/trunk/test/SemaObjC/unused-backing-ivar-warning.m&p1=cfe/trunk/test/SemaObjC/unsued-backing-ivar-warning.m&r1=198346&r2=198367&rev=198367&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/unsued-backing-ivar-warning.m (original)
+++ cfe/trunk/test/SemaObjC/unused-backing-ivar-warning.m Thu Jan 2 16:42:09 2014
@@ -104,3 +104,23 @@ typedef char BOOL;
return 0;
}
@end
+
+// rdar://15727327
+ at interface Radar15727327 : NSObject
+ at property (assign, readonly) long p;
+ at property (assign) long q; // expected-note 2 {{property declared here}}
+ at property (assign, readonly) long r; // expected-note {{property declared here}}
+- (long)Meth;
+ at end
+
+ at implementation Radar15727327
+ at synthesize p;
+ at synthesize q;
+ at synthesize r;
+- (long)Meth { return p; }
+- (long) p { [self Meth]; return 0; }
+- (long) q { return 0; } // expected-warning {{ivar 'q' which backs the property is not referenced in this property's accessor}}
+- (void) setQ : (long) val { } // expected-warning {{ivar 'q' which backs the property is not referenced in this property's accessor}}
+- (long) r { [self Meth]; return p; } // expected-warning {{ivar 'r' which backs the property is not referenced in this property's accessor}}
+ at end
+
More information about the cfe-commits
mailing list