[cfe-dev] OpenCL patch: vector literals

John McCall rjmccall at apple.com
Thu Jul 7 11:36:15 PDT 2011


On Jul 7, 2011, at 11:05 AM, Tanya Lattner wrote:
> On Jul 7, 2011, at 8:17 AM, Anton Lokhmotov wrote:
>>> Yes, you are 100% right that the test violates the OpenCL spec 
>>> (my mistake and haste in making a patch), but its catching a nasty
>>> compiler crash and I'd rather try to modify the test instead of just
>>> removing it. I've fixed this in TOT.
>> 
>> Unfortunately,
>> 
>> void foo( uchar8 x )
>> {
>> uchar4 val[4] = {{(uchar4){x.lo}}};
>> }
>> 
>> is still invalid in OpenCL C.  In particular, OpenCL doesn't allow using
>> braces {} in vector literals.
>> 
> 
> Well, its an array of uchar4's. So its using {} to initialize the array. Can you point me to where in the spec it says I can't do this?
> I'm not familiar with this rule.

I don't know what the base language for OpenCL is supposed to be, but this is C99 compound literal syntax, and:

  [C99 6.5.2.5] All the semantic rules and constraints for initializer lists in 6.7.8 are applicable to compound literals.

So this should be legal if C99 is an acceptable base language for OpenCL and the following is valid:
  uchar4 vec = { x.lo };


>> [Actually, I'm quite confused by this test.  Since x.lo produces uchar4, the
>> cast is superfluous?  And then it attempts to initialize an array of vectors
>> val[] from vector x.lo.  But I actually would expect only val[0] to be
>> initialized (backed by my experiments with gcc).

When an aggregate has any initializer at all, missing elements are implicitly
zero-initialized.

John.



More information about the cfe-dev mailing list