Objective-C arc: don't count use of __weak

variables when they are used in such unevaluated 
contexts as __typeof, etc. // rdar://13942025

llvm-svn: 182423
This commit is contained in:
Fariborz Jahanian 2013-05-21 21:20:26 +00:00
parent 9d3ccc700f
commit 6f829e34b3
5 changed files with 27 additions and 6 deletions

View File

@ -957,7 +957,13 @@ public:
sema::FunctionScopeInfo *getCurFunction() const {
return FunctionScopes.back();
}
template <typename ExprT>
void recordUseOfEvaluatedWeak(const ExprT *E, bool IsRead=true) {
if (!isUnevaluatedContext())
getCurFunction()->recordUseOfWeak(E, IsRead);
}
void PushCompoundScope();
void PopCompoundScope();

View File

@ -1550,7 +1550,7 @@ Sema::BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK,
Diags.getDiagnosticLevel(diag::warn_arc_repeated_use_of_weak,
E->getLocStart());
if (Level != DiagnosticsEngine::Ignored)
getCurFunction()->recordUseOfWeak(E);
recordUseOfEvaluatedWeak(E);
}
// Just in case we're building an illegal pointer-to-member.
@ -2152,7 +2152,7 @@ Sema::LookupInObjCMethod(LookupResult &Lookup, Scope *S,
DiagnosticsEngine::Level Level =
Diags.getDiagnosticLevel(diag::warn_arc_repeated_use_of_weak, Loc);
if (Level != DiagnosticsEngine::Ignored)
getCurFunction()->recordUseOfWeak(Result);
recordUseOfEvaluatedWeak(Result);
}
if (CurContext->isClosure())
Diag(Loc, diag::warn_implicitly_retains_self)

View File

@ -1311,7 +1311,7 @@ Sema::LookupMemberExpr(LookupResult &R, ExprResult &BaseExpr,
Diags.getDiagnosticLevel(diag::warn_arc_repeated_use_of_weak,
MemberLoc);
if (Level != DiagnosticsEngine::Ignored)
getCurFunction()->recordUseOfWeak(Result);
recordUseOfEvaluatedWeak(Result);
}
}

View File

@ -882,8 +882,8 @@ ExprResult ObjCPropertyOpBuilder::complete(Expr *SyntacticForm) {
S.Diags.getDiagnosticLevel(diag::warn_arc_repeated_use_of_weak,
SyntacticForm->getLocStart());
if (Level != DiagnosticsEngine::Ignored)
S.getCurFunction()->recordUseOfWeak(SyntacticRefExpr,
SyntacticRefExpr->isMessagingGetter());
S.recordUseOfEvaluatedWeak(SyntacticRefExpr,
SyntacticRefExpr->isMessagingGetter());
}
return PseudoOpBuilder::complete(SyntacticForm);

View File

@ -410,3 +410,18 @@ void doubleLevelAccessIvar(Test *a, Test *b) {
use(a.strongProp.weakProp); // no-warning
}
// rdar://13942025
@interface X
@end
@implementation X
- (int) warningAboutWeakVariableInsideTypeof {
__typeof__(self) __weak weakSelf = self;
^(){
__typeof__(weakSelf) blockSelf = weakSelf;
use(blockSelf);
}();
return sizeof(weakSelf);
}
@end