r173963 - Add OpenCL error that a kernel function must have void return type. Includes a test case.
Tanya Lattner
tonic at nondot.org
Wed Jan 30 11:48:52 PST 2013
Author: tbrethou
Date: Wed Jan 30 13:48:52 2013
New Revision: 173963
URL: http://llvm.org/viewvc/llvm-project?rev=173963&view=rev
Log:
Add OpenCL error that a kernel function must have void return type. Includes a test case.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaOpenCL/invalid-kernel.cl
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=173963&r1=173962&r2=173963&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Jan 30 13:48:52 2013
@@ -6124,6 +6124,8 @@ def err_event_t_struct_field : Error<
"the event_t type cannot be used to declare a structure or union field">;
def err_event_t_addr_space_qual : Error<
"the event_t type can only be used with __private address space qualifier">;
+def err_expected_kernel_void_return_type : Error<
+ "kernel must have void return type">;
} // end of sema category
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=173963&r1=173962&r2=173963&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Jan 30 13:48:52 2013
@@ -6227,7 +6227,14 @@ Sema::ActOnFunctionDeclarator(Scope *S,
Diag(D.getIdentifierLoc(), diag::err_static_kernel);
D.setInvalidType();
}
-
+
+ // OpenCL v1.2, s6.9 -- Kernels can only have return type void.
+ if (!NewFD->getResultType()->isVoidType()) {
+ Diag(D.getIdentifierLoc(),
+ diag::err_expected_kernel_void_return_type);
+ D.setInvalidType();
+ }
+
for (FunctionDecl::param_iterator PI = NewFD->param_begin(),
PE = NewFD->param_end(); PI != PE; ++PI) {
ParmVarDecl *Param = *PI;
Modified: cfe/trunk/test/SemaOpenCL/invalid-kernel.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/invalid-kernel.cl?rev=173963&r1=173962&r2=173963&view=diff
==============================================================================
--- cfe/trunk/test/SemaOpenCL/invalid-kernel.cl (original)
+++ cfe/trunk/test/SemaOpenCL/invalid-kernel.cl Wed Jan 30 13:48:52 2013
@@ -1,3 +1,7 @@
// RUN: %clang_cc1 -verify %s
kernel void no_ptrptr(global int **i) { } // expected-error{{kernel argument cannot be declared as a pointer to a pointer}}
+
+kernel int bar() { // expected-error {{kernel must have void return type}}
+ return 6;
+}
More information about the cfe-commits
mailing list