[clang] 35388dc - [OpenCL] Fix address space for base method call (PR43145)
Sven van Haastregt via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 21 02:39:57 PST 2019
Author: Sven van Haastregt
Date: 2019-11-21T10:39:33Z
New Revision: 35388dcbbc4ce6ce7125f718b3050be33c339464
URL: https://github.com/llvm/llvm-project/commit/35388dcbbc4ce6ce7125f718b3050be33c339464
DIFF: https://github.com/llvm/llvm-project/commit/35388dcbbc4ce6ce7125f718b3050be33c339464.diff
LOG: [OpenCL] Fix address space for base method call (PR43145)
Clang was creating an UncheckedDerivedToBase ImplicitCastExpr that was
also casting between address spaces. Insert an ImplicitCastExpr node
for doing the address space conversion.
Differential Revision: https://reviews.llvm.org/D69810
Added:
Modified:
clang/lib/Sema/SemaExpr.cpp
clang/test/CodeGenOpenCLCXX/addrspace-derived-base.cl
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index ea4321cdd728..3be8af1dd9e7 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -2711,6 +2711,20 @@ Sema::PerformObjectMemberConversion(Expr *From,
FromRecordType = FromType;
DestType = DestRecordType;
}
+
+ LangAS FromAS = FromRecordType.getAddressSpace();
+ LangAS DestAS = DestRecordType.getAddressSpace();
+ if (FromAS != DestAS) {
+ QualType FromRecordTypeWithoutAS =
+ Context.removeAddrSpaceQualType(FromRecordType);
+ QualType FromTypeWithDestAS =
+ Context.getAddrSpaceQualType(FromRecordTypeWithoutAS, DestAS);
+ if (PointerConversions)
+ FromTypeWithDestAS = Context.getPointerType(FromTypeWithDestAS);
+ From = ImpCastExprToType(From, FromTypeWithDestAS,
+ CK_AddressSpaceConversion, From->getValueKind())
+ .get();
+ }
} else {
// No conversion necessary.
return From;
diff --git a/clang/test/CodeGenOpenCLCXX/addrspace-derived-base.cl b/clang/test/CodeGenOpenCLCXX/addrspace-derived-base.cl
index ba76dbb4c6f7..d5d369fa80bb 100644
--- a/clang/test/CodeGenOpenCLCXX/addrspace-derived-base.cl
+++ b/clang/test/CodeGenOpenCLCXX/addrspace-derived-base.cl
@@ -28,6 +28,7 @@ void foo() {
class B2 {
public:
void baseMethod() const { }
+ int &getRef() { return bb; }
int bb;
};
@@ -46,7 +47,25 @@ void pr43145(const Derived *argDerived) {
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
+
+ private Derived *pd = &d;
+ pd->getRef() = n;
+
+ // CHECK: addrspacecast %class.Derived* %4 to %class.Derived addrspace(4)*
+ // CHECK: bitcast i8 addrspace(4)* %add.ptr1 to %class.B2 addrspace(4)*
+ // CHECK: call {{.*}} @_ZNU3AS42B26getRefEv
+}
More information about the cfe-commits
mailing list