]> granicus.if.org Git - clang/commitdiff
Look through parentheses.
authorAkira Hatanaka <ahatanaka@apple.com>
Thu, 28 Sep 2017 01:31:17 +0000 (01:31 +0000)
committerAkira Hatanaka <ahatanaka@apple.com>
Thu, 28 Sep 2017 01:31:17 +0000 (01:31 +0000)
This fixes a bug where clang would emit instructions to reclaim a value
that's going to be __bridge-casted to CF.

rdar://problem/34687542

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@314370 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExprObjC.cpp
test/CodeGenObjC/arc-bridged-cast.m

index 83ef799392aa96523457bec96cc469d2209568dc..93c982356540f0f44c814dcc1212bbd080274d58 100644 (file)
@@ -4322,7 +4322,7 @@ static Expr *maybeUndoReclaimObject(Expr *e) {
   // problems here.  To catch them all, we'd need to rebuild arbitrary
   // value-propagating subexpressions --- we can't reliably rebuild
   // in-place because of expression sharing.
-  if (ImplicitCastExpr *ice = dyn_cast<ImplicitCastExpr>(e))
+  if (auto *ice = dyn_cast<ImplicitCastExpr>(e->IgnoreParens()))
     if (ice->getCastKind() == CK_ARCReclaimReturnedObject)
       return ice->getSubExpr();
 
index 97a45c5a2f1090863db82f5be189902f4a785847..93f5d7ccaa3e610a808315508b1b80c09b29d3e6 100644 (file)
@@ -97,3 +97,10 @@ void bridge_of_cf(int *i) {
   // CHECK-NEXT: ret void
 }
 
+// CHECK-LABEL: define %struct.__CFString* @bridge_of_paren_expr()
+CFStringRef bridge_of_paren_expr() {
+  // CHECK-NOT: call i8* @objc_retainAutoreleasedReturnValue(
+  // CHECK-NOT: call void @objc_release(
+  CFStringRef r = (__bridge CFStringRef)(CreateNSString());
+  return r;
+}