1 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
2 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -fcuda-is-device -verify %s
4 __attribute__((device)) void device_fn() {}
5 __attribute__((host, device)) void hd_fn() {}
7 __attribute__((device)) void device_attr() {
8 ([]() __attribute__((device)) { device_fn(); })();
9 // expected-warning@-1 {{nvcc does not allow '__device__' to appear after the parameter list in lambdas}}
10 ([] __attribute__((device)) () { device_fn(); })();
11 ([] __attribute__((device)) { device_fn(); })();
13 ([&]() __attribute__((device)){ device_fn(); })();
14 // expected-warning@-1 {{nvcc does not allow '__device__' to appear after the parameter list in lambdas}}
15 ([&] __attribute__((device)) () { device_fn(); })();
16 ([&] __attribute__((device)) { device_fn(); })();
18 ([&](int) __attribute__((device)){ device_fn(); })(0);
19 // expected-warning@-1 {{nvcc does not allow '__device__' to appear after the parameter list in lambdas}}
20 ([&] __attribute__((device)) (int) { device_fn(); })(0);
23 __attribute__((host)) __attribute__((device)) void host_device_attrs() {
24 ([]() __attribute__((host)) __attribute__((device)){ hd_fn(); })();
25 // expected-warning@-1 {{nvcc does not allow '__host__' to appear after the parameter list in lambdas}}
26 // expected-warning@-2 {{nvcc does not allow '__device__' to appear after the parameter list in lambdas}}
27 ([] __attribute__((host)) __attribute__((device)) () { hd_fn(); })();
28 ([] __attribute__((host)) __attribute__((device)) { hd_fn(); })();
30 ([&]() __attribute__((host)) __attribute__((device)){ hd_fn(); })();
31 // expected-warning@-1 {{nvcc does not allow '__host__' to appear after the parameter list in lambdas}}
32 // expected-warning@-2 {{nvcc does not allow '__device__' to appear after the parameter list in lambdas}}
33 ([&] __attribute__((host)) __attribute__((device)) () { hd_fn(); })();
34 ([&] __attribute__((host)) __attribute__((device)) { hd_fn(); })();
36 ([&](int) __attribute__((host)) __attribute__((device)){ hd_fn(); })(0);
37 // expected-warning@-1 {{nvcc does not allow '__host__' to appear after the parameter list in lambdas}}
38 // expected-warning@-2 {{nvcc does not allow '__device__' to appear after the parameter list in lambdas}}
39 ([&] __attribute__((host)) __attribute__((device)) (int) { hd_fn(); })(0);
42 // TODO: Add tests for __attribute__((global)) once we support global lambdas.