================
@@ -213,3 +188,163 @@ void test() {
 }
 
 } // namespace badref7
+
+
+#include <stdatomic.h>
+// Check for atomic parameters and subobjects.
+namespace atomic1 {
+// Kernel entry point template definition.
+template<typename KNT, typename T>
+[[clang::sycl_kernel_entry_point(KNT)]]
+void kernel_single_task(T t) {} // expected-note-re {{within parameter 't' of 
type '(lambda at {{.*}})' declared here}}
+                                // expected-note-re@-1 {{within parameter 't' 
of type '(lambda at {{.*}})' declared here}}
+                                // expected-note-re@-2 {{within parameter 't' 
of type '(lambda at {{.*}})' declared here}}
+                                // expected-note-re@-3 {{within parameter 't' 
of type '(lambda at {{.*}})' declared here}}
+                                // expected-note@-4 {{within parameter 't' of 
type 'atomic1::Kernel' declared here}}
+
+struct Sa { 
+  int a;
+  _Atomic int b; // expected-error {{'_Atomic(int)' cannot be used as the type 
of a kernel parameter}}
+                 // expected-note@-3 {{within field of type 'Sa' declared 
here}}
+                 // expected-error@-2 {{'_Atomic(int)' cannot be used as the 
type of a kernel parameter}}
+                 // expected-note@-5 {{within field of type 'Sa' declared 
here}}
+                 // expected-error@-4 {{'_Atomic(int)' cannot be used as the 
type of a kernel parameter}}
+                 // expected-note@-7 {{within field of type 'Sa' declared 
here}}
+};
+
+class Kernel {
+  Sa data{1, 2}; // expected-note@-1 {{within field of type 'Kernel' declared 
here}}
+public:
+  void operator()() { }
+};
+
+void test() {
+  _Atomic int a = 0;
+  _Atomic(int) b = 2;
+  Sa s{1, 2};
+  Sa arr[] = {s, s};
+  kernel_single_task<class KN<15>>([=]{ (void)a; });
+  // expected-error@-1 {{'_Atomic(int)' cannot be used as the type of a kernel 
parameter}}
+  // expected-note-re@-2 {{in instantiation of function template 
specialization 'atomic1::kernel_single_task<KN<{{[0-9]+}}>, {{.*}}>' requested 
here}}
+  // expected-note@-3 {{within capture 'a' of lambda expression here}}
+  kernel_single_task<class KN<16>>([=]{ (void)b; });
+  // expected-error@-1 {{'_Atomic(int)' cannot be used as the type of a kernel 
parameter}}
+  // expected-note-re@-2 {{in instantiation of function template 
specialization 'atomic1::kernel_single_task<KN<{{[0-9]+}}>, {{.*}}>' requested 
here}}
+  // expected-note@-3 {{within capture 'b' of lambda expression here}}
+  kernel_single_task<class KN<17>>([=]{ (void)s; });
+  // expected-note-re@-1 {{in instantiation of function template 
specialization 'atomic1::kernel_single_task<KN<{{[0-9]+}}>, {{.*}}>' requested 
here}}
+  // expected-note@-2 {{within capture 's' of lambda expression here}}
+  kernel_single_task<class KN<18>>([=]{ (void)arr; });
+  // expected-note-re@-1 {{in instantiation of function template 
specialization 'atomic1::kernel_single_task<KN<{{[0-9]+}}>, {{.*}}>' requested 
here}}
+  // expected-note@-2 {{within capture 'arr' of lambda expression here}}
+  kernel_single_task<class KN<19>>(Kernel{});
+  // expected-note-re@-1 {{in instantiation of function template 
specialization 'atomic1::kernel_single_task<KN<{{[0-9]+}}>, {{.*}}>' requested 
here}}
+}
+
+} // namespace atomic1
+
+// Check for flexible array members -- would not be copyable to device
+namespace fam1 {
+// Kernel entry point template definition.
+template<typename KNT, typename T>
+[[clang::sycl_kernel_entry_point(KNT)]]
+void kernel_single_task(T t) {} // expected-note {{within parameter 't' of 
type 'fam1::Kernel' declared here}}
+
+struct FAM { 
+  int a;
+  int b[];
+};
+
+class Kernel { // expected-note {{within field of type 'Kernel' declared here}}
+  FAM fam; // expected-error {{'FAM' contains a flexible array member and 
cannot be used as a SYCL kernel parameter}}
----------------
tahonermann wrote:

Actually, I don't think that (extra) AST recursion is needed. The subobject 
visitation will naturally recurse through class types that are a FAM because 
they contain a FAM. I think we just need to guard emit of the diagnostic both 
on `isStructureTypeWithFlexibleArrayMember()` being true and on the last 
non-static data member being an array with unknown bound (not an incomplete 
array type as I stated in my last comment; my mistake).

https://github.com/llvm/llvm-project/pull/208571
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to