[cfe-dev] Casting scalars to vectors

John Thompson john.thompson.jtsoftware at gmail.com
Tue Apr 20 16:30:15 PDT 2010


I've run into a problem with vector literal/casting confusion:

vector float v = (vector float)((vector unsigned int)(0x49800000));
vecinit1.cpp:1:33: error: cannot initialize a vector element of type 'float'
with an lvalue of type '__vector unsigned int'
vector float v = (vector float)((vector unsigned int)(0x49800000));
It appears to be treating the outer paren expression as a vector literal
instead of a cast.

I'm looking into to it, but if someone knows a quick fix already...
-John

On Tue, Apr 20, 2010 at 12:45 PM, John Thompson <
john.thompson.jtsoftware at gmail.com> wrote:

> Anton,
>
> Clang was generating an error on vector initializers, when all the vector
> slots are not provided, i.e.:
>
> vector unsigned int v = (vector unsigned int)(vector int)(-1);
>
> Instead of:
>
> vector unsigned int v = (vector unsigned int)(vector int)(-1, -1, -1, -1);
>
> I'm seeing these kinds of statements in some headers in the PS3 sdk, which
> gcc allows.
>
> I've checked in a fix and revised the altivec tests.  (Sorry I missed a
> test last night, and broke the build.)
>
> I have a question, though (for Anton or anyone).  What will the
> initializers be for the unspecified slots?  Will they be 0?  What does gcc
> do?
>
> -John
>   On Tue, Apr 20, 2010 at 2:34 AM, Anton Lokhmotov <
> Anton.Lokhmotov at arm.com> wrote:
>
>> > This stops the error, but is it enough?
>>
>> Sorry, I couldn't understand from the thread what was the error?
>>
>> > -      if (SemaRef.getLangOptions().OpenCL ||
>> SemaRef.getLangOptions().AltiVec)
>> > +      if (SemaRef.getLangOptions().OpenCL)
>>
>> In other words, it's something that's not required for AltiVec but is
>> required for OpenCL?
>>
>> Cheers,
>> Anton.
>>
>>
>>
>
>
> --
>  John Thompson
> John.Thompson.JTSoftware at gmail.com
>
>


-- 
John Thompson
John.Thompson.JTSoftware at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20100420/9d47e30e/attachment.html>


More information about the cfe-dev mailing list