r246393 - [OpenCL] Improve diagnostics detecting implicit vector conversion.

Alexey Bader via cfe-commits cfe-commits at lists.llvm.org
Sun Aug 30 11:06:39 PDT 2015


Author: bader
Date: Sun Aug 30 13:06:39 2015
New Revision: 246393

URL: http://llvm.org/viewvc/llvm-project?rev=246393&view=rev
Log:
[OpenCL] Improve diagnostics detecting implicit vector conversion.

Reviewers: pekka.jaaskelainen

Differential Revision: http://reviews.llvm.org/D12470


Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/SemaOpenCL/cond.cl

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=246393&r1=246392&r2=246393&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sun Aug 30 13:06:39 2015
@@ -7445,6 +7445,8 @@ def err_opencl_return_value_with_address
   "return value cannot be qualified with address space">;
 def err_opencl_constant_no_init : Error<
   "variable in constant address space must be initialized">;
+def err_opencl_implicit_vector_conversion : Error<
+  "implicit conversions between vector types (%0 and %1) are not permitted">;
 } // end of sema category
 
 let CategoryName = "OpenMP Issue" in {

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=246393&r1=246392&r2=246393&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Sun Aug 30 13:06:39 2015
@@ -7534,6 +7534,18 @@ QualType Sema::CheckVectorOperands(ExprR
     return QualType();
   }
 
+  // OpenCL V1.1 6.2.6.p1:
+  // If the operands are of more than one vector type, then an error shall
+  // occur. Implicit conversions between vector types are not permitted, per
+  // section 6.2.1.
+  if (getLangOpts().OpenCL &&
+      RHSVecType && isa<ExtVectorType>(RHSVecType) &&
+      LHSVecType && isa<ExtVectorType>(LHSVecType)) {
+    Diag(Loc, diag::err_opencl_implicit_vector_conversion) << LHSType
+                                                           << RHSType;
+    return QualType();
+  }
+
   // Otherwise, use the generic diagnostic.
   Diag(Loc, diag::err_typecheck_vector_not_convertable)
     << LHSType << RHSType

Modified: cfe/trunk/test/SemaOpenCL/cond.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/cond.cl?rev=246393&r1=246392&r2=246393&view=diff
==============================================================================
--- cfe/trunk/test/SemaOpenCL/cond.cl (original)
+++ cfe/trunk/test/SemaOpenCL/cond.cl Sun Aug 30 13:06:39 2015
@@ -84,7 +84,7 @@ uchar2 ntest03(int2 C, uchar X, uchar Y)
 
 float2 ntest04(int2 C, int2 X, float2 Y)
 {
-  return C ? X : Y; // expected-error {{cannot convert between vector values of different size ('int2' (vector of 2 'int' values) and 'float2' (vector of 2 'float' values))}}
+  return C ? X : Y; // expected-error {{implicit conversions between vector types ('int2' (vector of 2 'int' values) and 'float2' (vector of 2 'float' values)) are not permitted}}
 }
 
 float2 ntest05(int2 C, int2 X, float Y)
@@ -115,7 +115,7 @@ int2 ntest09(int2 C, global int *X, glob
 
 char3 ntest10(char C, char3 X, char2 Y)
 {
-  return C ? X : Y; // expected-error {{cannot convert between vector values of different size ('char3' (vector of 3 'char' values) and 'char2' (vector of 2 'char' values))}}
+  return C ? X : Y; // expected-error {{implicit conversions between vector types ('char3' (vector of 3 'char' values) and 'char2' (vector of 2 'char' values)) are not permitted}}
 }
 
 char3 ntest11(char2 C, char3 X, char Y)




More information about the cfe-commits mailing list