blob: dfd6fc8ecdddb4263e36961d3272fac8204d916d [file] [log] [blame]
Justin Lebar0fad0ba2016-09-30 17:14:48 +00001// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
2// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fcuda-is-device -verify %s
3
Justin Lebar0fad0ba2016-09-30 17:14:48 +00004__attribute__((device)) void device_fn() {}
5__attribute__((device)) void hd_fn() {}
6
7__attribute__((device)) void device_attr() {
8 ([]() __attribute__((device)) { device_fn(); })();
Justin Lebare46ea722016-09-30 19:55:55 +00009 // expected-warning@-1 {{nvcc does not allow '__device__' to appear after '()' in lambdas}}
Justin Lebar0fad0ba2016-09-30 17:14:48 +000010 ([] __attribute__((device)) () { device_fn(); })();
11 ([] __attribute__((device)) { device_fn(); })();
12
13 ([&]() __attribute__((device)){ device_fn(); })();
Justin Lebare46ea722016-09-30 19:55:55 +000014 // expected-warning@-1 {{nvcc does not allow '__device__' to appear after '()' in lambdas}}
Justin Lebar0fad0ba2016-09-30 17:14:48 +000015 ([&] __attribute__((device)) () { device_fn(); })();
16 ([&] __attribute__((device)) { device_fn(); })();
17
18 ([&](int) __attribute__((device)){ device_fn(); })(0);
Justin Lebare46ea722016-09-30 19:55:55 +000019 // expected-warning@-1 {{nvcc does not allow '__device__' to appear after '()' in lambdas}}
Justin Lebar0fad0ba2016-09-30 17:14:48 +000020 ([&] __attribute__((device)) (int) { device_fn(); })(0);
21}
22
23__attribute__((host)) __attribute__((device)) void host_device_attrs() {
24 ([]() __attribute__((host)) __attribute__((device)){ hd_fn(); })();
Justin Lebare46ea722016-09-30 19:55:55 +000025 // expected-warning@-1 {{nvcc does not allow '__host__' to appear after '()' in lambdas}}
26 // expected-warning@-2 {{nvcc does not allow '__device__' to appear after '()' in lambdas}}
Justin Lebar0fad0ba2016-09-30 17:14:48 +000027 ([] __attribute__((host)) __attribute__((device)) () { hd_fn(); })();
28 ([] __attribute__((host)) __attribute__((device)) { hd_fn(); })();
29
30 ([&]() __attribute__((host)) __attribute__((device)){ hd_fn(); })();
Justin Lebare46ea722016-09-30 19:55:55 +000031 // expected-warning@-1 {{nvcc does not allow '__host__' to appear after '()' in lambdas}}
32 // expected-warning@-2 {{nvcc does not allow '__device__' to appear after '()' in lambdas}}
Justin Lebar0fad0ba2016-09-30 17:14:48 +000033 ([&] __attribute__((host)) __attribute__((device)) () { hd_fn(); })();
34 ([&] __attribute__((host)) __attribute__((device)) { hd_fn(); })();
35
36 ([&](int) __attribute__((host)) __attribute__((device)){ hd_fn(); })(0);
Justin Lebare46ea722016-09-30 19:55:55 +000037 // expected-warning@-1 {{nvcc does not allow '__host__' to appear after '()' in lambdas}}
38 // expected-warning@-2 {{nvcc does not allow '__device__' to appear after '()' in lambdas}}
Justin Lebar0fad0ba2016-09-30 17:14:48 +000039 ([&] __attribute__((host)) __attribute__((device)) (int) { hd_fn(); })(0);
40}
Justin Lebare46ea722016-09-30 19:55:55 +000041
42// TODO: Add tests for __attribute__((global)) once we support global lambdas.