[clang] [OpenCL] Diagnose block references in selection operator (PR #114824)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 4 08:24:27 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Sven van Haastregt (svenvh)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/114824.diff
2 Files Affected:
- (modified) clang/lib/Sema/SemaExpr.cpp (+5)
- (modified) clang/test/SemaOpenCL/invalid-block.cl (+2)
``````````diff
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}}
``````````
</details>
https://github.com/llvm/llvm-project/pull/114824
More information about the cfe-commits
mailing list