[PATCH] D69810: [OpenCL] Fix address space for base method call (PR43145)
Sven van Haastregt via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 19 10:06:37 PST 2019
svenvh updated this revision to Diff 230096.
svenvh edited the summary of this revision.
svenvh added a comment.
Rework fix to insert an addrspace conversion node into the AST instead of catching the addrspace cast in CGCall.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D69810/new/
https://reviews.llvm.org/D69810
Files:
clang/lib/Sema/SemaExpr.cpp
clang/test/CodeGenOpenCLCXX/addrspace-derived-base.cl
Index: clang/test/CodeGenOpenCLCXX/addrspace-derived-base.cl
===================================================================
--- clang/test/CodeGenOpenCLCXX/addrspace-derived-base.cl
+++ clang/test/CodeGenOpenCLCXX/addrspace-derived-base.cl
@@ -28,6 +28,7 @@
class B2 {
public:
void baseMethod() const { }
+ int& getRef() { return bb; }
int bb;
};
@@ -46,7 +47,17 @@
void pr43145_2(B *argB) {
Derived *x = (Derived*)argB;
+ // CHECK-LABEL: @_Z9pr43145_2
+ // CHECK: bitcast %struct.B addrspace(4)* %0 to %class.Derived addrspace(4)*
}
-// CHECK-LABEL: @_Z9pr43145_2
-// CHECK: bitcast %struct.B addrspace(4)* %0 to %class.Derived addrspace(4)*
+// Assigning to reference returned by base class method through derived class.
+
+void pr43145_3(int n) {
+ Derived d;
+ d.getRef() = n;
+ // CHECK-LABEL: @_Z9pr43145_3
+ // CHECK: addrspacecast %class.Derived* %d to %class.Derived addrspace(4)*
+ // CHECK: bitcast i8 addrspace(4)* %add.ptr to %class.B2 addrspace(4)*
+ // CHECK: call {{.*}} @_ZNU3AS42B26getRefEv
+}
Index: clang/lib/Sema/SemaExpr.cpp
===================================================================
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -2711,6 +2711,15 @@
FromRecordType = FromType;
DestType = DestRecordType;
}
+
+ LangAS FromAS = FromRecordType.getAddressSpace();
+ LangAS DestAS = DestRecordType.getAddressSpace();
+ if (FromAS != DestAS) {
+ auto FromTyWithoutAS = Context.removeAddrSpaceQualType(FromType);
+ auto DestASTy = Context.getAddrSpaceQualType(FromTyWithoutAS, DestAS);
+ From = ImpCastExprToType(From, DestASTy, CK_AddressSpaceConversion,
+ From->getValueKind()).get();
+ }
} else {
// No conversion necessary.
return From;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69810.230096.patch
Type: text/x-patch
Size: 1818 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191119/9e979ee4/attachment.bin>
More information about the cfe-commits
mailing list