| 1 | // RUN: %clang_cc1 %s --std=c++11 -triple x86_64-linux-unknown -fsyntax-only -o - -verify |
| 2 | |
| 3 | #include "Inputs/cuda.h" |
| 4 | |
| 5 | // Check that we get an error if we try to call a __device__ function from a |
| 6 | // module initializer. |
| 7 | |
| 8 | struct S { |
| 9 | __device__ S() {} |
| 10 | // expected-note@-1 {{'S' declared here}} |
| 11 | }; |
| 12 | |
| 13 | S s; |
| 14 | // expected-error@-1 {{reference to __device__ function 'S' in global initializer}} |
| 15 | |
| 16 | struct T { |
| 17 | __host__ __device__ T() {} |
| 18 | }; |
| 19 | T t; // No error, this is OK. |
| 20 | |
| 21 | struct U { |
| 22 | __host__ U() {} |
| 23 | __device__ U(int) {} |
| 24 | // expected-note@-1 {{'U' declared here}} |
| 25 | }; |
| 26 | U u(42); |
| 27 | // expected-error@-1 {{reference to __device__ function 'U' in global initializer}} |
| 28 | |
| 29 | __device__ int device_fn() { return 42; } |
| 30 | // expected-note@-1 {{'device_fn' declared here}} |
| 31 | int n = device_fn(); |
| 32 | // expected-error@-1 {{reference to __device__ function 'device_fn' in global initializer}} |
| 33 | |