Justin Lebar | 18e2d82 | 2016-08-15 23:00:49 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 %s --std=c++11 -triple nvptx-unknown-unknown -fcuda-is-device -emit-llvm -o - -verify |
| 2 | |
| 3 | // Note: This test won't work with -fsyntax-only, because some of these errors |
| 4 | // are emitted during codegen. |
| 5 | |
| 6 | #include "Inputs/cuda.h" |
| 7 | |
| 8 | extern "C" void host_fn() {} |
Justin Lebar | 26bb311 | 2016-08-16 00:48:21 +0000 | [diff] [blame] | 9 | // expected-note@-1 {{'host_fn' declared here}} |
| 10 | // expected-note@-2 {{'host_fn' declared here}} |
| 11 | // expected-note@-3 {{'host_fn' declared here}} |
| 12 | // expected-note@-4 {{'host_fn' declared here}} |
| 13 | // expected-note@-5 {{'host_fn' declared here}} |
| 14 | // expected-note@-6 {{'host_fn' declared here}} |
Justin Lebar | 18e2d82 | 2016-08-15 23:00:49 +0000 | [diff] [blame] | 15 | |
| 16 | struct S { |
| 17 | S() {} |
Justin Lebar | 26bb311 | 2016-08-16 00:48:21 +0000 | [diff] [blame] | 18 | // expected-note@-1 {{'S' declared here}} |
| 19 | // expected-note@-2 {{'S' declared here}} |
Justin Lebar | 18e2d82 | 2016-08-15 23:00:49 +0000 | [diff] [blame] | 20 | ~S() { host_fn(); } |
Justin Lebar | 26bb311 | 2016-08-16 00:48:21 +0000 | [diff] [blame] | 21 | // expected-note@-1 {{'~S' declared here}} |
Justin Lebar | 18e2d82 | 2016-08-15 23:00:49 +0000 | [diff] [blame] | 22 | int x; |
| 23 | }; |
| 24 | |
| 25 | struct T { |
| 26 | __host__ __device__ void hd() { host_fn(); } |
| 27 | // expected-error@-1 {{reference to __host__ function 'host_fn' in __host__ __device__ function}} |
| 28 | |
| 29 | // No error; this is (implicitly) inline and is never called, so isn't |
| 30 | // codegen'ed. |
| 31 | __host__ __device__ void hd2() { host_fn(); } |
| 32 | |
| 33 | __host__ __device__ void hd3(); |
| 34 | |
| 35 | void h() {} |
Justin Lebar | 26bb311 | 2016-08-16 00:48:21 +0000 | [diff] [blame] | 36 | // expected-note@-1 {{'h' declared here}} |
Justin Lebar | 18e2d82 | 2016-08-15 23:00:49 +0000 | [diff] [blame] | 37 | }; |
| 38 | |
| 39 | __host__ __device__ void T::hd3() { |
| 40 | host_fn(); |
| 41 | // expected-error@-1 {{reference to __host__ function 'host_fn' in __host__ __device__ function}} |
| 42 | } |
| 43 | |
| 44 | template <typename T> __host__ __device__ void hd2() { host_fn(); } |
| 45 | // expected-error@-1 {{reference to __host__ function 'host_fn' in __host__ __device__ function}} |
| 46 | __global__ void kernel() { hd2<int>(); } |
| 47 | |
| 48 | __host__ __device__ void hd() { host_fn(); } |
| 49 | // expected-error@-1 {{reference to __host__ function 'host_fn' in __host__ __device__ function}} |
| 50 | |
| 51 | template <typename T> __host__ __device__ void hd3() { host_fn(); } |
| 52 | // expected-error@-1 {{reference to __host__ function 'host_fn' in __host__ __device__ function}} |
| 53 | __device__ void device_fn() { hd3<int>(); } |
| 54 | |
| 55 | // No error because this is never instantiated. |
| 56 | template <typename T> __host__ __device__ void hd4() { host_fn(); } |
| 57 | |
| 58 | __host__ __device__ void local_var() { |
| 59 | S s; |
| 60 | // expected-error@-1 {{reference to __host__ function 'S' in __host__ __device__ function}} |
| 61 | } |
| 62 | |
| 63 | __host__ __device__ void placement_new(char *ptr) { |
| 64 | ::new(ptr) S(); |
| 65 | // expected-error@-1 {{reference to __host__ function 'S' in __host__ __device__ function}} |
| 66 | } |
| 67 | |
| 68 | __host__ __device__ void explicit_destructor(S *s) { |
| 69 | s->~S(); |
| 70 | // expected-error@-1 {{reference to __host__ function '~S' in __host__ __device__ function}} |
| 71 | } |
| 72 | |
| 73 | __host__ __device__ void hd_member_fn() { |
| 74 | T t; |
| 75 | // Necessary to trigger an error on T::hd. It's (implicitly) inline, so |
| 76 | // isn't codegen'ed until we call it. |
| 77 | t.hd(); |
| 78 | } |
| 79 | |
| 80 | __host__ __device__ void h_member_fn() { |
| 81 | T t; |
| 82 | t.h(); |
| 83 | // expected-error@-1 {{reference to __host__ function 'h' in __host__ __device__ function}} |
| 84 | } |
| 85 | |
| 86 | __host__ __device__ void fn_ptr() { |
| 87 | auto* ptr = &host_fn; |
| 88 | // expected-error@-1 {{reference to __host__ function 'host_fn' in __host__ __device__ function}} |
| 89 | } |
| 90 | |
| 91 | template <typename T> |
| 92 | __host__ __device__ void fn_ptr_template() { |
| 93 | auto* ptr = &host_fn; // Not an error because the template isn't instantiated. |
| 94 | } |