llvm-project
82 строки · 2.9 Кб
1// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify=com %s
2// RUN: %clang_cc1 -std=c++17 -fsyntax-only -fcuda-is-device -verify=com,dev,warn %s
3// RUN: %clang_cc1 -std=c++17 -fsyntax-only -fcuda-is-device -verify=com,dev,warn \
4// RUN: -triple amdgcn-amd-amdhsa -target-cpu gfx906 -x hip %s
5// RUN: %clang_cc1 -std=c++17 -fsyntax-only -fcuda-is-device -verify=com,dev \
6// RUN: -Wno-gpu-maybe-wrong-side %s
7
8#include "Inputs/cuda.h"
9
10auto global_lambda = [] () { return 123; };
11
12template<class F>
13__global__ void kernel(F f) { f(); }
14// dev-note@-1 3{{called by 'kernel<(lambda}}
15// warn-note@-2 5{{called by 'kernel<(lambda}}
16
17__host__ __device__ void hd(int x);
18
19class A {
20int b;
21public:
22void test() {
23[=](){ hd(b); }();
24
25[&](){ hd(b); }();
26
27kernel<<<1,1>>>([](){ hd(0); });
28
29kernel<<<1,1>>>([=](){ hd(b); });
30// warn-warning@-1 {{capture host side class data member by this pointer in device or host device lambda function may result in invalid memory access if this pointer is not accessible on device side}}
31
32kernel<<<1,1>>>([&](){ hd(b); });
33// warn-warning@-1 {{capture host side class data member by this pointer in device or host device lambda function may result in invalid memory access if this pointer is not accessible on device side}}
34
35kernel<<<1,1>>>([&] __device__ (){ hd(b); });
36// warn-warning@-1 {{capture host side class data member by this pointer in device or host device lambda function may result in invalid memory access if this pointer is not accessible on device side}}
37
38kernel<<<1,1>>>([&](){
39auto f = [&]{ hd(b); };
40// warn-warning@-1 {{capture host side class data member by this pointer in device or host device lambda function may result in invalid memory access if this pointer is not accessible on device side}}
41f();
42});
43
44auto lambda1 = [this] __device__ { hd(this->b); };
45// warn-warning@-1 {{capture host side class data member by this pointer in device or host device lambda function may result in invalid memory access if this pointer is not accessible on device side}}
46kernel<<<1,1>>>(lambda1);
47}
48};
49
50int main(void) {
51auto lambda_kernel = [&]__global__(){};
52// com-error@-1 {{kernel function 'operator()' must be a free function or static member function}}
53
54int b;
55[&](){ hd(b); }();
56
57[=, &b](){ hd(b); }();
58
59kernel<<<1,1>>>(global_lambda);
60
61kernel<<<1,1>>>([](){ hd(0); });
62
63kernel<<<1,1>>>([=](){ hd(b); });
64
65kernel<<<1,1>>>([b](){ hd(b); });
66
67kernel<<<1,1>>>([&](){ hd(b); });
68// dev-error@-1 {{capture host variable 'b' by reference in device or host device lambda function}}
69
70kernel<<<1,1>>>([=, &b](){ hd(b); });
71// dev-error@-1 {{capture host variable 'b' by reference in device or host device lambda function}}
72
73kernel<<<1,1>>>([&, b](){ hd(b); });
74
75kernel<<<1,1>>>([&](){
76auto f = [&]{ hd(b); };
77// dev-error@-1 {{capture host variable 'b' by reference in device or host device lambda function}}
78f();
79});
80
81return 0;
82}
83