[PATCH] D50003: Sema: Fix explicit address space cast involving void pointers

John McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 2 15:57:18 PDT 2018


rjmccall added inline comments.


================
Comment at: lib/Sema/SemaCast.cpp:1050
+         SrcType->getAs<PointerType>()->getPointeeType().getAddressSpace() !=
+             DestType->getAs<PointerType>()->getPointeeType().getAddressSpace();
+}
----------------
yaxunl wrote:
> rjmccall wrote:
> > yaxunl wrote:
> > > rjmccall wrote:
> > > > I know the code was like this before, but please rewrite this to just use `getAs<PointerType>()` instead of doing the separate `isPointerType()` check.
> > > IsAddressSpaceConversion is also called in line 2218 of the same file, where SrcType or DestType may not be pointer type.
> > `getAs` is a query; it returns null if the type isn't of the target type.
> How about 
> 
> ```
> auto *SrcPtrType = SrcType->getAs<PointerType>();
> if (!SrcPtrType )
>   return false;
> auto *DestPtrType = DestType->getAs<PointerType>();
> if (!DestPtrType)
>   return false;
> return SrcPtrType->getPointeeType().getAddressSpace() !=
>              DestPtrType->getPointeeType().getAddressSpace();
> ```
That looks right.


https://reviews.llvm.org/D50003





More information about the cfe-commits mailing list