[clang] c33e296 - [OpenCL] Disallows static kernel functions in C++ for OpenCL
Justas Janickas via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 7 02:24:03 PDT 2021
Author: Justas Janickas
Date: 2021-09-07T10:23:50+01:00
New Revision: c33e296be1daa621f5933f3729a0ce51172f1505
URL: https://github.com/llvm/llvm-project/commit/c33e296be1daa621f5933f3729a0ce51172f1505
DIFF: https://github.com/llvm/llvm-project/commit/c33e296be1daa621f5933f3729a0ce51172f1505.diff
LOG: [OpenCL] Disallows static kernel functions in C++ for OpenCL
It is disallowed in OpenCL C to declare static kernel functions and
C++ for OpenCL is expected to inherit such behaviour. Error is now
correctly reported in C++ for OpenCL when declaring a static kernel
function.
Differential Revision: https://reviews.llvm.org/D109150
Added:
Modified:
clang/lib/Sema/SemaDecl.cpp
clang/test/SemaOpenCL/storageclass-cl20.cl
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index f33811f63c71e..92c1a37fdab96 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -9970,8 +9970,7 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC,
if (getLangOpts().OpenCL && NewFD->hasAttr<OpenCLKernelAttr>()) {
// OpenCL v1.2 s6.8 static is invalid for kernel functions.
- if ((getLangOpts().OpenCLVersion >= 120)
- && (SC == SC_Static)) {
+ if (SC == SC_Static) {
Diag(D.getIdentifierLoc(), diag::err_static_kernel);
D.setInvalidType();
}
diff --git a/clang/test/SemaOpenCL/storageclass-cl20.cl b/clang/test/SemaOpenCL/storageclass-cl20.cl
index 581701d2a6a54..f07966e5bd01f 100644
--- a/clang/test/SemaOpenCL/storageclass-cl20.cl
+++ b/clang/test/SemaOpenCL/storageclass-cl20.cl
@@ -1,4 +1,5 @@
// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=clc++1.0
int G2 = 0;
global int G3 = 0;
@@ -18,6 +19,9 @@ extern local float g_local_extern_var; // expected-error {{extern variable m
extern private float g_private_extern_var; // expected-error {{extern variable must reside in global or constant address space}}
extern generic float g_generic_extern_var; // expected-error {{extern variable must reside in global or constant address space}}
+static void kernel bar() { // expected-error{{kernel functions cannot be declared static}}
+}
+
void kernel foo() {
constant int L1 = 0;
local int L2;
More information about the cfe-commits
mailing list