[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
This commit is contained in:
Justas Janickas 2021-09-02 11:51:39 +01:00
parent da9ed3dc71
commit c33e296be1
2 changed files with 5 additions and 2 deletions

View File

@ -9970,8 +9970,7 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC,
if (getLangOpts().OpenCL && NewFD->hasAttr<OpenCLKernelAttr>()) { if (getLangOpts().OpenCL && NewFD->hasAttr<OpenCLKernelAttr>()) {
// OpenCL v1.2 s6.8 static is invalid for kernel functions. // OpenCL v1.2 s6.8 static is invalid for kernel functions.
if ((getLangOpts().OpenCLVersion >= 120) if (SC == SC_Static) {
&& (SC == SC_Static)) {
Diag(D.getIdentifierLoc(), diag::err_static_kernel); Diag(D.getIdentifierLoc(), diag::err_static_kernel);
D.setInvalidType(); D.setInvalidType();
} }

View File

@ -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=CL2.0
// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=clc++1.0
int G2 = 0; int G2 = 0;
global int G3 = 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 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}} 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() { void kernel foo() {
constant int L1 = 0; constant int L1 = 0;
local int L2; local int L2;