r194068 - Do not allow functions or kernels called 'main' in OpenCL.

Joey Gouly joey.gouly at arm.com
Tue Nov 5 04:30:40 PST 2013


Author: joey
Date: Tue Nov  5 06:30:39 2013
New Revision: 194068

URL: http://llvm.org/viewvc/llvm-project?rev=194068&view=rev
Log:
Do not allow functions or kernels called 'main' in OpenCL.

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=194068&r1=194067&r2=194068&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Nov  5 06:30:39 2013
@@ -6670,7 +6670,7 @@ def err_wrong_sampler_addressspace: Erro
   "sampler type cannot be used with the __local and __global address space qualifiers">;
 def err_opencl_global_invalid_addr_space : Error<
   "global variables must have a constant address space qualifier">;
-
+def err_opencl_no_main : Error<"%select{function|kernel}0 cannot be called 'main'">;
 } // end of sema category
 
 let CategoryName = "OpenMP Issue" in {

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=194068&r1=194067&r2=194068&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Nov  5 06:30:39 2013
@@ -7694,6 +7694,13 @@ void Sema::CheckMain(FunctionDecl* FD, c
     FD->setConstexpr(false);
   }
 
+  if (getLangOpts().OpenCL) {
+    Diag(FD->getLocation(), diag::err_opencl_no_main)
+        << FD->hasAttr<OpenCLKernelAttr>();
+    FD->setInvalidDecl();
+    return;
+  }
+
   QualType T = FD->getType();
   assert(T->isFunctionType() && "function decl is not of function type");
   const FunctionType* FT = T->castAs<FunctionType>();

Modified: cfe/trunk/test/SemaOpenCL/invalid-kernel.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/invalid-kernel.cl?rev=194068&r1=194067&r2=194068&view=diff
==============================================================================
--- cfe/trunk/test/SemaOpenCL/invalid-kernel.cl (original)
+++ cfe/trunk/test/SemaOpenCL/invalid-kernel.cl Tue Nov  5 06:30:39 2013
@@ -5,3 +5,11 @@ kernel void no_ptrptr(global int **i) {
 kernel int bar()  { // expected-error {{kernel must have void return type}}
   return 6;
 }
+
+kernel void main() { // expected-error {{kernel cannot be called 'main'}}
+
+}
+
+int main() { // expected-error {{function cannot be called 'main'}}
+  return 0;
+}





More information about the cfe-commits mailing list