llvm-gcc fails to recognize __block keywords

Bug #483679 reported by Mario Schwalbe
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
llvm-gcc-4.2 (Ubuntu)
New
Undecided
Unassigned

Bug Description

Binary package hint: llvm-gcc-4.2

the following source code:

#include <stdio.h>

int main(void)
{
    printf("Hello World!\n");

#ifdef __BLOCKS__
    int closed = 1;
    __block int open = 2;
    //int open = 2;

    void (^print)(int) = ^(int n)
    {
        printf("%d %d %d\n", closed, open, n);
    };

    closed = 3;
    open = 4;

    print(5); // prints 1 4 5
#endif

    return 0;
}

compiled with:

/usr/lib/llvm/llvm/gcc-4.2/bin/llvm-gcc -fblocks blocks.c

causes:

blocks.c: In function 'main':
blocks.c:9: error: '__block' undeclared (first use in this function)
blocks.c:9: error: (Each undeclared identifier is reported only once
blocks.c:9: error: for each function it appears in.)
blocks.c:9: error: expected ';' before 'int'
blocks.c: In function '__main_block_invoke_1':
blocks.c:13: error: 'open' undeclared (first use in this function)
blocks.c: In function 'main':
blocks.c:17: error: 'open' undeclared (first use in this function)

after removing the __block keyword, compilation succeeds. (links and runs fine as well
after manually compiling the blocks runtime library.)

for reference:

> /usr/lib/llvm/llvm/gcc-4.2/bin/llvm-gcc --version
llvm-gcc (GCC) 4.2.1 (Based on Apple Inc. build 5649) (LLVM build)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

> apt-cache policy llvm-gcc-4.2
llvm-gcc-4.2:
  Installed: 2.6~pre1-0ubuntu1
  Candidate: 2.6~pre1-0ubuntu1
  Version table:
 *** 2.6~pre1-0ubuntu1 0
        500 http://de.archive.ubuntu.com karmic/universe Packages
        100 /var/lib/dpkg/status

Revision history for this message
Mario Schwalbe (schwalbe) wrote :

looking at the LLVM/Clang documentation (http://clang.llvm.org/doxygen/InitPreprocessor_8cpp-source.html) shows that __block is not actually a keyword, but a macro that is defined to be __attribute__((__blocks__(byref))).
so adding:

#ifndef __block
    #define __block __attribute__((__blocks__(byref)))
#endif

to the above example works.

btw: this also happens if using a self-compiled upstream LLVM/GCC, so it's not actually an Ubuntu bug.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.