[clang] 957213f - [OpenCL] Diagnose block references in selection operator (#114824)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 22 00:50:00 PST 2025
Author: Sven van Haastregt
Date: 2025-01-22T09:49:56+01:00
New Revision: 957213f60b258a5f6cab04e50c78c0a0c1c304c2
URL: https://github.com/llvm/llvm-project/commit/957213f60b258a5f6cab04e50c78c0a0c1c304c2
DIFF: https://github.com/llvm/llvm-project/commit/957213f60b258a5f6cab04e50c78c0a0c1c304c2.diff
LOG: [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.
Added:
Modified:
clang/lib/Sema/SemaExpr.cpp
clang/test/SemaOpenCL/invalid-block.cl
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 444640b27de1fe..d5273d463d7c01 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -8388,6 +8388,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}}
More information about the cfe-commits
mailing list