[PATCH] D52598: [OpenCL] Fixed address space cast in C style cast of C++ parsing

Anastasia Stulova via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 5 07:53:31 PDT 2018


Anastasia added inline comments.


================
Comment at: lib/Sema/SemaCast.cpp:2288
+      SrcType->isPointerType()) {
+    const PointerType *DestPtr = DestType->getAs<PointerType>();
+    if (!DestPtr->isAddressSpaceOverlapping(*SrcType->getAs<PointerType>())) {
----------------
Anastasia wrote:
> rjmccall wrote:
> > Please test the result of `getAs` instead of separately testing `isPointerType`.
> > 
> > Why is this check OpenCL-specific?  Address spaces are a general language feature.
> I think mainly because I am factoring out from the existing OpenCL check. But it probably makes sense that the semantics of this is not different in other languages. I will update it! Thanks!
After playing with this for a bit longer I discovered that I have to keep the OpenCL check unfortunately.

I found this old commit (`d4c5f84`/`r129583`) that says:
  C-style casts can add/remove/change address spaces through the reinterpret_cast mechanism.
That's not the same as in OpenCL because it seems for C++ you can cast any AS to any other AS. Therefore, no checks are needed at all. I am not sure if we can come up with a common function for the moment.

The following  tests are checking this:
   CodeGenCXX/address-space-cast.cpp
   SemaCXX/address-space-conversion.cpp

Do you think it would make sense to rename this method with OpenCL-something or keep in case may be CUDA or some other languages might need similar functionality...



https://reviews.llvm.org/D52598





More information about the cfe-commits mailing list