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

Richard Smith richard at metafoo.co.uk
Thu Oct 27 19:02:43 PDT 2011


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 right fix for this would
seem to be to implement the OpenCL rules for the usual arithmetic conversions.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: vector-conversion.diff
Type: text/x-patch
Size: 14275 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20111028/c59d0bab/attachment.bin>

More information about the cfe-commits mailing list