[cfe-commits] r56955 - in /cfe/trunk: Driver/RewriteBlocks.cpp lib/Sema/SemaDecl.cpp test/Sema/block-literal.c

Eli Friedman eli.friedman at gmail.com
Thu Oct 2 18:01:40 PDT 2008


On Thu, Oct 2, 2008 at 10:12 AM, Steve Naroff <snaroff at apple.com> wrote:
==============================================================================
> --- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Oct  2 12:12:56 2008
> @@ -1286,6 +1286,10 @@
>   if (Init->getType()->isFunctionType())
>     return false;
>
> +  // Allow block exprs at top level.
> +  if (Init->getType()->isBlockPointerType())
> +    return false;
> +

This isn't right; if I'm not mistaken, this will let through anything
with a block pointer type, even if isn't constant, and it will
disallow thing like a block expr cast to a void*.

I'm a bit too tired right now to figure out exactly what the correct
fix is.  Probably block pointers should be sent through
CheckAddressConstantExpression.

Oh, and also, we probably need some more checks on the block itself;
we don't want to allow the following:
int a(int arg_x) {
static void (^global_block)(void) = ^{ printf("arg x is %d\n", arg_x); };
}

-Eli



More information about the cfe-commits mailing list