Skip to content

Commit d36e130

Browse files
committed
[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 llvm-svn: 365500
1 parent b00d5f7 commit d36e130

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

clang/lib/Sema/SemaExprCXX.cpp

+14-1
Original file line numberDiff line numberDiff line change
@@ -4216,7 +4216,20 @@ Sema::PerformImplicitConversion(Expr *From, QualType ToType,
42164216
break;
42174217

42184218
case ICK_Block_Pointer_Conversion: {
4219-
From = ImpCastExprToType(From, ToType.getUnqualifiedType(), CK_BitCast,
4219+
QualType LHSType = Context.getCanonicalType(ToType).getUnqualifiedType();
4220+
QualType RHSType = Context.getCanonicalType(FromType).getUnqualifiedType();
4221+
4222+
// Assumptions based on Sema::IsBlockPointerConversion.
4223+
assert(isa<BlockPointerType>(LHSType) && "BlockPointerType expected");
4224+
assert(isa<BlockPointerType>(RHSType) && "BlockPointerType expected");
4225+
4226+
LangAS AddrSpaceL =
4227+
LHSType->getAs<BlockPointerType>()->getPointeeType().getAddressSpace();
4228+
LangAS AddrSpaceR =
4229+
RHSType->getAs<BlockPointerType>()->getPointeeType().getAddressSpace();
4230+
CastKind Kind =
4231+
AddrSpaceL != AddrSpaceR ? CK_AddressSpaceConversion : CK_BitCast;
4232+
From = ImpCastExprToType(From, ToType.getUnqualifiedType(), Kind,
42204233
VK_RValue, /*BasePath=*/nullptr, CCK).get();
42214234
break;
42224235
}

0 commit comments

Comments
 (0)