|
1 | 1 | // RUN: %clang_cc1 -fsycl-is-device -fsyntax-only -Wno-sycl-2017-compat -verify %s
|
| 2 | +// |
| 3 | +// This test checks that the compiler issues an error on attempt to capture |
| 4 | +// "this" pointer by lambdas passed to the device code (directly and indirectly) |
2 | 5 |
|
3 |
| -template <typename name, typename Func> |
4 |
| -__attribute__((sycl_kernel)) void kernel(const Func &kernelFunc) { |
5 |
| - kernelFunc(); |
6 |
| -} |
| 6 | +#include "Inputs/sycl.hpp" |
| 7 | +using namespace cl::sycl; |
| 8 | +queue q; |
7 | 9 |
|
8 | 10 | class Class {
|
9 | 11 | public:
|
10 | 12 | Class() : member(1) {}
|
11 | 13 | void function();
|
| 14 | + void function2(); |
| 15 | + void function3(); |
12 | 16 | int member;
|
13 | 17 | };
|
14 | 18 |
|
| 19 | +void Class::function3() { |
| 20 | + auto Lambda = [=]() { |
| 21 | + int acc[1] = {5}; |
| 22 | + acc[0] *= member; |
| 23 | + }; |
| 24 | +} |
| 25 | + |
| 26 | +void Class::function2() { |
| 27 | + auto Lambda = [=]() { |
| 28 | + int acc[1] = {5}; |
| 29 | + acc[0] *= member; |
| 30 | + }; |
| 31 | + function3(); |
| 32 | +} |
| 33 | + |
15 | 34 | void Class::function() {
|
16 |
| - // expected-note@+1{{used here}} |
17 |
| - kernel<class kernel_wrapper>( |
18 |
| - [=]() { |
| 35 | + auto Lambda = [=]() { |
| 36 | + int acc[1] = {5}; |
| 37 | + acc[0] *= member; // expected-error 2{{implicit capture of 'this' is not allowed for kernel functions}} |
| 38 | + }; |
| 39 | + q.submit([&](handler &h) { |
| 40 | + // expected-note@+1 {{in instantiation of function template specialization}} |
| 41 | + h.single_task<class Simple>([=]() { |
| 42 | + int acc[1] = {5}; |
| 43 | + acc[0] *= member; // expected-error{{implicit capture of 'this' is not allowed for kernel functions}} |
| 44 | + }); |
| 45 | + }); |
| 46 | + q.submit([&](handler &h) { |
| 47 | + // expected-note@+1 {{in instantiation of function template specialization}} |
| 48 | + h.single_task<class CapturedOnDevice>([=]() { |
| 49 | + auto DeviceLambda = [=]() { |
19 | 50 | int acc[1] = {5};
|
20 | 51 | acc[0] *= member; // expected-error{{implicit capture of 'this' is not allowed for kernel functions}}
|
21 |
| - }); |
| 52 | + }; |
| 53 | + DeviceLambda(); |
| 54 | + }); |
| 55 | + }); |
| 56 | + q.submit([&](handler &h) { |
| 57 | + // expected-note@+1 {{in instantiation of function template specialization}} |
| 58 | + h.single_task<class CapturedOnDevice1>([=]() { |
| 59 | + // FIXME: That is probably not correct source location for a diagnostic |
| 60 | + function2(); // expected-error{{implicit capture of 'this' is not allowed for kernel functions}} |
| 61 | + }); |
| 62 | + }); |
| 63 | + q.submit([&](handler &h) { |
| 64 | + // expected-note@+1 {{in instantiation of function template specialization}} |
| 65 | + h.single_task<class CapturedOnDevice2>([=]() { |
| 66 | + // FIXME: That is probably not correct source location for a diagnostic |
| 67 | + function3(); // expected-error{{implicit capture of 'this' is not allowed for kernel functions}} |
| 68 | + }); |
| 69 | + }); |
| 70 | + q.submit([&](handler &h) { |
| 71 | + // expected-note@+1 {{in instantiation of function template specialization}} |
| 72 | + h.single_task<class CapturedOnHost>([=]() { |
| 73 | + Lambda(); |
| 74 | + }); |
| 75 | + }); |
| 76 | + q.submit([&](handler &h) { |
| 77 | + // expected-note@+1 {{in instantiation of function template specialization}} |
| 78 | + h.single_task<class CapturedOnHost1>([Lambda]() { |
| 79 | + }); |
| 80 | + }); |
| 81 | + auto InnerLambda = [=]() { |
| 82 | + int A = 2 + member; // expected-error {{implicit capture of 'this' is not allowed for kernel functions}} |
| 83 | + }; |
| 84 | + auto ExternalLambda = [=]() { |
| 85 | + InnerLambda(); |
| 86 | + }; |
| 87 | + q.submit([&](handler &h) { |
| 88 | + // expected-note@+1 {{in instantiation of function template specialization}} |
| 89 | + h.single_task<class CapturedOnHost2>([=]() { |
| 90 | + ExternalLambda(); |
| 91 | + }); |
| 92 | + }); |
22 | 93 | }
|
23 | 94 |
|
24 | 95 | int main(int argc, char *argv[]) {
|
|
0 commit comments