This is an archive of the discontinued LLVM Phabricator instance.

[Sema] Iteratively strip sugar when removing address spaces.
ClosedPublic

Authored by ebevhan on Jul 7 2020, 10:34 AM.

Details

Summary

ASTContext::removeAddrSpaceQualType does not properly deal
with sugar. QualTypes derive their ASes from the AS on the
canonical type, not the type itself. However,
removeAddrSpaceQualType only strips the outermost qualifiers,
which means that it can fail to remove addrspace qualifiers
if there is sugar in the way.

Change the function to desugar types until the address space
really no longer exists on the corresponding QualType. This
should guarantee the removal of the address space.

This fixes the erroneous behavior in D62574.

Diff Detail

Event Timeline

ebevhan created this revision.Jul 7 2020, 10:34 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 7 2020, 10:34 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Wondering if stripping the sugar is the right thing to do here, because it means we don't have any sugar on the resulting type if it has gone through the SCS and pointer type reconstruction?

I'm unsure if this is currently broken upstream without other patches to exploit the behavior,

I'm not sure either; perhaps @rjmccall has some insights.

removeAddrSpaceQualType should guarantee that it removes the address space qualifier; you shouldn't need to do something special here. That means it needs to iteratively desugar and collect qualifiers as long as the type is still address-space-qualified.

removeAddrSpaceQualType should guarantee that it removes the address space qualifier; you shouldn't need to do something special here. That means it needs to iteratively desugar and collect qualifiers as long as the type is still address-space-qualified.

Well, from what I observed, it is not doing that, so perhaps that's what needs to be addressed. That's a bit more involved, though.

We will still end up stripping all sugar up until we hit the AS-qualification, though. Unless we are supposed to reconstitute the sugared type with the AS altered somehow?

There's no way to do that, no. Stripping sugar down to the point where you don't have that qualifier anymore is the best we can do.

ebevhan updated this revision to Diff 284395.Aug 10 2020, 8:52 AM
ebevhan retitled this revision from [Sema] Be more thorough when unpacking the AS-qualified pointee for a pointer conversion. to [Sema] Iteratively strip sugar when removing address spaces..
ebevhan edited the summary of this revision. (Show Details)

Redid patch. Now we properly strip ASes from types by desugaring.

This revision is now accepted and ready to land.Aug 10 2020, 2:06 PM
svenvh accepted this revision.Aug 11 2020, 4:42 AM

LGTM, but just wondering if the test actually belongs to this patch, as it doesn't demonstrate the problem without one of your other patches?

LGTM, but just wondering if the test actually belongs to this patch, as it doesn't demonstrate the problem without one of your other patches?

Mm, that is true, but then I'd be submitting the patch without a test and that doesn't seem quite right.

I'm unsure if there's a way to exhibit the failure without the followup patch.