[cfe-dev] [OpenCL patch] Vector literals are rvalues *updated*

John McCall rjmccall at apple.com
Fri Sep 23 11:51:44 PDT 2011


On Sep 23, 2011, at 8:55 AM, Anton Lokhmotov wrote:
> Many thanks for prompt reviews!
> 
> On Sep 21, 2011, at 7:30 AM, Peter Collingbourne wrote:
> 
>> What about compound literals which are not of vector type?  
>> The OpenCL specification is silent on these, which means we 
>> should defer to C99, which states that they are lvalues.
> 
> I personally think it's a sad omission, because I can't imagine why one
> would want to take the address of a compound literal of any type (e.g. C++
> forbids it).

Well, for example, you can pass the address of a compound literal to a
function which takes a struct by pointer.

Anyway, C99 is quite clear about compound literals being l-values,
and we're not going to unilaterally change that.

> On Sep 21, 2011, at 10:01 AM, John McCall wrote:
>> Right.  Ideally, this should just apply to OpenCL vector literals,
>> i.e. this should be an r-value:
>>  (int4) (3,2,1,0)
>> and this should be an l-value:
>>  (int4) {3,2,1,0}
> 
> On 22 September 2011 00:57, Tanya Lattner wrote:
>> Agreed. If you can have it apply only for OpenCL vector literals, 
>> then it looks good to me.
> 
> Unfortunately, we can't, as these two forms are indistinguishable in the
> AST.  (Strictly speaking, only the first form is valid in OpenCL, but as we
> discussed [1] we should permit the second one as well.)

Two forms being indistinguishable in the AST is theoretically solvable.
But more importantly, it is quite easy to distinguish them here, because
Sema has just done the AST transformation itself.

John.



More information about the cfe-dev mailing list