Index: clang/lib/Sema/SemaCast.cpp =================================================================== --- clang/lib/Sema/SemaCast.cpp +++ clang/lib/Sema/SemaCast.cpp @@ -2356,7 +2356,7 @@ return TC_Failed; } - if (SrcType == DestType) { + if (SrcType == Self.Context.removeAddrSpaceQualType(DestType)) { // C++ 5.2.10p2 has a note that mentions that, subject to all other // restrictions, a cast to the same type is allowed so long as it does not // cast away constness. In C++98, the intent was not entirely clear here, Index: clang/test/CodeGenOpenCLCXX/reinterpret_cast.clcpp =================================================================== --- clang/test/CodeGenOpenCLCXX/reinterpret_cast.clcpp +++ clang/test/CodeGenOpenCLCXX/reinterpret_cast.clcpp @@ -11,6 +11,17 @@ //CHECK: bitcast i64 %{{[0-9]+}} to <2 x i32> auto i2 = reinterpret_cast(l); + __private short s1; + // CHECK: %{{[0-9]+}} = load i16, i16* %s1, align 2 + // CHECK-NEXT: store i16 %{{[0-9]+}}, i16* %s2, align 2 + auto s2 = reinterpret_cast<__private short>(s1); + // CHECK: %{{[0-9]+}} = load i16, i16* %s1, align 2 + // CHECK-NEXT: store i16 %{{[0-9]+}}, i16* %s3, align 2 + auto s3 = reinterpret_cast(s1); + // CHECK: %{{[0-9]+}} = load i16, i16* %s1, align 2 + // CHECK-NEXT: store i16 %{{[0-9]+}}, i16* %s4, align 2 + auto s4 = reinterpret_cast<__global short>(s1); + int4 i4; //CHECK: bitcast <4 x i32> %{{[0-9]+}} to <2 x i64> auto l2 = reinterpret_cast(i4); Index: clang/test/SemaOpenCLCXX/reinterpret-cast.clcpp =================================================================== --- clang/test/SemaOpenCLCXX/reinterpret-cast.clcpp +++ clang/test/SemaOpenCLCXX/reinterpret-cast.clcpp @@ -4,6 +4,11 @@ typedef int int3 __attribute__((ext_vector_type(3))); typedef int int4 __attribute__((ext_vector_type(4))); +struct X {}; + +__global int g = 0; +__global int *__global g_ptr = &g; + kernel void foo() { // Testing conversions between vectors and vectors/scalars long l1; @@ -13,6 +18,17 @@ auto i2_to_i = reinterpret_cast(i2); // expected-error{{reinterpret_cast from vector 'int2' (vector of 2 'int' values) to scalar 'int' of different size}} auto i2_to_i2 = reinterpret_cast(i2); + // Testing reinterpret_cast with address spaces. + __private short s; + auto s2 = reinterpret_cast<__private short>(s); + auto s3 = reinterpret_cast(s); + auto s4 = reinterpret_cast<__global short>(s); + + __private X x; + auto x2 = reinterpret_cast<__private X>(x); // expected-error{{reinterpret_cast from '__private X' to '__private X' is not allowed}} + + auto ptr = reinterpret_cast<__global int* __private>(g_ptr); + // Only integral types (and pointer/references) can be reinterpret casted to themselves. // Currently this does not include any opencl types. reserve_id_t r_id1;