From: Jordan Rose Date: Wed, 10 Oct 2012 16:43:06 +0000 (+0000) Subject: -Warc-repeated-use-of-weak: look through explicit casts on assigned values. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c88f8ef9d85a537233b4423d31dbf8bc81be525a;p=clang -Warc-repeated-use-of-weak: look through explicit casts on assigned values. Reading from a weak property, casting the result, and assigning to a strong pointer should still be considered safe. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@165629 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/ScopeInfo.cpp b/lib/Sema/ScopeInfo.cpp index 7a9d917a02..76f967d588 100644 --- a/lib/Sema/ScopeInfo.cpp +++ b/lib/Sema/ScopeInfo.cpp @@ -115,7 +115,7 @@ FunctionScopeInfo::WeakObjectProfileTy::WeakObjectProfileTy( } void FunctionScopeInfo::markSafeWeakUse(const Expr *E) { - E = E->IgnoreParenImpCasts(); + E = E->IgnoreParenCasts(); if (const PseudoObjectExpr *POE = dyn_cast(E)) { markSafeWeakUse(POE->getSyntacticForm()); diff --git a/test/SemaObjC/arc-repeated-weak.mm b/test/SemaObjC/arc-repeated-weak.mm index 90ba75f6ef..1c6578ef13 100644 --- a/test/SemaObjC/arc-repeated-weak.mm +++ b/test/SemaObjC/arc-repeated-weak.mm @@ -147,6 +147,17 @@ void testBlock(Test *a) { }); } +void assignToStrongWithCasts(Test *a) { + if (condition()) { + Test *val = (Test *)a.weakProp; // no-warning + (void)val; + } else { + id val; + val = (Test *)a.weakProp; // no-warning + (void)val; + } +} + @interface Test (Methods) @end