This is an archive of the discontinued LLVM Phabricator instance.

Sema: Fix explicit address space cast involving void pointers
ClosedPublic

Authored by yaxunl on Jul 30 2018, 12:30 PM.

Details

Summary

Explicit cast of a void pointer to a pointer type in different address space is
incorrectly classified as bitcast, which causes invalid bitcast in codegen.

The patch fixes that by checking the address space of the source and destination
type and set the correct cast kind.

Diff Detail

Repository
rL LLVM

Event Timeline

yaxunl created this revision.Jul 30 2018, 12:30 PM
rjmccall accepted this revision.Aug 1 2018, 3:06 PM

One minor request; feel free to just do that when you commit.

lib/Sema/SemaCast.cpp
1050 ↗(On Diff #158043)

I know the code was like this before, but please rewrite this to just use getAs<PointerType>() instead of doing the separate isPointerType() check.

This revision is now accepted and ready to land.Aug 1 2018, 3:06 PM
yaxunl added inline comments.Aug 1 2018, 9:52 PM
lib/Sema/SemaCast.cpp
1050 ↗(On Diff #158043)

IsAddressSpaceConversion is also called in line 2218 of the same file, where SrcType or DestType may not be pointer type.

rjmccall added inline comments.Aug 1 2018, 10:59 PM
lib/Sema/SemaCast.cpp
1050 ↗(On Diff #158043)

getAs is a query; it returns null if the type isn't of the target type.

yaxunl added inline comments.Aug 2 2018, 5:44 AM
lib/Sema/SemaCast.cpp
1050 ↗(On Diff #158043)

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();
rjmccall added inline comments.Aug 2 2018, 3:57 PM
lib/Sema/SemaCast.cpp
1050 ↗(On Diff #158043)

That looks right.

This revision was automatically updated to reflect the committed changes.