invalid-kernel-parameters.cl 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. // RUN: %clang_cc1 -fsyntax-only -verify %s -triple spir-unknown-unknown
  2. kernel void half_arg(half x) { } // expected-error{{declaring function parameter of type 'half' is not allowed; did you forget * ?}}
  3. #pragma OPENCL EXTENSION cl_khr_fp16 : enable
  4. // Disallowed: parameters with type
  5. // bool, half, size_t, ptrdiff_t, intptr_t, and uintptr_t
  6. // or a struct / union with any of these types in them
  7. typedef __SIZE_TYPE__ size_t; // expected-note{{'size_t' (aka 'unsigned int') declared here}}
  8. // expected-note@-1{{'size_t' (aka 'unsigned int') declared here}}
  9. typedef __PTRDIFF_TYPE__ ptrdiff_t; // expected-note{{'ptrdiff_t' (aka 'int') declared here}}
  10. typedef __INTPTR_TYPE__ intptr_t; // expected-note{{'intptr_t' (aka 'int') declared here}}
  11. typedef __UINTPTR_TYPE__ uintptr_t; // expected-note{{'uintptr_t' (aka 'unsigned int') declared here}}
  12. kernel void size_t_arg(size_t x) {} // expected-error{{'size_t' (aka 'unsigned int') cannot be used as the type of a kernel parameter}}
  13. kernel void ptrdiff_t_arg(ptrdiff_t x) {} // expected-error{{'ptrdiff_t' (aka 'int') cannot be used as the type of a kernel parameter}}
  14. kernel void intptr_t_arg(intptr_t x) {} // expected-error{{'intptr_t' (aka 'int') cannot be used as the type of a kernel parameter}}
  15. kernel void uintptr_t_arg(uintptr_t x) {} // expected-error{{'uintptr_t' (aka 'unsigned int') cannot be used as the type of a kernel parameter}}
  16. typedef size_t size_ty;
  17. struct SizeTStruct { // expected-note{{within field of type 'SizeTStruct' declared here}}
  18. size_ty s; // expected-note{{field of illegal type 'size_ty' (aka 'unsigned int') declared here}}
  19. };
  20. kernel void size_t_struct_arg(struct SizeTStruct x) {} // expected-error{{'struct SizeTStruct' cannot be used as the type of a kernel parameter}}
  21. union SizeTUnion { // expected-note{{within field of type 'SizeTUnion' declared here}}
  22. size_t s; // expected-note{{field of illegal type 'size_t' (aka 'unsigned int') declared here}}
  23. float f;
  24. };
  25. kernel void size_t_union_arg(union SizeTUnion x) {} // expected-error{{'union SizeTUnion' cannot be used as the type of a kernel parameter}}
  26. typedef size_t s_ty; // expected-note{{'s_ty' (aka 'unsigned int') declared here}}
  27. typedef s_ty ss_ty; // expected-note{{'ss_ty' (aka 'unsigned int') declared here}}
  28. kernel void typedef_to_size_t(ss_ty s) {} // expected-error{{'ss_ty' (aka 'unsigned int') cannot be used as the type of a kernel parameter}}
  29. kernel void bool_arg(bool x) { } // expected-error{{'bool' cannot be used as the type of a kernel parameter}}
  30. // half kernel argument is allowed when cl_khr_fp16 is enabled.
  31. kernel void half_arg(half x) { }
  32. typedef struct ContainsBool // expected-note{{within field of type 'ContainsBool' declared here}}
  33. {
  34. bool x; // expected-note{{field of illegal type 'bool' declared here}}
  35. } ContainsBool;
  36. kernel void bool_in_struct_arg(ContainsBool x) { } // expected-error{{'ContainsBool' (aka 'struct ContainsBool') cannot be used as the type of a kernel parameter}}
  37. typedef struct FooImage2D // expected-note{{within field of type 'FooImage2D' declared here}}
  38. {
  39. // TODO: Clean up needed - we don't really need to check for image, event, etc
  40. // as a note here any longer.
  41. // They are diagnosed as an error for all struct fields (OpenCL v1.2 s6.9b,r).
  42. image2d_t imageField; // expected-note{{field of illegal type '__read_only image2d_t' declared here}} expected-error{{the '__read_only image2d_t' type cannot be used to declare a structure or union field}}
  43. } FooImage2D;
  44. kernel void image_in_struct_arg(FooImage2D arg) { } // expected-error{{struct kernel parameters may not contain pointers}}
  45. typedef struct Foo // expected-note{{within field of type 'Foo' declared here}}
  46. {
  47. int* ptrField; // expected-note{{field of illegal pointer type 'int *' declared here}}
  48. } Foo;
  49. kernel void pointer_in_struct_arg(Foo arg) { } // expected-error{{struct kernel parameters may not contain pointers}}
  50. typedef union FooUnion // expected-note{{within field of type 'FooUnion' declared here}}
  51. {
  52. int* ptrField; // expected-note{{field of illegal pointer type 'int *' declared here}}
  53. } FooUnion;
  54. kernel void pointer_in_union_arg(FooUnion arg) { }// expected-error{{union kernel parameters may not contain pointers}}
  55. typedef struct NestedPointer // expected-note 2 {{within field of type 'NestedPointer' declared here}}
  56. {
  57. int x;
  58. struct InnerNestedPointer
  59. {
  60. int* ptrField; // expected-note 3 {{field of illegal pointer type 'int *' declared here}}
  61. } inner; // expected-note 3 {{within field of type 'struct InnerNestedPointer' declared here}}
  62. } NestedPointer;
  63. kernel void pointer_in_nested_struct_arg(NestedPointer arg) { }// expected-error{{struct kernel parameters may not contain pointers}}
  64. struct NestedPointerComplex // expected-note{{within field of type 'NestedPointerComplex' declared here}}
  65. {
  66. int foo;
  67. float bar;
  68. struct InnerNestedPointerComplex
  69. {
  70. int innerFoo;
  71. int* innerPtrField; // expected-note{{field of illegal pointer type 'int *' declared here}}
  72. } inner; // expected-note{{within field of type 'struct InnerNestedPointerComplex' declared here}}
  73. float y;
  74. float z[4];
  75. };
  76. kernel void pointer_in_nested_struct_arg_complex(struct NestedPointerComplex arg) { }// expected-error{{struct kernel parameters may not contain pointers}}
  77. typedef struct NestedBool // expected-note 2 {{within field of type 'NestedBool' declared here}}
  78. {
  79. int x;
  80. struct InnerNestedBool
  81. {
  82. bool boolField; // expected-note 2 {{field of illegal type 'bool' declared here}}
  83. } inner; // expected-note 2 {{within field of type 'struct InnerNestedBool' declared here}}
  84. } NestedBool;
  85. kernel void bool_in_nested_struct_arg(NestedBool arg) { } // expected-error{{'NestedBool' (aka 'struct NestedBool') cannot be used as the type of a kernel parameter}}
  86. // Warning emitted again for argument used in other kernel
  87. kernel void bool_in_nested_struct_arg_again(NestedBool arg) { } // expected-error{{'NestedBool' (aka 'struct NestedBool') cannot be used as the type of a kernel parameter}}
  88. // Check for note with a struct not defined inside the struct
  89. typedef struct NestedBool2Inner
  90. {
  91. bool boolField; // expected-note{{field of illegal type 'bool' declared here}}
  92. } NestedBool2Inner;
  93. typedef struct NestedBool2 // expected-note{{within field of type 'NestedBool2' declared here}}
  94. {
  95. int x;
  96. NestedBool2Inner inner; // expected-note{{within field of type 'NestedBool2Inner' (aka 'struct NestedBool2Inner') declared here}}
  97. } NestedBool2;
  98. kernel void bool_in_nested_struct_2_arg(NestedBool2 arg) { } // expected-error{{'NestedBool2' (aka 'struct NestedBool2') cannot be used as the type of a kernel parameter}}
  99. struct InnerInner
  100. {
  101. int* foo;
  102. bool x;
  103. };
  104. struct Valid
  105. {
  106. float c;
  107. float d;
  108. };
  109. struct Inner
  110. {
  111. struct Valid v;
  112. struct InnerInner a;
  113. struct Valid g;
  114. struct InnerInner b;
  115. };
  116. struct AlsoUser // expected-note{{within field of type 'AlsoUser' declared here}}
  117. {
  118. float x;
  119. struct Valid valid1;
  120. struct Valid valid2;
  121. struct NestedPointer aaaa; // expected-note{{within field of type 'struct NestedPointer' declared here}}
  122. };
  123. kernel void pointer_in_nested_struct_arg_2(struct Valid valid, struct NestedPointer arg, struct AlsoUser also) { } // expected-error 2 {{struct kernel parameters may not contain pointers}}
  124. struct ArrayOfPtr // expected-note{{within field of type 'ArrayOfPtr' declared here}}
  125. {
  126. float *arr[3]; // expected-note{{field of illegal type 'float *[3]' declared here}}
  127. // expected-note@-1{{field of illegal type 'float *[3]' declared here}}
  128. };
  129. kernel void array_of_ptr(struct ArrayOfPtr arr) {} // expected-error{{struct kernel parameters may not contain pointers}}
  130. struct ArrayOfStruct // expected-note{{within field of type 'ArrayOfStruct' declared here}}
  131. {
  132. struct ArrayOfPtr arr[3]; // expected-note{{within field of type 'struct ArrayOfPtr [3]' declared here}}
  133. };
  134. kernel void array_of_struct(struct ArrayOfStruct arr) {} // expected-error{{struct kernel parameters may not contain pointers}}