[OpenCL] Disallows static kernel functions in C++ for OpenCL
authorJustas Janickas <Justas.Janickas@arm.com>
Thu, 2 Sep 2021 10:51:39 +0000 (11:51 +0100)
committerJustas Janickas <Justas.Janickas@arm.com>
Tue, 7 Sep 2021 09:23:50 +0000 (10:23 +0100)
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

clang/lib/Sema/SemaDecl.cpp
clang/test/SemaOpenCL/storageclass-cl20.cl

index f33811f..92c1a37 100644 (file)
@@ -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();
     }
index 581701d..f07966e 100644 (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=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;