File tree Expand file tree Collapse file tree 2 files changed +35
-2
lines changed Expand file tree Collapse file tree 2 files changed +35
-2
lines changed Original file line number Diff line number Diff line change @@ -2711,6 +2711,20 @@ Sema::PerformObjectMemberConversion(Expr *From,
27112711 FromRecordType = FromType;
27122712 DestType = DestRecordType;
27132713 }
2714+
2715+ LangAS FromAS = FromRecordType.getAddressSpace();
2716+ LangAS DestAS = DestRecordType.getAddressSpace();
2717+ if (FromAS != DestAS) {
2718+ QualType FromRecordTypeWithoutAS =
2719+ Context.removeAddrSpaceQualType(FromRecordType);
2720+ QualType FromTypeWithDestAS =
2721+ Context.getAddrSpaceQualType(FromRecordTypeWithoutAS, DestAS);
2722+ if (PointerConversions)
2723+ FromTypeWithDestAS = Context.getPointerType(FromTypeWithDestAS);
2724+ From = ImpCastExprToType(From, FromTypeWithDestAS,
2725+ CK_AddressSpaceConversion, From->getValueKind())
2726+ .get();
2727+ }
27142728 } else {
27152729 // No conversion necessary.
27162730 return From;
Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ void foo() {
2828class B2 {
2929 public :
3030 void baseMethod () const { }
31+ int &getRef () { return bb ; }
3132 int bb ;
3233};
3334
@@ -46,7 +47,25 @@ void pr43145(const Derived *argDerived) {
4647
4748void pr43145_2 (B *argB ) {
4849 Derived *x = (Derived *)argB ;
50+ // CHECK -LABEL : @_Z9pr43145_2
51+ // CHECK : bitcast %struct .B addrspace (4 )* %0 to %class .Derived addrspace (4 )*
4952}
5053
51- // CHECK -LABEL : @_Z9pr43145_2
52- // CHECK : bitcast %struct .B addrspace (4 )* %0 to %class .Derived addrspace (4 )*
54+ // Assigning to reference returned by base class method through derived class .
55+
56+ void pr43145_3 (int n ) {
57+ Derived d ;
58+ d .getRef () = n ;
59+
60+ // CHECK -LABEL : @_Z9pr43145_3
61+ // CHECK : addrspacecast %class .Derived * %d to %class .Derived addrspace (4 )*
62+ // CHECK : bitcast i8 addrspace (4 )* %add .ptr to %class .B2 addrspace (4 )*
63+ // CHECK : call {{.*}} @_ZNU3AS42B26getRefEv
64+
65+ private Derived *pd = &d ;
66+ pd ->getRef () = n ;
67+
68+ // CHECK : addrspacecast %class .Derived * %4 to %class .Derived addrspace (4 )*
69+ // CHECK : bitcast i8 addrspace (4 )* %add .ptr1 to %class .B2 addrspace (4 )*
70+ // CHECK : call {{.*}} @_ZNU3AS42B26getRefEv
71+ }
You can’t perform that action at this time.
0 commit comments