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() {} |
| 9 | |
| 10 | struct S { |
| 11 | S() {} |
| 12 | ~S() { host_fn(); } |
| 13 | int x; |
| 14 | }; |
| 15 | |
| 16 | struct T { |
| 17 | __host__ __device__ void hd() { host_fn(); } |
| 18 | // expected-error@-1 {{reference to __host__ function 'host_fn' in __host__ __device__ function}} |
| 19 | |
| 20 | // No error; this is (implicitly) inline and is never called, so isn't |
| 21 | // codegen'ed. |
| 22 | __host__ __device__ void hd2() { host_fn(); } |
| 23 | |
| 24 | __host__ __device__ void hd3(); |
| 25 | |
| 26 | void h() {} |
| 27 | }; |
| 28 | |
| 29 | __host__ __device__ void T::hd3() { |
| 30 | host_fn(); |
| 31 | // expected-error@-1 {{reference to __host__ function 'host_fn' in __host__ __device__ function}} |
| 32 | } |
| 33 | |
| 34 | template <typename T> __host__ __device__ void hd2() { host_fn(); } |
| 35 | // expected-error@-1 {{reference to __host__ function 'host_fn' in __host__ __device__ function}} |
| 36 | __global__ void kernel() { hd2<int>(); } |
| 37 | |
| 38 | __host__ __device__ void hd() { host_fn(); } |
| 39 | // expected-error@-1 {{reference to __host__ function 'host_fn' in __host__ __device__ function}} |
| 40 | |
| 41 | template <typename T> __host__ __device__ void hd3() { host_fn(); } |
| 42 | // expected-error@-1 {{reference to __host__ function 'host_fn' in __host__ __device__ function}} |
| 43 | __device__ void device_fn() { hd3<int>(); } |
| 44 | |
| 45 | // No error because this is never instantiated. |
| 46 | template <typename T> __host__ __device__ void hd4() { host_fn(); } |
| 47 | |
| 48 | __host__ __device__ void local_var() { |
| 49 | S s; |
| 50 | // expected-error@-1 {{reference to __host__ function 'S' in __host__ __device__ function}} |
| 51 | } |
| 52 | |
| 53 | __host__ __device__ void placement_new(char *ptr) { |
| 54 | ::new(ptr) S(); |
| 55 | // expected-error@-1 {{reference to __host__ function 'S' in __host__ __device__ function}} |
| 56 | } |
| 57 | |
| 58 | __host__ __device__ void explicit_destructor(S *s) { |
| 59 | s->~S(); |
| 60 | // expected-error@-1 {{reference to __host__ function '~S' in __host__ __device__ function}} |
| 61 | } |
| 62 | |
| 63 | __host__ __device__ void hd_member_fn() { |
| 64 | T t; |
| 65 | // Necessary to trigger an error on T::hd. It's (implicitly) inline, so |
| 66 | // isn't codegen'ed until we call it. |
| 67 | t.hd(); |
| 68 | } |
| 69 | |
| 70 | __host__ __device__ void h_member_fn() { |
| 71 | T t; |
| 72 | t.h(); |
| 73 | // expected-error@-1 {{reference to __host__ function 'h' in __host__ __device__ function}} |
| 74 | } |
| 75 | |
| 76 | __host__ __device__ void fn_ptr() { |
| 77 | auto* ptr = &host_fn; |
| 78 | // expected-error@-1 {{reference to __host__ function 'host_fn' in __host__ __device__ function}} |
| 79 | } |
| 80 | |
| 81 | template <typename T> |
| 82 | __host__ __device__ void fn_ptr_template() { |
| 83 | auto* ptr = &host_fn; // Not an error because the template isn't instantiated. |
| 84 | } |