]> granicus.if.org Git - clang/commitdiff
-Warc-repeated-use-of-weak: look through explicit casts on assigned values.
authorJordan Rose <jordan_rose@apple.com>
Wed, 10 Oct 2012 16:43:06 +0000 (16:43 +0000)
committerJordan Rose <jordan_rose@apple.com>
Wed, 10 Oct 2012 16:43:06 +0000 (16:43 +0000)
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

lib/Sema/ScopeInfo.cpp
test/SemaObjC/arc-repeated-weak.mm

index 7a9d917a025088489d995ade75fa115fae0c51ff..76f967d588be83a4a015e6a1051522707e9d9531 100644 (file)
@@ -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<PseudoObjectExpr>(E)) {
     markSafeWeakUse(POE->getSyntacticForm());
index 90ba75f6efde730dbd4a0c29fadc67bdb392d17f..1c6578ef13138f9b52450698945336f48dd103b2 100644 (file)
@@ -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