Author: grosser Date: Thu Sep 22 08:03:14 2011 New Revision: 140300 URL: http://llvm.org/viewvc/llvm-project?rev=140300&view=rev Log: In OpenCL, conversions between different vector types are disallowed
OpenCL 6.2.1 says: "Implicit conversions between built-in vector data types are disallowed." OpenCL 6.2.2 says: "Explicit casts between vector types are not legal." For example: uint4 u = (uint4)(1); int4 i = u; // invalid implicit conversion int4 e = (int4)u; // invalid explicit conversion Fixes PR10967. Submitted by: Anton Lokhmotov <[email protected]> Added: cfe/trunk/test/SemaOpenCL/vector_conv_invalid.cl Modified: cfe/trunk/lib/Sema/SemaExpr.cpp Modified: cfe/trunk/lib/Sema/SemaExpr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=140300&r1=140299&r2=140300&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaExpr.cpp (original) +++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Sep 22 08:03:14 2011 @@ -4194,8 +4194,12 @@ // If SrcTy is a VectorType, the total size must match to explicitly cast to // an ExtVectorType. + // In OpenCL, casts between vectors of different types are not allowed. + // (See OpenCL 6.2). if (SrcTy->isVectorType()) { - if (Context.getTypeSize(DestTy) != Context.getTypeSize(SrcTy)) { + if (Context.getTypeSize(DestTy) != Context.getTypeSize(SrcTy) + || (getLangOptions().OpenCL && + (DestTy.getCanonicalType() != SrcTy.getCanonicalType()))) { Diag(R.getBegin(),diag::err_invalid_conversion_between_ext_vectors) << DestTy << SrcTy << R; return ExprError(); Added: cfe/trunk/test/SemaOpenCL/vector_conv_invalid.cl URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/vector_conv_invalid.cl?rev=140300&view=auto ============================================================================== --- cfe/trunk/test/SemaOpenCL/vector_conv_invalid.cl (added) +++ cfe/trunk/test/SemaOpenCL/vector_conv_invalid.cl Thu Sep 22 08:03:14 2011 @@ -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'}} +} _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
