This is an archive of the discontinued LLVM Phabricator instance.

[PR40778] Preserve addr space in Derived to Base cast
ClosedPublic

Authored by Anastasia on Feb 27 2019, 3:30 AM.

Details

Reviewers
rjmccall
Summary

The address space for the Base class pointer when up-casting from Derived should be taken from the Derived class pointer.

Diff Detail

Event Timeline

Anastasia created this revision.Feb 27 2019, 3:30 AM
rjmccall added inline comments.Feb 27 2019, 10:10 AM
lib/Sema/SemaExpr.cpp
2674

This path (when the object is a gl-value) also needs an address-space qualifier, so you should probably add it above and then just add a pointer in the pointer case.

Anastasia updated this revision to Diff 189347.Mar 5 2019, 10:07 AM
Anastasia marked an inline comment as done.

Moved adding address space to DestType earlier to cover pointer and non-pointer case.

Anastasia added inline comments.Mar 5 2019, 10:09 AM
lib/Sema/SemaExpr.cpp
2674

I updated this but I haven't really found any test case that would fail. I guess because casting non-pointer types in different address spaces works fine...

For example the IR is generated correctly with or without the fix.

1 struct S {
2    volatile int a;
3 }; 
4 
5 __global S g;
6 
7 void foo(){
8 g.a; 
9 }

However, I still think it's indeed good to add the address space in both cases for consistency.

rjmccall added inline comments.Mar 5 2019, 10:36 AM
lib/Sema/SemaExpr.cpp
2666

Please do a getAs<PointerType>() into a local and then use that here and below.

Anastasia updated this revision to Diff 189371.Mar 5 2019, 10:58 AM

Use common pointer type.

Anastasia marked an inline comment as done.Mar 5 2019, 10:59 AM
rjmccall added inline comments.Mar 5 2019, 11:10 AM
lib/Sema/SemaExpr.cpp
2671

And here.

Anastasia updated this revision to Diff 189470.Mar 6 2019, 3:02 AM
Anastasia marked an inline comment as done.
Anastasia added inline comments.
lib/Sema/SemaExpr.cpp
2671

Oh, yes... thanks!

rjmccall accepted this revision.Mar 6 2019, 7:13 AM

Thanks, LGTM.

This revision is now accepted and ready to land.Mar 6 2019, 7:13 AM
Anastasia closed this revision.Mar 7 2019, 9:08 AM

Committed in r355606.