Skip to content

Commit 386b891

Browse files
committed
[OpenCL] Diagnose block references in selection operator
In addition to the case that is already diagnosed, also diagnose when a block reference appears on either side of a ternary selection operator.
1 parent ae0ab24 commit 386b891

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

clang/lib/Sema/SemaExpr.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8374,6 +8374,11 @@ OpenCLCheckVectorConditional(Sema &S, ExprResult &Cond,
83748374

83758375
/// Return true if the Expr is block type
83768376
static bool checkBlockType(Sema &S, const Expr *E) {
8377+
if (E->getType()->isBlockPointerType()) {
8378+
S.Diag(E->getExprLoc(), diag::err_opencl_ternary_with_block);
8379+
return true;
8380+
}
8381+
83778382
if (const CallExpr *CE = dyn_cast<CallExpr>(E)) {
83788383
QualType Ty = CE->getCallee()->getType();
83798384
if (Ty->isBlockPointerType()) {

clang/test/SemaOpenCL/invalid-block.cl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ void f5(int i) {
6565
bl2_t arr[] = {bl1, bl2}; // expected-error {{array of 'bl2_t' (aka 'int (__generic ^const)(__private int)') type is invalid in OpenCL}}
6666
int tmp = i ? bl1(i) // expected-error {{block type cannot be used as expression in ternary expression in OpenCL}}
6767
: bl2(i); // expected-error {{block type cannot be used as expression in ternary expression in OpenCL}}
68+
bl2_t bref = i ? bl1 // expected-error {{block type cannot be used as expression in ternary expression in OpenCL}}
69+
: bl2; // expected-error {{block type cannot be used as expression in ternary expression in OpenCL}}
6870
}
6971
// A block pointer type and all pointer operations are disallowed
7072
void f6(bl2_t *bl_ptr) { // expected-error{{pointer to type 'bl2_t' (aka 'int (__generic ^const)(__private int)') is invalid in OpenCL}}

0 commit comments

Comments
 (0)