]> granicus.if.org Git - clang/commitdiff
Do not allow functions or kernels called 'main' in OpenCL.
authorJoey Gouly <joey.gouly@arm.com>
Tue, 5 Nov 2013 12:30:39 +0000 (12:30 +0000)
committerJoey Gouly <joey.gouly@arm.com>
Tue, 5 Nov 2013 12:30:39 +0000 (12:30 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@194068 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaDecl.cpp
test/SemaOpenCL/invalid-kernel.cl

index c1c701db08f8c49a9b3d3c01a27fcfff0848a04d..ea0df85d72e25abb78ea24ddf8256606fc78425d 100644 (file)
@@ -6670,7 +6670,7 @@ def err_wrong_sampler_addressspace: Error<
   "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 {
index d9dd4507de6202eec33b0ca13031b38122e508b5..222b70cdab8a3459ff5e8b92ac86c96345690840 100644 (file)
@@ -7694,6 +7694,13 @@ void Sema::CheckMain(FunctionDecl* FD, const DeclSpec& DS) {
     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>();
index 3eb2f71aafb344be3cc735394d6ebb4d1854a985..c12bd8414e27821ecc12b3d9ab43fe8c48b2a320 100644 (file)
@@ -5,3 +5,11 @@ kernel void no_ptrptr(global int **i) { } // expected-error{{kernel parameter ca
 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;
+}