Skip to content

Commit 957213f

Browse files
authored
[OpenCL] Diagnose block references in selection operator (#114824)
In addition to the invocation case that is already diagnosed, also diagnose when a block reference appears on either side of a ternary selection operator. Until now, clang would accept the added test case only to crash during code generation.
1 parent 22561cf commit 957213f

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
@@ -8388,6 +8388,11 @@ OpenCLCheckVectorConditional(Sema &S, ExprResult &Cond,
83888388

83898389
/// Return true if the Expr is block type
83908390
static bool checkBlockType(Sema &S, const Expr *E) {
8391+
if (E->getType()->isBlockPointerType()) {
8392+
S.Diag(E->getExprLoc(), diag::err_opencl_ternary_with_block);
8393+
return true;
8394+
}
8395+
83918396
if (const CallExpr *CE = dyn_cast<CallExpr>(E)) {
83928397
QualType Ty = CE->getCallee()->getType();
83938398
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)