Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 656eb5d

Browse files
committed
[ObjC][ARC] Honor noescape attribute for -Warc-retain-cycles
rdar://35409566 Differential Revision: https://reviews.llvm.org/D40141 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@318552 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 56e12b4 commit 656eb5d

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

lib/Sema/SemaChecking.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11652,9 +11652,15 @@ void Sema::checkRetainCycles(ObjCMessageExpr *msg) {
1165211652
}
1165311653

1165411654
// Check whether the receiver is captured by any of the arguments.
11655-
for (unsigned i = 0, e = msg->getNumArgs(); i != e; ++i)
11656-
if (Expr *capturer = findCapturingExpr(*this, msg->getArg(i), owner))
11655+
const ObjCMethodDecl *MD = msg->getMethodDecl();
11656+
for (unsigned i = 0, e = msg->getNumArgs(); i != e; ++i) {
11657+
if (Expr *capturer = findCapturingExpr(*this, msg->getArg(i), owner)) {
11658+
// noescape blocks should not be retained by the method.
11659+
if (MD && MD->parameters()[i]->hasAttr<NoEscapeAttr>())
11660+
continue;
1165711661
return diagnoseRetainCycle(*this, capturer, owner);
11662+
}
11663+
}
1165811664
}
1165911665

1166011666
/// Check a property assign to see if it's likely to cause a retain cycle.

test/SemaObjC/warn-retain-cycle.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,3 +198,15 @@ __block void(^myBlock)(void) = ^{
198198
};
199199

200200
}
201+
202+
typedef void (^a_block_t)(void);
203+
204+
@interface HonorNoEscape
205+
- (void)addStuffUsingBlock:(__attribute__((noescape)) a_block_t)block;
206+
@end
207+
208+
void testNoEscape(HonorNoEscape *obj) {
209+
[obj addStuffUsingBlock:^{
210+
(void)obj; // ok.
211+
}];
212+
}

0 commit comments

Comments
 (0)