<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Hi Michaël,<div><br></div><div>If your interest is replicating the current behavior of -Warc-retain-cycles for methods that do not begin with “add” and “set”, then annotations seem like a reasonable ground for experimentation. We’ve done this before with the static analyzer, where it first started with a list of heuristics for identifying methods with specific memory management behavior and then added compiler support for annotations to increase that knowledge base by encoding it in the source code itself. Similarly, having annotations here would be useful, and they could also be useful to disable the builtin heuristic. Such annotations would need to go through design of course, but that could be done via proposing patches and looking at the proposed behavior.</div><div><br></div><div>If your interest is to expand the current functionality, that’s a little more involved as it entails more design. Annotations are a small form of language design, and when we add them we need to consider them carefully.</div><div><br></div><div>Ted</div><div><div><br><div><div>On Oct 14, 2013, at 5:31 PM, Michaël Fortin <<a href="mailto:fortinmike@gmail.com">fortinmike@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><meta http-equiv="Content-Type" content="text/html charset=windows-1252"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Hi there,</div><div class=""><br class=""></div><div class="">I’m new to this mailing list, so let me begin by saying a big thank you to all of the devs working on llvm-clang! The enhancements that were made to Objective-C in the last few years (among other thinks) thanks to your work make our lives much easier.</div><div class=""><br class=""></div><div class="">Now for the actual business: I would like to know if there is currently a way to benefit from the "arc-retain-cycles" warning (Objective-C) for methods that do not begin with “add” and “set”. I’ve checked out the clang source to validate my theory (i.e. that only methods prefixed with “add” and “set” benefit from the check, since I didn’t see any special annotation on the declarations of methods that generated this warning) and from what I’ve seen I was correct (relevant code: SemaChecking.cpp:6634 and the implementation of isSetterLikeSelector() just above that).</div><div class=""><br class=""></div><div class="">I am implementing a few methods in a library that take block arguments and store them for later, repeated execution. However, those methods do not benefit from the arc-retain-cycles warning and it’s pretty easy to create a retain cycle by accident, particularly for novice Objective-C devs. I would like to annotate the methods I know can lead to cycles for inclusion in this check to save others (and myself) from introducing leaks in the future.</div><div class=""><br class=""></div><div class="">If there is a way to do that, I’d love to know how. Else, I’m proposing adding an Objective-C-specific attribute (if that’s the appropriate construct) to indicate that a method’s usages should be checked for potential retain cycles without requiring the method to begin with “add” or “set". Something like:</div><div class=""><br class=""></div><div class="">- (void)doSomethingWithObject:(id)anObject andBlock:(void (^)())aBlock <b class="">__attribute__((check_retain_cycles))</b>;</div><div class=""><br></div><div class="">In addition, it would probably be nice to offer the complementary ability to exclude some “add” and “set”-prefixed methods from the retain cycle check if we know it’s not relevant in a specific case, like the NSOperationQueue “addOperationWithBlock” exclusion that’s currently hard-coded in the isSetterLikeSelector() function (SemaChecking.cpp:6620) but in a dynamic way using an attribute:</div><div class=""><br></div><div class="">- (void)addOperationWithBlock:(void (^)(void))block <b>__attribute__((dont_</b><span class="" style="font-weight: bold;">check_retain_cycles</span><b>))</b>;</div><div class=""><br></div><div class="">What do you think?</div><div class=""><br class=""></div><div class="">Best regards,</div><br class=""><div apple-content-edited="true" class="">
<span style="border-collapse: separate; border-spacing: 0px;" class="Apple-style-span"><span style="border-collapse: separate; font-family: Helvetica; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; border-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;" class="Apple-style-span"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span style="border-collapse: separate; font-family: Helvetica; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; border-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;" class="Apple-style-span"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span style="border-collapse: separate; font-family: Helvetica; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; border-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;" class="Apple-style-span"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span style="border-collapse: separate; font-family: Helvetica; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; border-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;" class="Apple-style-span"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Michaël Fortin</div></span></div></span></div></span></div></span></span></div></div>_______________________________________________<br>cfe-dev mailing list<br><a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev<br></blockquote></div><br></div></div></body></html>