зеркало из https://github.com/microsoft/clang-1.git
objective-arc: Retune my previous patch so warning
is issued on weak property as receiver and not on any other use of a weak property. // rdar://10225276 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@155169 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
1e77b65b48
Коммит
9879556f25
|
@ -5901,9 +5901,6 @@ public:
|
||||||
bool IsInstance);
|
bool IsInstance);
|
||||||
|
|
||||||
bool inferObjCARCLifetime(ValueDecl *decl);
|
bool inferObjCARCLifetime(ValueDecl *decl);
|
||||||
|
|
||||||
void DiagnoseARCUseOfWeakReceiver(NamedDecl *PDecl,
|
|
||||||
QualType T, SourceLocation Loc);
|
|
||||||
|
|
||||||
ExprResult
|
ExprResult
|
||||||
HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT,
|
HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT,
|
||||||
|
|
|
@ -1323,30 +1323,48 @@ ObjCMethodDecl *Sema::LookupMethodInQualifiedType(Selector Sel,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void DiagnoseARCUseOfWeakReceiver(Sema &S, Expr *Receiver) {
|
||||||
Sema::DiagnoseARCUseOfWeakReceiver(NamedDecl *PDecl,
|
if (!Receiver)
|
||||||
QualType T, SourceLocation Loc) {
|
|
||||||
if (!getLangOpts().ObjCAutoRefCount)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (T.getObjCLifetime() == Qualifiers::OCL_Weak) {
|
Expr *RExpr = Receiver->IgnoreParenImpCasts();
|
||||||
Diag(Loc, diag::warn_receiver_is_weak)
|
SourceLocation Loc = RExpr->getLocStart();
|
||||||
<< (!PDecl ? 0 : (isa<ObjCPropertyDecl>(PDecl) ? 1 : 2));
|
QualType T = RExpr->getType();
|
||||||
if (PDecl) {
|
ObjCPropertyDecl *PDecl = 0;
|
||||||
if (isa<ObjCPropertyDecl>(PDecl))
|
ObjCMethodDecl *GDecl = 0;
|
||||||
Diag(PDecl->getLocation(), diag::note_property_declare);
|
if (PseudoObjectExpr *POE = dyn_cast<PseudoObjectExpr>(RExpr)) {
|
||||||
else
|
RExpr = POE->getSyntacticForm();
|
||||||
Diag(PDecl->getLocation(), diag::note_method_declared_at) << PDecl;
|
if (ObjCPropertyRefExpr *PRE = dyn_cast<ObjCPropertyRefExpr>(RExpr)) {
|
||||||
|
if (PRE->isImplicitProperty()) {
|
||||||
|
GDecl = PRE->getImplicitPropertyGetter();
|
||||||
|
if (GDecl) {
|
||||||
|
T = GDecl->getResultType();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
PDecl = PRE->getExplicitProperty();
|
||||||
|
if (PDecl) {
|
||||||
|
T = PDecl->getType();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (T.getObjCLifetime() == Qualifiers::OCL_Weak) {
|
||||||
|
S.Diag(Loc, diag::warn_receiver_is_weak)
|
||||||
|
<< ((!PDecl && !GDecl) ? 0 : (PDecl ? 1 : 2));
|
||||||
|
if (PDecl)
|
||||||
|
S.Diag(PDecl->getLocation(), diag::note_property_declare);
|
||||||
|
else if (GDecl)
|
||||||
|
S.Diag(GDecl->getLocation(), diag::note_method_declared_at) << GDecl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PDecl)
|
if (PDecl &&
|
||||||
if (ObjCPropertyDecl *Prop = dyn_cast<ObjCPropertyDecl>(PDecl))
|
(PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_weak)) {
|
||||||
if (Prop->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_weak) {
|
S.Diag(Loc, diag::warn_receiver_is_weak) << 1;
|
||||||
Diag(Loc, diag::warn_receiver_is_weak) << 1;
|
S.Diag(PDecl->getLocation(), diag::note_property_declare);
|
||||||
Diag(Prop->getLocation(), diag::note_property_declare);
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// HandleExprPropertyRefExpr - Handle foo.bar where foo is a pointer to an
|
/// HandleExprPropertyRefExpr - Handle foo.bar where foo is a pointer to an
|
||||||
|
@ -2404,10 +2422,7 @@ ExprResult Sema::BuildInstanceMessage(Expr *Receiver,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getLangOpts().ObjCAutoRefCount) {
|
if (getLangOpts().ObjCAutoRefCount) {
|
||||||
if (Receiver)
|
DiagnoseARCUseOfWeakReceiver(*this, Receiver);
|
||||||
DiagnoseARCUseOfWeakReceiver(0 /* PDecl */,
|
|
||||||
Receiver->IgnoreParenImpCasts()->getType(),
|
|
||||||
Receiver->getLocStart());
|
|
||||||
|
|
||||||
// In ARC, annotate delegate init calls.
|
// In ARC, annotate delegate init calls.
|
||||||
if (Result->getMethodFamily() == OMF_init &&
|
if (Result->getMethodFamily() == OMF_init &&
|
||||||
|
|
|
@ -478,8 +478,6 @@ bool ObjCPropertyOpBuilder::findGetter() {
|
||||||
if (RefExpr->isImplicitProperty()) {
|
if (RefExpr->isImplicitProperty()) {
|
||||||
if ((Getter = RefExpr->getImplicitPropertyGetter())) {
|
if ((Getter = RefExpr->getImplicitPropertyGetter())) {
|
||||||
GetterSelector = Getter->getSelector();
|
GetterSelector = Getter->getSelector();
|
||||||
S.DiagnoseARCUseOfWeakReceiver(Getter, Getter->getResultType(),
|
|
||||||
RefExpr->getLocation());
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -499,8 +497,6 @@ bool ObjCPropertyOpBuilder::findGetter() {
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjCPropertyDecl *prop = RefExpr->getExplicitProperty();
|
ObjCPropertyDecl *prop = RefExpr->getExplicitProperty();
|
||||||
S.DiagnoseARCUseOfWeakReceiver(prop, prop->getType(),
|
|
||||||
RefExpr->getLocation());
|
|
||||||
Getter = LookupMethodInReceiverType(S, prop->getGetterName(), RefExpr);
|
Getter = LookupMethodInReceiverType(S, prop->getGetterName(), RefExpr);
|
||||||
return (Getter != 0);
|
return (Getter != 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,21 +23,21 @@ void test0(Test0 *x) {
|
||||||
__weak Test* weak_prop;
|
__weak Test* weak_prop;
|
||||||
}
|
}
|
||||||
- (void) Meth;
|
- (void) Meth;
|
||||||
@property __weak Test* weak_prop; // expected-note 2 {{property declared here}}
|
@property __weak Test* weak_prop; // expected-note {{property declared here}}
|
||||||
@property (weak, atomic) id weak_atomic_prop; // expected-note 2 {{property declared here}}
|
@property (weak, atomic) id weak_atomic_prop; // expected-note {{property declared here}}
|
||||||
- (__weak id) P; // expected-note 2 {{method 'P' declared here}}
|
- (__weak id) P; // expected-note {{method 'P' declared here}}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation Test
|
@implementation Test
|
||||||
- (void) Meth {
|
- (void) Meth {
|
||||||
if (self.weak_prop) { // expected-warning {{weak property may be unpredictably null in ARC mode}}
|
if (self.weak_prop) {
|
||||||
self.weak_prop = 0;
|
self.weak_prop = 0;
|
||||||
}
|
}
|
||||||
if (self.weak_atomic_prop) { // expected-warning {{weak property may be unpredictably null in ARC mode}}
|
if (self.weak_atomic_prop) {
|
||||||
self.weak_atomic_prop = 0;
|
self.weak_atomic_prop = 0;
|
||||||
}
|
}
|
||||||
[self.weak_prop Meth]; // expected-warning {{weak property may be unpredictably null in ARC mode}}
|
[self.weak_prop Meth]; // expected-warning {{weak property may be unpredictably null in ARC mode}}
|
||||||
id pi = self.P; // expected-warning {{weak implicit property may be unpredictably null in ARC mode}}
|
id pi = self.P;
|
||||||
|
|
||||||
[self.weak_atomic_prop Meth]; // expected-warning {{weak property may be unpredictably null in ARC mode}}
|
[self.weak_atomic_prop Meth]; // expected-warning {{weak property may be unpredictably null in ARC mode}}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче