http://llvm.org/bugs/show_bug.cgi?id=11187

           Summary: Add checks that completionHandlers are called
           Product: clang
           Version: 2.8
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Static Analyzer
        AssignedTo: [email protected]
        ReportedBy: [email protected]
                CC: [email protected]


Several Cocoa APIs now take completion handler blocks and failure to call those
completion handlers results in hard to debug errors and deadlocks.

clang-sa could have an annotation on block arguments (say
"__attribute__((must_call))" for the sake of argument) and it could
automatically apply that if the block argument or method name fragment is
called 'completionHandler'.

For example:

- (void)doSomethingAsync:(void (^)(void))completionHandler;
{
    if (!thing1Works) {
        if (completionHandler)
            completionHandler(); // OK
        return;
    }

    return; // diagnostic since the completionHandler wasn't called
}

This would need to handle the pattern where the completionHandler is destined
to be invoked on another queue:

- (void)doSomethingAsync:(void (^)(NSError *errorOrNil))completionHandler;
{
    NSError *error;

    ... do some stuff ...

    if (completionHandler) {
        [[NSOperationQueue mainQueue] addOperationWithBlock:^{
            completionHandler(error);
        }];
    }
}

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to