[PATCH] D24472: [Sema] Support lax conversions for compound assignments

Bruno Cardoso Lopes via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 23 14:50:05 PDT 2016

bruno added inline comments.

Comment at: lib/Sema/SemaExpr.cpp:8090
@@ +8089,3 @@
+      *RHSExpr = ImpCastExprToType(RHSExpr->get(), LHSType, CK_BitCast);
+      return VecType;
+    }
ahatanak wrote:
> Sorry I wasn't clear, but I was asking whether you were planning to  allow the following conversions for compound statements.
> ```
> typedef short s4 __attribute__ ((vector_size(8)));
> typedef int i2 __attribute__ ((vector_size(8)));
> s4 a;
> i2 b;
> a = a + b; // clang accepts this.
> a += b; // currently clang rejects this.
> ```
> Also, I feel clang is inconsistent in warning about incompatible types. In the following example, it issues a warning for the first line, but is silent about the second line:
> ```
> a = b + a; // incompatible vector types warning
> a = a + b; // no warning
> ```
> I don't think we have to fix everything in this patch, but just wanted to know what your thoughts were.
You're right, the diagnostics are bad here, this patch adds some FIXMEs so we can later work on it. A PR would be nice though (we have an internal track for that as well, see rdar://problem/28067874).

Given your example:

  a = a + b; // clang accepts this. 
  a += b; // currently clang rejects this.

IMO, clang should reject `a = a + b` too if not in OpenCL mode, which means whenever (a) `a` and `b` have same size but different num elt and (b) `a` and `b` are generic vectors (non ext-vectors). However, It looks like we have tests that rely on this behavior, we should probably find out why first and clean it up.

I also think we should support splatting when one of the operands is a scalar and the other a non ext-vector (as of now we currently only do it for OpenCL). This is basically what GCC supports https://gcc.gnu.org/onlinedocs/gcc/Vector-Extensions.html.


More information about the cfe-commits mailing list