[PATCH] D38463: [OpenCL] Fix checking of vector type casting

2017-10-03 Thread Yaxun Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL314802: [OpenCL] Fix checking of vector type casting 
(authored by yaxunl).

Changed prior to commit:
  https://reviews.llvm.org/D38463?vs=117357=117524#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D38463

Files:
  cfe/trunk/lib/Sema/SemaExpr.cpp
  cfe/trunk/test/SemaOpenCL/vector_conv_invalid.cl


Index: cfe/trunk/test/SemaOpenCL/vector_conv_invalid.cl
===
--- cfe/trunk/test/SemaOpenCL/vector_conv_invalid.cl
+++ cfe/trunk/test/SemaOpenCL/vector_conv_invalid.cl
@@ -5,10 +5,18 @@
 typedef int int3 __attribute((ext_vector_type(3)));
 typedef unsigned uint3 __attribute((ext_vector_type(3)));
 
-void vector_conv_invalid() {
+void vector_conv_invalid(const global int4 *const_global_ptr) {
   uint4 u = (uint4)(1);
   int4 i = u; // expected-error{{initializing 'int4' (vector of 4 'int' 
values) with an expression of incompatible type 'uint4' (vector of 4 'unsigned 
int' values)}}
   int4 e = (int4)u; // expected-error{{invalid conversion between ext-vector 
type 'int4' (vector of 4 'int' values) and 'uint4' (vector of 4 'unsigned int' 
values)}}
 
   uint3 u4 = (uint3)u; // expected-error{{invalid conversion between 
ext-vector type 'uint3' (vector of 3 'unsigned int' values) and 'uint4' (vector 
of 4 'unsigned int' values)}}
+
+  e = (const int4)i;
+  e = (constant int4)i;
+  e = (private int4)i;
+
+  private int4 *private_ptr = (const private int4 *)const_global_ptr; // 
expected-error{{casting 'const __global int4 *' to type 'const int4 *' changes 
address space of pointer}}
+  global int4 *global_ptr = const_global_ptr; // 
expected-warning {{initializing '__global int4 *' with an expression of type 
'const __global int4 *' discards qualifiers}}
+  global_ptr = (global int4 *)const_global_ptr;
 }
Index: cfe/trunk/lib/Sema/SemaExpr.cpp
===
--- cfe/trunk/lib/Sema/SemaExpr.cpp
+++ cfe/trunk/lib/Sema/SemaExpr.cpp
@@ -6033,9 +6033,9 @@
   // In OpenCL, casts between vectors of different types are not allowed.
   // (See OpenCL 6.2).
   if (SrcTy->isVectorType()) {
-if (!areLaxCompatibleVectorTypes(SrcTy, DestTy)
-|| (getLangOpts().OpenCL &&
-(DestTy.getCanonicalType() != SrcTy.getCanonicalType( {
+if (!areLaxCompatibleVectorTypes(SrcTy, DestTy) ||
+(getLangOpts().OpenCL &&
+ !Context.hasSameUnqualifiedType(DestTy, SrcTy))) {
   Diag(R.getBegin(),diag::err_invalid_conversion_between_ext_vectors)
 << DestTy << SrcTy << R;
   return ExprError();


Index: cfe/trunk/test/SemaOpenCL/vector_conv_invalid.cl
===
--- cfe/trunk/test/SemaOpenCL/vector_conv_invalid.cl
+++ cfe/trunk/test/SemaOpenCL/vector_conv_invalid.cl
@@ -5,10 +5,18 @@
 typedef int int3 __attribute((ext_vector_type(3)));
 typedef unsigned uint3 __attribute((ext_vector_type(3)));
 
-void vector_conv_invalid() {
+void vector_conv_invalid(const global int4 *const_global_ptr) {
   uint4 u = (uint4)(1);
   int4 i = u; // expected-error{{initializing 'int4' (vector of 4 'int' values) with an expression of incompatible type 'uint4' (vector of 4 'unsigned int' values)}}
   int4 e = (int4)u; // expected-error{{invalid conversion between ext-vector type 'int4' (vector of 4 'int' values) and 'uint4' (vector of 4 'unsigned int' values)}}
 
   uint3 u4 = (uint3)u; // expected-error{{invalid conversion between ext-vector type 'uint3' (vector of 3 'unsigned int' values) and 'uint4' (vector of 4 'unsigned int' values)}}
+
+  e = (const int4)i;
+  e = (constant int4)i;
+  e = (private int4)i;
+
+  private int4 *private_ptr = (const private int4 *)const_global_ptr; // expected-error{{casting 'const __global int4 *' to type 'const int4 *' changes address space of pointer}}
+  global int4 *global_ptr = const_global_ptr; // expected-warning {{initializing '__global int4 *' with an expression of type 'const __global int4 *' discards qualifiers}}
+  global_ptr = (global int4 *)const_global_ptr;
 }
Index: cfe/trunk/lib/Sema/SemaExpr.cpp
===
--- cfe/trunk/lib/Sema/SemaExpr.cpp
+++ cfe/trunk/lib/Sema/SemaExpr.cpp
@@ -6033,9 +6033,9 @@
   // In OpenCL, casts between vectors of different types are not allowed.
   // (See OpenCL 6.2).
   if (SrcTy->isVectorType()) {
-if (!areLaxCompatibleVectorTypes(SrcTy, DestTy)
-|| (getLangOpts().OpenCL &&
-(DestTy.getCanonicalType() != SrcTy.getCanonicalType( {
+if (!areLaxCompatibleVectorTypes(SrcTy, DestTy) ||
+(getLangOpts().OpenCL &&
+ !Context.hasSameUnqualifiedType(DestTy, SrcTy))) {
   Diag(R.getBegin(),diag::err_invalid_conversion_between_ext_vectors)
 << DestTy << SrcTy << R;
   return ExprError();

[PATCH] D38463: [OpenCL] Fix checking of vector type casting

2017-10-03 Thread Alexey Bader via Phabricator via cfe-commits
bader accepted this revision.
bader added a comment.
This revision is now accepted and ready to land.

LGTM.


https://reviews.llvm.org/D38463



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D38463: [OpenCL] Fix checking of vector type casting

2017-10-02 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.

Currently clang allows the following code

  int a;
  int b = (const int) a;

However it does not the following code

  int4 a;
  int4 b = (const int4) a;

This is because Clang compares the qualified types instead of unqualified types 
for vector type casting, which causes the inconsistency.

This patch fixes that.


https://reviews.llvm.org/D38463

Files:
  lib/Sema/SemaExpr.cpp
  test/SemaOpenCL/vector_conv_invalid.cl


Index: test/SemaOpenCL/vector_conv_invalid.cl
===
--- test/SemaOpenCL/vector_conv_invalid.cl
+++ test/SemaOpenCL/vector_conv_invalid.cl
@@ -5,10 +5,18 @@
 typedef int int3 __attribute((ext_vector_type(3)));
 typedef unsigned uint3 __attribute((ext_vector_type(3)));
 
-void vector_conv_invalid() {
+void vector_conv_invalid(const global int4 *const_global_ptr) {
   uint4 u = (uint4)(1);
   int4 i = u; // expected-error{{initializing 'int4' (vector of 4 'int' 
values) with an expression of incompatible type 'uint4' (vector of 4 'unsigned 
int' values)}}
   int4 e = (int4)u; // expected-error{{invalid conversion between ext-vector 
type 'int4' (vector of 4 'int' values) and 'uint4' (vector of 4 'unsigned int' 
values)}}
 
   uint3 u4 = (uint3)u; // expected-error{{invalid conversion between 
ext-vector type 'uint3' (vector of 3 'unsigned int' values) and 'uint4' (vector 
of 4 'unsigned int' values)}}
+
+  e = (const int4)i;
+  e = (constant int4)i;
+  e = (private int4)i;
+
+  private int4 *private_ptr = (const private int4 *)const_global_ptr; // 
expected-error{{casting 'const __global int4 *' to type 'const int4 *' changes 
address space of pointer}}
+  global int4 *global_ptr = const_global_ptr; // 
expected-warning {{initializing '__global int4 *' with an expression of type 
'const __global int4 *' discards qualifiers}}
+  global_ptr = (global int4 *)const_global_ptr;
 }
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -6033,9 +6033,9 @@
   // In OpenCL, casts between vectors of different types are not allowed.
   // (See OpenCL 6.2).
   if (SrcTy->isVectorType()) {
-if (!areLaxCompatibleVectorTypes(SrcTy, DestTy)
-|| (getLangOpts().OpenCL &&
-(DestTy.getCanonicalType() != SrcTy.getCanonicalType( {
+if (!areLaxCompatibleVectorTypes(SrcTy, DestTy) ||
+(getLangOpts().OpenCL &&
+ !Context.hasSameUnqualifiedType(DestTy, SrcTy))) {
   Diag(R.getBegin(),diag::err_invalid_conversion_between_ext_vectors)
 << DestTy << SrcTy << R;
   return ExprError();


Index: test/SemaOpenCL/vector_conv_invalid.cl
===
--- test/SemaOpenCL/vector_conv_invalid.cl
+++ test/SemaOpenCL/vector_conv_invalid.cl
@@ -5,10 +5,18 @@
 typedef int int3 __attribute((ext_vector_type(3)));
 typedef unsigned uint3 __attribute((ext_vector_type(3)));
 
-void vector_conv_invalid() {
+void vector_conv_invalid(const global int4 *const_global_ptr) {
   uint4 u = (uint4)(1);
   int4 i = u; // expected-error{{initializing 'int4' (vector of 4 'int' values) with an expression of incompatible type 'uint4' (vector of 4 'unsigned int' values)}}
   int4 e = (int4)u; // expected-error{{invalid conversion between ext-vector type 'int4' (vector of 4 'int' values) and 'uint4' (vector of 4 'unsigned int' values)}}
 
   uint3 u4 = (uint3)u; // expected-error{{invalid conversion between ext-vector type 'uint3' (vector of 3 'unsigned int' values) and 'uint4' (vector of 4 'unsigned int' values)}}
+
+  e = (const int4)i;
+  e = (constant int4)i;
+  e = (private int4)i;
+
+  private int4 *private_ptr = (const private int4 *)const_global_ptr; // expected-error{{casting 'const __global int4 *' to type 'const int4 *' changes address space of pointer}}
+  global int4 *global_ptr = const_global_ptr; // expected-warning {{initializing '__global int4 *' with an expression of type 'const __global int4 *' discards qualifiers}}
+  global_ptr = (global int4 *)const_global_ptr;
 }
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -6033,9 +6033,9 @@
   // In OpenCL, casts between vectors of different types are not allowed.
   // (See OpenCL 6.2).
   if (SrcTy->isVectorType()) {
-if (!areLaxCompatibleVectorTypes(SrcTy, DestTy)
-|| (getLangOpts().OpenCL &&
-(DestTy.getCanonicalType() != SrcTy.getCanonicalType( {
+if (!areLaxCompatibleVectorTypes(SrcTy, DestTy) ||
+(getLangOpts().OpenCL &&
+ !Context.hasSameUnqualifiedType(DestTy, SrcTy))) {
   Diag(R.getBegin(),diag::err_invalid_conversion_between_ext_vectors)
 << DestTy << SrcTy << R;
   return ExprError();
___
cfe-commits mailing list