This is an archive of the discontinued LLVM Phabricator instance.

[OpenCL] Fix address space for implicit conversion (PR43145)
ClosedPublic

Authored by svenvh on Nov 22 2019, 10:29 AM.

Details

Summary

Clang was creating a DerivedToBase ImplicitCastExpr that was also
casting between address spaces as part of the second step in the
standard conversion sequence. Defer the address space conversion to
the third step in the sequence instead, such that we get a separate
ImplicitCastExpr for the address space conversion.

Diff Detail

Event Timeline

svenvh created this revision.Nov 22 2019, 10:29 AM

Is there a similar problem with reference parameters?

Is there a similar problem with reference parameters?

It doesn't seem so, patching the test as follows gives reasonable output.

@@ -73,8 +73,10 @@ void pr43145_3(int n) {
 // Implicit conversion of derived to base.
 
 void functionWithBaseArg(class B2 *b) {}
+void functionWithBaseArgRef(class B2 &b) {}
 
 void pr43145_4() {
   Derived d;
   functionWithBaseArg(&d);
+  functionWithBaseArgRef(d);
 }

Great. Could you add that to the test, then, just to make sure we don't regress it?

svenvh updated this revision to Diff 231285.Nov 27 2019, 9:32 AM

Added test for references too.

rjmccall added inline comments.Nov 27 2019, 11:04 AM
clang/lib/Sema/SemaExprCXX.cpp
4108

Hmm, sorry, just noticed this. Could you write this so that it preserves the original kind of pointer of ToType? I think it has to be a PointerType, BlockPointerType, or ObjCObjectPointerType. It doesn't look like there's an existing utility for that.

svenvh updated this revision to Diff 231426.Nov 28 2019, 6:47 AM

Address comment from @rjmccall to preserve original ToType pointer type.

rjmccall accepted this revision.Nov 28 2019, 12:59 PM

Thanks, LGTM.

This revision is now accepted and ready to land.Nov 28 2019, 12:59 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptDec 2 2019, 6:21 AM
ebevhan added a subscriber: ebevhan.Jul 7 2020, 9:08 AM

I know this is some really late feedback on this patch. I struck upon some issues with while rebasing D62574.

clang/lib/Sema/SemaExprCXX.cpp
4106

I don't think this will manage to properly repack the type if it's hidden behind enough sugar. When I enable C++ address space conversions in a non-OpenCL context, this breaks the derived-to-base example in CodeGenCXX/address-space-cast.cpp.

IsPointerConversion doesn't have an issue with this since it reconstructs the destination type with the appropriate qualifiers through BuildSimilarlyQualifiedPointerType.

Wouldn't it make more sense to have *PointerConversion only handle the derived-to-base and leave the address space conversion to *QualificationConversion?

svenvh marked an inline comment as done.Jul 7 2020, 10:03 AM
svenvh added inline comments.
clang/lib/Sema/SemaExprCXX.cpp
4106

Wouldn't it make more sense to have *PointerConversion only handle the derived-to-base and leave the address space conversion to *QualificationConversion?

I didn't have a thorough look to understand all implications of that, but maybe it's worth trying. Not sure I'll be able to follow up on this any time soon, would you be able to give it a try?

ebevhan added inline comments.Jul 7 2020, 10:07 AM
clang/lib/Sema/SemaExprCXX.cpp
4106

I'll see if I can have a look, or at least make the existing implementation a bit more thorough.

To be entirely honest, I feel a bit stupid right now: I forgot that I added the derived-to-base test in the test case I mentioned in my local experimental branch, so of course you wouldn't be able to use that as a baseline. Oops!