In ARC, reclaim all return values of retainable type, not just those
where we have an immediate need of a retained value.

As an exception, don't do this when the call is made as the immediate
operand of a __bridge retain.  This is more in the way of a workaround
than an actual guarantee, so it's acceptable to be brittle here.

rdar://problem/9504800



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@134605 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/ARCMigrate/TransRetainReleaseDealloc.cpp b/lib/ARCMigrate/TransRetainReleaseDealloc.cpp
index c177363..fe80a43 100644
--- a/lib/ARCMigrate/TransRetainReleaseDealloc.cpp
+++ b/lib/ARCMigrate/TransRetainReleaseDealloc.cpp
@@ -116,11 +116,16 @@
       return true;
     }
 
-    if (ParenExpr *parenE = dyn_cast_or_null<ParenExpr>(StmtMap->getParent(E)))
+    Stmt *parent = StmtMap->getParent(E);
+
+    if (ImplicitCastExpr *castE = dyn_cast_or_null<ImplicitCastExpr>(parent))
+      return tryRemoving(castE);
+
+    if (ParenExpr *parenE = dyn_cast_or_null<ParenExpr>(parent))
       return tryRemoving(parenE);
 
     if (BinaryOperator *
-          bopE = dyn_cast_or_null<BinaryOperator>(StmtMap->getParent(E))) {
+          bopE = dyn_cast_or_null<BinaryOperator>(parent)) {
       if (bopE->getOpcode() == BO_Comma && bopE->getLHS() == E &&
           isRemovable(bopE)) {
         Pass.TA.replace(bopE->getSourceRange(), bopE->getRHS()->getSourceRange());
diff --git a/lib/ARCMigrate/TransformActions.cpp b/lib/ARCMigrate/TransformActions.cpp
index 45a3d47..2ae9798 100644
--- a/lib/ARCMigrate/TransformActions.cpp
+++ b/lib/ARCMigrate/TransformActions.cpp
@@ -313,7 +313,7 @@
   assert(IsInTransaction && "Actions only allowed during a transaction");
   ActionData data;
   data.Kind = Act_RemoveStmt;
-  data.S = S;
+  data.S = S->IgnoreImplicit(); // important for uniquing
   CachedActions.push_back(data);
 }
 
diff --git a/lib/ARCMigrate/Transforms.cpp b/lib/ARCMigrate/Transforms.cpp
index 1a98833..80c52d7 100644
--- a/lib/ARCMigrate/Transforms.cpp
+++ b/lib/ARCMigrate/Transforms.cpp
@@ -180,12 +180,9 @@
   void mark(Stmt *S) {
     if (!S) return;
     
-    if (LabelStmt *Label = dyn_cast<LabelStmt>(S))
-      return mark(Label->getSubStmt());
-    if (ImplicitCastExpr *CE = dyn_cast<ImplicitCastExpr>(S))
-      return mark(CE->getSubExpr());
-    if (ExprWithCleanups *EWC = dyn_cast<ExprWithCleanups>(S))
-      return mark(EWC->getSubExpr());
+    while (LabelStmt *Label = dyn_cast<LabelStmt>(S))
+      S = Label->getSubStmt();
+    S = S->IgnoreImplicit();
     if (Expr *E = dyn_cast<Expr>(S))
       Removables.insert(E);
   }