https://github.com/svenvh created https://github.com/llvm/llvm-project/pull/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. >From 386b891dce07f37d3b886008f42160e7224f6e4c Mon Sep 17 00:00:00 2001 From: Sven van Haastregt <sven.vanhaastr...@arm.com> Date: Mon, 4 Nov 2024 13:36:04 +0000 Subject: [PATCH] [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. --- clang/lib/Sema/SemaExpr.cpp | 5 +++++ clang/test/SemaOpenCL/invalid-block.cl | 2 ++ 2 files changed, 7 insertions(+) diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 7f3cff1054aeed..cbaca2fb5af56e 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -8374,6 +8374,11 @@ OpenCLCheckVectorConditional(Sema &S, ExprResult &Cond, /// Return true if the Expr is block type static bool checkBlockType(Sema &S, const Expr *E) { + if (E->getType()->isBlockPointerType()) { + S.Diag(E->getExprLoc(), diag::err_opencl_ternary_with_block); + return true; + } + if (const CallExpr *CE = dyn_cast<CallExpr>(E)) { QualType Ty = CE->getCallee()->getType(); if (Ty->isBlockPointerType()) { diff --git a/clang/test/SemaOpenCL/invalid-block.cl b/clang/test/SemaOpenCL/invalid-block.cl index 6c918d302f8018..16053690004297 100644 --- a/clang/test/SemaOpenCL/invalid-block.cl +++ b/clang/test/SemaOpenCL/invalid-block.cl @@ -65,6 +65,8 @@ void f5(int i) { bl2_t arr[] = {bl1, bl2}; // expected-error {{array of 'bl2_t' (aka 'int (__generic ^const)(__private int)') type is invalid in OpenCL}} int tmp = i ? bl1(i) // expected-error {{block type cannot be used as expression in ternary expression in OpenCL}} : bl2(i); // expected-error {{block type cannot be used as expression in ternary expression in OpenCL}} + bl2_t bref = i ? bl1 // expected-error {{block type cannot be used as expression in ternary expression in OpenCL}} + : bl2; // expected-error {{block type cannot be used as expression in ternary expression in OpenCL}} } // A block pointer type and all pointer operations are disallowed void f6(bl2_t *bl_ptr) { // expected-error{{pointer to type 'bl2_t' (aka 'int (__generic ^const)(__private int)') is invalid in OpenCL}} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits