[OpenCL] Restrict addr space conversions in nested pointers
authorAnastasia Stulova <anastasia.stulova@arm.com>
Thu, 6 Feb 2020 11:56:21 +0000 (11:56 +0000)
committerAnastasia Stulova <anastasia.stulova@arm.com>
Fri, 7 Feb 2020 12:04:35 +0000 (12:04 +0000)
commit6064f426a18304e16b51cc79e74c9c2d55ef5a9c
tree73197662e0f72142bb9bd9bc799bae3de87d60dd
parent64bc627b8878dd77fc3a85007e2ced0a515c77d3
[OpenCL] Restrict addr space conversions in nested pointers

Address space conversion changes pointer representation.
This commit disallows such conversions when they are not
legal i.e. for the nested pointers even with compatible
address spaces. Because the address space conversion in
the nested levels can't be generated to modify the pointers
correctly. The behavior implemented is as follows:

- Any implicit conversions of nested pointers with different
  address spaces is rejected.
- Any conversion of address spaces in nested pointers in safe
  casts (e.g. const_cast or static_cast) is rejected.
- Conversion in low level C-style or reinterpret_cast is accepted
  but with a warning (this aligns with OpenCL C behavior).

Fixes PR39674

Differential Revision: https://reviews.llvm.org/D73360
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaCast.cpp
clang/lib/Sema/SemaOverload.cpp
clang/test/SemaOpenCL/address-spaces-conversions-cl2.0.cl
clang/test/SemaOpenCL/address-spaces.cl
clang/test/SemaOpenCLCXX/address-space-castoperators.cl [new file with mode: 0644]
clang/test/SemaOpenCLCXX/address-space-deduction.cl
clang/test/SemaOpenCLCXX/address-space-references.cl