[cfe-commits] [PATCH] Missing arithmetic conversions in vector operations

Eli Friedman eli.friedman at gmail.com
Thu Oct 27 19:41:08 PDT 2011


On Thu, Oct 27, 2011 at 7:02 PM, Richard Smith <richard at metafoo.co.uk> wrote:
> Hi,
>
> The attached patch moves the checking for vector operations after the usual
> arithmetic conversions are performed. This matters because:
>
>  * The OpenCL specification requires that we perform the usual arithmetic
> conversions on vectors (although it requires changes to the conversions
> themselves, which we do not yet implement).
>  * The lvalue-to-rvalue conversion on vector operands is otherwise missing in
> many cases (leading to problems with analysis passes, and soon with C++11
> constant evaluation).
>
> The patch adds both some tests and a new assert that ImpCastExprToType doesn't
> accidentally cast an lvalue to an rvalue; this assert fires on the new tests
> without the rest of the patch.
>
> I'm not very familiar with the vector handling code, so I'd appreciate someone
> looking over the patch and the approach to make sure that it's reasonable.
>
>
> One unit test changed behavior (for an ext_vector_type vector):
>
>  ish8 += 5; // expected-error {{...}}
>  ish8 += (short)5;
>
> We now reject the second line just like the first, since the short is promoted
> back to int before being assigned. However, according to the OpenCL
> specification (which I've been informed that ext_vector_type is supposed to
> support), both of these lines should be legal.

The test is correct as-is.  Try reading the section on usual
arithmetic conversions again.

Please just fix CheckVectorOperands to call
DefaultFunctionArrayLvalueConversion.

-Eli




More information about the cfe-commits mailing list