]> granicus.if.org Git - clang/commitdiff
[OpenCL] Improve diagnostics detecting implicit vector conversion.
authorAlexey Bader <aleksey.bader@mail.ru>
Sun, 30 Aug 2015 18:06:39 +0000 (18:06 +0000)
committerAlexey Bader <aleksey.bader@mail.ru>
Sun, 30 Aug 2015 18:06:39 +0000 (18:06 +0000)
Reviewers: pekka.jaaskelainen

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@246393 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaExpr.cpp
test/SemaOpenCL/cond.cl

index 7b21e1068c3d28bd7d3558fd5f30c9fc97b4ef5e..01fcc8714c4963eef67758e20489222f39109b2f 100644 (file)
@@ -7445,6 +7445,8 @@ def err_opencl_return_value_with_address_space : Error<
   "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 {
index 5297d7e26a4547520ab74ecee664a7d628ce03fb..58e2d2db6f993938299592781658982c6c27da02 100644 (file)
@@ -7534,6 +7534,18 @@ QualType Sema::CheckVectorOperands(ExprResult &LHS, ExprResult &RHS,
     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
index 2e93c318b44d70f0564fc8ea5135f0794a4c8c25..8cc4f1e8e9104a3272ea81a6d1ae176f181feb58 100644 (file)
@@ -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, global int *Y)
 
 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)