diff options
author | Marco Antognini <marco.antognini@arm.com> | 2019-07-09 15:04:27 +0000 |
---|---|---|
committer | Marco Antognini <marco.antognini@arm.com> | 2019-07-09 15:04:27 +0000 |
commit | 7b940eef535a52a1fa1978f6fb5a5f290e5070e4 (patch) | |
tree | a040ca404802ee86a36b0056291729138ac21172 /lib/Sema/SemaExprCXX.cpp | |
parent | 86a2a1c7f3e8ac546c920028a8cc76e1bd54d7bf (diff) | |
download | clang-7b940eef535a52a1fa1978f6fb5a5f290e5070e4.tar.gz |
[OpenCL][Sema] Improve address space support for blocks
Summary:
This patch ensures that the following code is compiled identically with
-cl-std=CL2.0 and -fblocks -cl-std=c++.
kernel void test(void) {
void (^const block_A)(void) = ^{
return;
};
}
A new test is not added because cl20-device-side-enqueue.cl will cover
this once blocks are further improved for C++ for OpenCL.
The changes to Sema::PerformImplicitConversion are based on
the parts of Sema::CheckAssignmentConstraints on block pointer
conversions.
Reviewers: rjmccall, Anastasia
Subscribers: yaxunl, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64083
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@365500 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaExprCXX.cpp')
-rw-r--r-- | lib/Sema/SemaExprCXX.cpp | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index 32b35ba7c3..3029861f23 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -4216,7 +4216,20 @@ Sema::PerformImplicitConversion(Expr *From, QualType ToType, break; case ICK_Block_Pointer_Conversion: { - From = ImpCastExprToType(From, ToType.getUnqualifiedType(), CK_BitCast, + QualType LHSType = Context.getCanonicalType(ToType).getUnqualifiedType(); + QualType RHSType = Context.getCanonicalType(FromType).getUnqualifiedType(); + + // Assumptions based on Sema::IsBlockPointerConversion. + assert(isa<BlockPointerType>(LHSType) && "BlockPointerType expected"); + assert(isa<BlockPointerType>(RHSType) && "BlockPointerType expected"); + + LangAS AddrSpaceL = + LHSType->getAs<BlockPointerType>()->getPointeeType().getAddressSpace(); + LangAS AddrSpaceR = + RHSType->getAs<BlockPointerType>()->getPointeeType().getAddressSpace(); + CastKind Kind = + AddrSpaceL != AddrSpaceR ? CK_AddressSpaceConversion : CK_BitCast; + From = ImpCastExprToType(From, ToType.getUnqualifiedType(), Kind, VK_RValue, /*BasePath=*/nullptr, CCK).get(); break; } |