From: Fariborz Jahanian Date: Tue, 21 May 2013 21:20:26 +0000 (+0000) Subject: Objective-C arc: don't count use of __weak X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=569b4ad6506960f1a7f191107c185cb1566a7fbb;p=clang Objective-C arc: don't count use of __weak variables when they are used in such unevaluated contexts as __typeof, etc. // rdar://13942025 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182423 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index 69ef5f9cc2..f4e5cd468b 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -957,7 +957,13 @@ public: sema::FunctionScopeInfo *getCurFunction() const { return FunctionScopes.back(); } - + + template + void recordUseOfEvaluatedWeak(const ExprT *E, bool IsRead=true) { + if (!isUnevaluatedContext()) + getCurFunction()->recordUseOfWeak(E, IsRead); + } + void PushCompoundScope(); void PopCompoundScope(); diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 87bc673adf..9d6601af32 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -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) diff --git a/lib/Sema/SemaExprMember.cpp b/lib/Sema/SemaExprMember.cpp index 0f65d3f505..6a31a362f0 100644 --- a/lib/Sema/SemaExprMember.cpp +++ b/lib/Sema/SemaExprMember.cpp @@ -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); } } diff --git a/lib/Sema/SemaPseudoObject.cpp b/lib/Sema/SemaPseudoObject.cpp index 054d557e92..fe11b37068 100644 --- a/lib/Sema/SemaPseudoObject.cpp +++ b/lib/Sema/SemaPseudoObject.cpp @@ -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); diff --git a/test/SemaObjC/arc-repeated-weak.mm b/test/SemaObjC/arc-repeated-weak.mm index b5d9002130..64df92a9af 100644 --- a/test/SemaObjC/arc-repeated-weak.mm +++ b/test/SemaObjC/arc-repeated-weak.mm @@ -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 +