[LLVMbugs] [Bug 13474] New: Feature request: warning for unnecessary __block keywords

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Jul 27 13:14:46 PDT 2012


             Bug #: 13474
           Summary: Feature request: warning for unnecessary __block
           Product: clang
           Version: 3.1
          Platform: Macintosh
        OS/Version: MacOS X
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: matt at upthere.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Since clang can detect variables that need to be annotated with the __block
keyword but are not, I was hoping the converse might be possible.

Specifically, consider:

#include <stdio.h>

int main(int argc, char **argv) {
    __block int i;
    for (i = 0; i < argc; i++) {
        printf("argv[%d] is %s\n", i, argv[i]);
    return 0;

Clang will happily compile this with -Wall -Wextra without a peep and will
generate code that allows 'i' to be used from a block (set-up extra state on
the stack and call Block_object_dispose()). Since there is a performance cost
in the emitted code, it would be nice if the compile could detect when __block
variables are not referenced from within a block and warn about it. Or,
alternatively, just optimize away the code for handling the block-ness. 

I am using:
Apple clang version 3.1 (tags/Apple/clang-318.0.61) (based on LLVM 3.1svn)
Target: x86_64-apple-darwin11.4.0
Thread model: posix

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.

More information about the llvm-bugs mailing list