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

steve naroff snaroff at apple.com
Thu Oct 2 19:05:33 PDT 2008


On Oct 2, 2008, at 9:01 PM, Eli Friedman wrote:

> 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*.
>

You're right. As the comment states, I simply want to allow block  
(literal) expressions at file scope.

> 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.
>

No rush at all. For now, I just need it to pass through without Sema  
barfing on it.

> 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); };
> }
>

Understood. There are definitely more semantic checks that can/should  
be done.

At the moment, I'm focusing on the blocks rewriter...

Thanks for reviewing,

snaroff

> -Eli




More information about the cfe-commits mailing list