[cfe-commits] r64994 - in /cfe/trunk/lib: AST/ExprConstant.cpp CodeGen/CGBlocks.cpp CodeGen/CGExprConstant.cpp CodeGen/CGExprScalar.cpp CodeGen/CodeGenModule.h
Fariborz Jahanian
fjahanian at apple.com
Thu Feb 19 09:08:09 PST 2009
On Feb 18, 2009, at 7:41 PM, Eli Friedman wrote:
> On Wed, Feb 18, 2009 at 7:22 PM, Mike Stump <mrs at apple.com> wrote:
>> On Feb 18, 2009, at 7:12 PM, Eli Friedman wrote:
>>>
>>> On Wed, Feb 18, 2009 at 5:01 PM, Mike Stump <mrs at apple.com> wrote:
>>>>
>>>> --- cfe/trunk/lib/AST/ExprConstant.cpp (original)
>>>> +++ cfe/trunk/lib/AST/ExprConstant.cpp Wed Feb 18 19:01:04 2009
>>>> @@ -260,6 +260,7 @@
>>>> APValue VisitAddrLabelExpr(AddrLabelExpr *E)
>>>> { return APValue(E, 0); }
>>>> APValue VisitCallExpr(CallExpr *E);
>>>> + APValue VisitBlockExpr(BlockExpr *E) { return APValue(E, 0); }
>>>
>>> Aren't there some missing checks here?
>>
>> Work in progress. There is all sorts of checking, semantics and
>> codegen
>> missing.
>
> That's fine, but it would be nice to at least put in a FIXME for the
> missing checks.
>
>>> Block expressions can't possibly be constant in general.
>>
>> They are?! That is why they are called block literal expressions.
>> In the
>> same way that 1 is a literal and unchanging, ^{} is a literal,
>> constant and
>> unchanging. Now, I could easily have it wrong, it you could point
>> out the
>> part you thought would vary, I can contemplate it.
>
> Hmm, I might be confused about something, but take something like the
> following (I haven't checked if this particular example compiles, but
> this sort of thing is legal):
> int a(int x) {
> static int (^y)(void) = ^{x;};
> return y();
> }
Above is illegal, as you are importing a local variable in a static
block. gcc complains
(which of course can be improved ):
% cat t.c
int a(int x) {
static int (^y)(void) = ^{return x;};
return y();
}
% !gcc
gcc -c t.c
t.c: In function 'a':
t.c:2: error: initializer element is not constant
But local blocks are fine because they are allocated on the stack and
the argument
is passed by value.
- fariborz
>
>
> This initializer for y must be illegal because it can't be evaluated
> at compile-time: the returned value changes! Therefore, blocks aren't
> constant in the general case.
>
> I believe that file-scope block expressions are constant, but you need
> some way to check that; the use of isFileScope for compund literals
> would be a good example to follow.
>
> -Eli
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list