[PATCH] D109150: [OpenCL] Disallows static kernel functions in C++ for OpenCL
Justas Janickas via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 2 05:38:42 PDT 2021
Topotuna created this revision.
Topotuna added a reviewer: Anastasia.
Herald added subscribers: ldrumm, yaxunl.
Topotuna requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D109150
Files:
clang/lib/Sema/SemaDecl.cpp
clang/test/SemaOpenCL/storageclass-cl20.cl
Index: clang/test/SemaOpenCL/storageclass-cl20.cl
===================================================================
--- clang/test/SemaOpenCL/storageclass-cl20.cl
+++ 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 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;
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -9969,8 +9969,8 @@
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 ((getLangOpts().getOpenCLCompatibleVersion() >= 120) &&
+ (SC == SC_Static)) {
Diag(D.getIdentifierLoc(), diag::err_static_kernel);
D.setInvalidType();
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109150.370241.patch
Type: text/x-patch
Size: 1435 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210902/49b379eb/attachment.bin>
More information about the cfe-commits
mailing list