Looks pretty simple: I just check for extended vectors of integral
elements to accept (non-integral vectors fail).  Patch includes
modifications to Sema/SemaExpr.cpp and adds a new test file
SemaOpenCL/vector_ops.cl with test cases.  Any feedback on this?

Regards,
--John Stratton
Index: test/SemaOpenCL/vector_ops.cl
===================================================================
--- test/SemaOpenCL/vector_ops.cl	(revision 0)
+++ test/SemaOpenCL/vector_ops.cl	(revision 0)
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -verify %s
+
+typedef unsigned int uint4 __attribute((ext_vector_type(4)));
+typedef int int4 __attribute((ext_vector_type(4)));
+typedef int int3 __attribute((ext_vector_type(3)));
+typedef unsigned uint3 __attribute((ext_vector_type(3)));
+
+void vector_conv_invalid() {
+  uint4 u = (uint4)(1);
+  int4 i = u; // expected-error{{initializing 'int4' with an expression of incompatible type 'uint4'}}
+  int4 e = (int4)u; // expected-error{{invalid conversion between ext-vector type 'int4' and 'uint4'}}
+
+  uint3 u4 = (uint3)u; // expected-error{{invalid conversion between ext-vector type 'uint3' and 'uint4'}}
+}
Index: lib/Sema/SemaExpr.cpp
===================================================================
--- lib/Sema/SemaExpr.cpp	(revision 179744)
+++ lib/Sema/SemaExpr.cpp	(working copy)
@@ -8143,6 +8143,15 @@
                                           IsInc, IsPrefix);
   } else if (S.getLangOpts().AltiVec && ResType->isVectorType()) {
     // OK! ( C/C++ Language Extensions for CBEA(Version 2.6) 10.3 )
+  } else if (ResType->isExtVectorType()) {
+    // Only integral ext vector types are OK
+    // ( OpenCL Language Specification (Version 1.1) 6.3.c )
+    QualType EltType = ResType->getAs<ExtVectorType>()->getElementType();
+    if (!EltType->isIntegralType(S.getASTContext())) {
+      S.Diag(OpLoc, diag::err_typecheck_illegal_increment_decrement)
+        << ResType << int(IsInc) << Op->getSourceRange();
+      return QualType();
+    }
   } else {
     S.Diag(OpLoc, diag::err_typecheck_illegal_increment_decrement)
       << ResType << int(IsInc) << Op->getSourceRange();
_______________________________________________
cfe-commits mailing list
cfe-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to