r197243 - [OpenCL] Produce an error when the work group and vec type hint attributes

Joey Gouly joey.gouly at arm.com
Fri Dec 13 08:15:28 PST 2013


Author: joey
Date: Fri Dec 13 10:15:28 2013
New Revision: 197243

URL: http://llvm.org/viewvc/llvm-project?rev=197243&view=rev
Log:
[OpenCL] Produce an error when the work group and vec type hint attributes
are used on non-kernel functions.

Reviewed by Aaron over IRC!

Modified:
    cfe/trunk/include/clang/Basic/Attr.td
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaDeclAttr.cpp
    cfe/trunk/test/SemaOpenCL/invalid-kernel-attrs.cl

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=197243&r1=197242&r2=197243&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Fri Dec 13 10:15:28 2013
@@ -772,6 +772,7 @@ def ReqdWorkGroupSize : InheritableAttr
   let Spellings = [GNU<"reqd_work_group_size">];
   let Args = [UnsignedArgument<"XDim">, UnsignedArgument<"YDim">,
               UnsignedArgument<"ZDim">];
+  let Subjects = SubjectList<[Function], ErrorDiag>;
 }
 
 def WorkGroupSizeHint :  InheritableAttr {
@@ -779,6 +780,7 @@ def WorkGroupSizeHint :  InheritableAttr
   let Args = [UnsignedArgument<"XDim">, 
               UnsignedArgument<"YDim">,
               UnsignedArgument<"ZDim">];
+  let Subjects = SubjectList<[Function], ErrorDiag>;
 }
 
 def InitPriority : InheritableAttr {
@@ -877,6 +879,7 @@ def VectorSize : TypeAttr {
 def VecTypeHint : InheritableAttr {
   let Spellings = [GNU<"vec_type_hint">];
   let Args = [TypeArgument<"TypeHint">];
+  let Subjects = SubjectList<[Function], ErrorDiag>;
 }
 
 def Visibility : InheritableAttr {

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=197243&r1=197242&r2=197243&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Dec 13 10:15:28 2013
@@ -6728,6 +6728,8 @@ def err_wrong_sampler_addressspace: Erro
 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'">;
+def err_opencl_kernel_attr :
+  Error<"attribute '%0' can only be applied to a kernel function">;
 } // end of sema category
 
 let CategoryName = "OpenMP Issue" in {

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=197243&r1=197242&r2=197243&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Fri Dec 13 10:15:28 2013
@@ -4217,6 +4217,7 @@ void Sema::ProcessDeclAttributeList(Scop
   for (const AttributeList* l = AttrList; l; l = l->getNext())
     ProcessDeclAttribute(*this, S, D, *l, IncludeCXX11Attributes);
 
+  // FIXME: We should be able to handle these cases in TableGen.
   // GCC accepts
   // static int a9 __attribute__((weakref));
   // but that looks really pointless. We reject it.
@@ -4226,6 +4227,24 @@ void Sema::ProcessDeclAttributeList(Scop
     D->dropAttr<WeakRefAttr>();
     return;
   }
+
+  if (!D->hasAttr<OpenCLKernelAttr>()) {
+    // These attributes cannot be applied to a non-kernel function.
+    if (D->hasAttr<ReqdWorkGroupSizeAttr>()) {
+      Diag(D->getLocation(), diag::err_opencl_kernel_attr)
+          << "reqd_work_group_size";
+      D->setInvalidDecl();
+    }
+    if (D->hasAttr<WorkGroupSizeHintAttr>()) {
+      Diag(D->getLocation(), diag::err_opencl_kernel_attr)
+          << "work_group_size_hint";
+      D->setInvalidDecl();
+    }
+    if (D->hasAttr<VecTypeHintAttr>()) {
+      Diag(D->getLocation(), diag::err_opencl_kernel_attr) << "vec_type_hint";
+      D->setInvalidDecl();
+    }
+  }
 }
 
 // Annotation attributes are the only attributes allowed after an access

Modified: cfe/trunk/test/SemaOpenCL/invalid-kernel-attrs.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/invalid-kernel-attrs.cl?rev=197243&r1=197242&r2=197243&view=diff
==============================================================================
--- cfe/trunk/test/SemaOpenCL/invalid-kernel-attrs.cl (original)
+++ cfe/trunk/test/SemaOpenCL/invalid-kernel-attrs.cl Fri Dec 13 10:15:28 2013
@@ -14,3 +14,14 @@ kernel __attribute__((work_group_size_hi
 
 kernel __attribute__((work_group_size_hint(1,2,3))) __attribute__((work_group_size_hint(3,2,1))) void kernel7() {}  //expected-warning{{attribute 'work_group_size_hint' is already applied with different parameters}}
 
+__attribute__((reqd_work_group_size(8,16,32))) void kernel8(){} // expected-error {{attribute 'reqd_work_group_size' can only be applied to a kernel}}
+
+__attribute__((work_group_size_hint(8,16,32))) void kernel9(){} // expected-error {{attribute 'work_group_size_hint' can only be applied to a kernel}}
+
+__attribute__((vec_type_hint(char))) void kernel10(){} // expected-error {{attribute 'vec_type_hint' can only be applied to a kernel}}
+
+constant  int foo1 __attribute__((reqd_work_group_size(8,16,32))); // expected-error {{'reqd_work_group_size' attribute only applies to functions}}
+
+constant int foo2 __attribute__((work_group_size_hint(8,16,32))); // expected-error {{'work_group_size_hint' attribute only applies to functions}}
+
+constant int foo3 __attribute__((vec_type_hint(char))); // expected-error {{'vec_type_hint' attribute only applies to functions}}





More information about the cfe-commits mailing list