From 3bef4a5688250d984c10ef3ed64c85d0f62de5ac Mon Sep 17 00:00:00 2001 From: Anastasia Stulova Date: Thu, 7 Mar 2019 16:23:15 +0000 Subject: [PR40778] Preserve addr space in Derived to Base cast. The address space for the Base class pointer when up-casting from Derived should be taken from the Derived class pointer. Differential Revision: https://reviews.llvm.org/D53818 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@355606 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaExpr.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'lib/Sema/SemaExpr.cpp') diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 187d8e2fdd..a6724a5288 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -2660,10 +2660,15 @@ Sema::PerformObjectMemberConversion(Expr *From, bool PointerConversions = false; if (isa(Member)) { DestRecordType = Context.getCanonicalType(Context.getTypeDeclType(RD)); + auto FromPtrType = FromType->getAs(); + DestRecordType = Context.getAddrSpaceQualType( + DestRecordType, FromPtrType + ? FromType->getPointeeType().getAddressSpace() + : FromType.getAddressSpace()); - if (FromType->getAs()) { + if (FromPtrType) { DestType = Context.getPointerType(DestRecordType); - FromRecordType = FromType->getPointeeType(); + FromRecordType = FromPtrType->getPointeeType(); PointerConversions = true; } else { DestType = DestRecordType; -- cgit v1.2.1