Suppress -Wunused-variable when initializer uses bridge casts for memory management.

Fixes <rdar://problem/15432770>.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@194647 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 9281951..a7b37c5 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -1313,6 +1313,28 @@
       }
     }
 
+    // Under ARC, bridged casts can have side-effects on memory
+    // management semantics.  Some users assign a bridged
+    // value to a temporary to adjust reference counts.
+    const Expr *Init = VD->getInit();
+    if (Init) {
+      if (const ExprWithCleanups *EC = dyn_cast<ExprWithCleanups>(Init))
+        Init = EC->getSubExpr();
+      Init = Init->IgnoreParens();
+      if (const ImplicitCastExpr *IC = dyn_cast<ImplicitCastExpr>(Init)) {
+        switch (IC->getCastKind()) {
+        case CK_ARCProduceObject:
+        case CK_ARCConsumeObject:
+        case CK_ARCReclaimReturnedObject:
+        case CK_ARCExtendBlockObject:
+        case CK_CopyAndAutoreleaseBlockObject:
+          return false;
+        default:
+          break;
+        }
+      }
+    }
+
     // TODO: __attribute__((unused)) templates?
   }