[cfe-commits] r148355 - in /cfe/trunk: lib/Sema/SemaChecking.cpp test/SemaObjC/arc-property-lifetime.m
Fariborz Jahanian
fjahanian at apple.com
Tue Jan 17 14:58:17 PST 2012
Author: fjahanian
Date: Tue Jan 17 16:58:16 2012
New Revision: 148355
URL: http://llvm.org/viewvc/llvm-project?rev=148355&view=rev
Log:
objc-arc: when 'assign' attribute is unspecified,
rely on property's type for its life-time to avoid
bogus warning with -Warc-unsafe-retained-assign.
// rdar://10694932
Modified:
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/SemaObjC/arc-property-lifetime.m
Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=148355&r1=148354&r2=148355&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Jan 17 16:58:16 2012
@@ -4652,7 +4652,19 @@
void Sema::checkUnsafeExprAssigns(SourceLocation Loc,
Expr *LHS, Expr *RHS) {
- QualType LHSType = LHS->getType();
+ QualType LHSType;
+ // PropertyRef on LHS type need be directly obtained from
+ // its declaration as it has a PsuedoType.
+ ObjCPropertyRefExpr *PRE
+ = dyn_cast<ObjCPropertyRefExpr>(LHS->IgnoreParens());
+ if (PRE && !PRE->isImplicitProperty()) {
+ const ObjCPropertyDecl *PD = PRE->getExplicitProperty();
+ if (PD)
+ LHSType = PD->getType();
+ }
+
+ if (LHSType.isNull())
+ LHSType = LHS->getType();
if (checkUnsafeAssigns(Loc, LHSType, RHS))
return;
Qualifiers::ObjCLifetime LT = LHSType.getObjCLifetime();
@@ -4660,8 +4672,7 @@
if (LT != Qualifiers::OCL_None)
return;
- if (ObjCPropertyRefExpr *PRE
- = dyn_cast<ObjCPropertyRefExpr>(LHS->IgnoreParens())) {
+ if (PRE) {
if (PRE->isImplicitProperty())
return;
const ObjCPropertyDecl *PD = PRE->getExplicitProperty();
@@ -4669,7 +4680,15 @@
return;
unsigned Attributes = PD->getPropertyAttributes();
- if (Attributes & ObjCPropertyDecl::OBJC_PR_assign)
+ if (Attributes & ObjCPropertyDecl::OBJC_PR_assign) {
+ // when 'assign' attribute was not explicitly specified
+ // by user, ignore it and rely on property type itself
+ // for lifetime info.
+ unsigned AsWrittenAttr = PD->getPropertyAttributesAsWritten();
+ if (!(AsWrittenAttr & ObjCPropertyDecl::OBJC_PR_assign) &&
+ LHSType->isObjCRetainableType())
+ return;
+
while (ImplicitCastExpr *cast = dyn_cast<ImplicitCastExpr>(RHS)) {
if (cast->getCastKind() == CK_ARCConsumeObject) {
Diag(Loc, diag::warn_arc_retained_property_assign)
@@ -4678,5 +4697,6 @@
}
RHS = cast->getSubExpr();
}
+ }
}
}
Modified: cfe/trunk/test/SemaObjC/arc-property-lifetime.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/arc-property-lifetime.m?rev=148355&r1=148354&r2=148355&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/arc-property-lifetime.m (original)
+++ cfe/trunk/test/SemaObjC/arc-property-lifetime.m Tue Jan 17 16:58:16 2012
@@ -149,3 +149,22 @@
}
@end
+// rdar://10694932
+ at interface Baz
+ at property id prop;
+ at property __strong id strong_prop;
+ at property (strong) id strong_attr_prop;
+ at property (strong) __strong id realy_strong_attr_prop;
++ (id) alloc;
+- (id) init;
+- (id) implicit;
+- (void) setImplicit : (id) arg;
+ at end
+
+void foo(Baz *f) {
+ f.prop = [[Baz alloc] init];
+ f.strong_prop = [[Baz alloc] init];
+ f.strong_attr_prop = [[Baz alloc] init];
+ f.realy_strong_attr_prop = [[Baz alloc] init];
+ f.implicit = [[Baz alloc] init];
+}
More information about the cfe-commits
mailing list