Justin Lebar | 23d9542 | 2016-10-13 20:52:12 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 %s --std=c++11 -triple nvptx-unknown-unknown -fcuda-is-device \ |
Justin Lebar | 6c86e91 | 2016-10-19 21:15:01 +0000 | [diff] [blame^] | 2 | // RUN: -emit-llvm -o /dev/null -verify -verify-ignore-unexpected=note |
Justin Lebar | 18e2d82 | 2016-08-15 23:00:49 +0000 | [diff] [blame] | 3 | |
| 4 | // Note: This test won't work with -fsyntax-only, because some of these errors |
| 5 | // are emitted during codegen. |
| 6 | |
| 7 | #include "Inputs/cuda.h" |
| 8 | |
| 9 | extern "C" void host_fn() {} |
Justin Lebar | 26bb311 | 2016-08-16 00:48:21 +0000 | [diff] [blame] | 10 | // expected-note@-1 {{'host_fn' declared here}} |
| 11 | // expected-note@-2 {{'host_fn' declared here}} |
| 12 | // expected-note@-3 {{'host_fn' declared here}} |
| 13 | // expected-note@-4 {{'host_fn' declared here}} |
| 14 | // expected-note@-5 {{'host_fn' declared here}} |
| 15 | // expected-note@-6 {{'host_fn' declared here}} |
Justin Lebar | 9fdb46e | 2016-10-08 01:07:11 +0000 | [diff] [blame] | 16 | // expected-note@-7 {{'host_fn' declared here}} |
| 17 | |
| 18 | struct Dummy {}; |
Justin Lebar | 18e2d82 | 2016-08-15 23:00:49 +0000 | [diff] [blame] | 19 | |
| 20 | struct S { |
| 21 | S() {} |
Justin Lebar | 26bb311 | 2016-08-16 00:48:21 +0000 | [diff] [blame] | 22 | // expected-note@-1 {{'S' declared here}} |
| 23 | // expected-note@-2 {{'S' declared here}} |
Justin Lebar | 18e2d82 | 2016-08-15 23:00:49 +0000 | [diff] [blame] | 24 | ~S() { host_fn(); } |
Justin Lebar | 26bb311 | 2016-08-16 00:48:21 +0000 | [diff] [blame] | 25 | // expected-note@-1 {{'~S' declared here}} |
Justin Lebar | 18e2d82 | 2016-08-15 23:00:49 +0000 | [diff] [blame] | 26 | int x; |
| 27 | }; |
| 28 | |
| 29 | struct T { |
| 30 | __host__ __device__ void hd() { host_fn(); } |
| 31 | // expected-error@-1 {{reference to __host__ function 'host_fn' in __host__ __device__ function}} |
| 32 | |
| 33 | // No error; this is (implicitly) inline and is never called, so isn't |
| 34 | // codegen'ed. |
| 35 | __host__ __device__ void hd2() { host_fn(); } |
| 36 | |
| 37 | __host__ __device__ void hd3(); |
| 38 | |
| 39 | void h() {} |
Justin Lebar | 26bb311 | 2016-08-16 00:48:21 +0000 | [diff] [blame] | 40 | // expected-note@-1 {{'h' declared here}} |
Justin Lebar | 9fdb46e | 2016-10-08 01:07:11 +0000 | [diff] [blame] | 41 | |
| 42 | void operator+(); |
| 43 | // expected-note@-1 {{'operator+' declared here}} |
| 44 | |
| 45 | void operator-(const T&) {} |
| 46 | // expected-note@-1 {{'operator-' declared here}} |
| 47 | |
| 48 | operator Dummy() { return Dummy(); } |
| 49 | // expected-note@-1 {{'operator Dummy' declared here}} |
Richard Smith | f75dcbe | 2016-10-11 00:21:10 +0000 | [diff] [blame] | 50 | |
| 51 | __host__ void operator delete(void*); |
| 52 | __device__ void operator delete(void*, size_t); |
| 53 | }; |
| 54 | |
| 55 | struct U { |
| 56 | __device__ void operator delete(void*, size_t) = delete; |
| 57 | __host__ __device__ void operator delete(void*); |
Justin Lebar | 18e2d82 | 2016-08-15 23:00:49 +0000 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | __host__ __device__ void T::hd3() { |
| 61 | host_fn(); |
| 62 | // expected-error@-1 {{reference to __host__ function 'host_fn' in __host__ __device__ function}} |
| 63 | } |
| 64 | |
| 65 | template <typename T> __host__ __device__ void hd2() { host_fn(); } |
| 66 | // expected-error@-1 {{reference to __host__ function 'host_fn' in __host__ __device__ function}} |
| 67 | __global__ void kernel() { hd2<int>(); } |
| 68 | |
| 69 | __host__ __device__ void hd() { host_fn(); } |
| 70 | // expected-error@-1 {{reference to __host__ function 'host_fn' in __host__ __device__ function}} |
| 71 | |
| 72 | template <typename T> __host__ __device__ void hd3() { host_fn(); } |
| 73 | // expected-error@-1 {{reference to __host__ function 'host_fn' in __host__ __device__ function}} |
| 74 | __device__ void device_fn() { hd3<int>(); } |
| 75 | |
| 76 | // No error because this is never instantiated. |
| 77 | template <typename T> __host__ __device__ void hd4() { host_fn(); } |
| 78 | |
| 79 | __host__ __device__ void local_var() { |
| 80 | S s; |
| 81 | // expected-error@-1 {{reference to __host__ function 'S' in __host__ __device__ function}} |
| 82 | } |
| 83 | |
| 84 | __host__ __device__ void placement_new(char *ptr) { |
| 85 | ::new(ptr) S(); |
| 86 | // expected-error@-1 {{reference to __host__ function 'S' in __host__ __device__ function}} |
| 87 | } |
| 88 | |
| 89 | __host__ __device__ void explicit_destructor(S *s) { |
| 90 | s->~S(); |
| 91 | // expected-error@-1 {{reference to __host__ function '~S' in __host__ __device__ function}} |
| 92 | } |
| 93 | |
Richard Smith | f75dcbe | 2016-10-11 00:21:10 +0000 | [diff] [blame] | 94 | __host__ __device__ void class_specific_delete(T *t, U *u) { |
| 95 | delete t; // ok, call sized device delete even though host has preferable non-sized version |
| 96 | delete u; // ok, call non-sized HD delete rather than sized D delete |
| 97 | } |
| 98 | |
Justin Lebar | 18e2d82 | 2016-08-15 23:00:49 +0000 | [diff] [blame] | 99 | __host__ __device__ void hd_member_fn() { |
| 100 | T t; |
| 101 | // Necessary to trigger an error on T::hd. It's (implicitly) inline, so |
| 102 | // isn't codegen'ed until we call it. |
| 103 | t.hd(); |
| 104 | } |
| 105 | |
| 106 | __host__ __device__ void h_member_fn() { |
| 107 | T t; |
| 108 | t.h(); |
| 109 | // expected-error@-1 {{reference to __host__ function 'h' in __host__ __device__ function}} |
| 110 | } |
| 111 | |
| 112 | __host__ __device__ void fn_ptr() { |
| 113 | auto* ptr = &host_fn; |
| 114 | // expected-error@-1 {{reference to __host__ function 'host_fn' in __host__ __device__ function}} |
| 115 | } |
| 116 | |
| 117 | template <typename T> |
| 118 | __host__ __device__ void fn_ptr_template() { |
| 119 | auto* ptr = &host_fn; // Not an error because the template isn't instantiated. |
| 120 | } |
Justin Lebar | 9fdb46e | 2016-10-08 01:07:11 +0000 | [diff] [blame] | 121 | |
| 122 | __host__ __device__ void unaryOp() { |
| 123 | T t; |
| 124 | (void) +t; // expected-error {{reference to __host__ function 'operator+' in __host__ __device__ function}} |
| 125 | } |
| 126 | |
| 127 | __host__ __device__ void binaryOp() { |
| 128 | T t; |
| 129 | (void) (t - t); // expected-error {{reference to __host__ function 'operator-' in __host__ __device__ function}} |
| 130 | } |
| 131 | |
| 132 | __host__ __device__ void implicitConversion() { |
| 133 | T t; |
| 134 | Dummy d = t; // expected-error {{reference to __host__ function 'operator Dummy' in __host__ __device__ function}} |
| 135 | } |
| 136 | |
| 137 | template <typename T> |
| 138 | struct TmplStruct { |
| 139 | template <typename U> __host__ __device__ void fn() {} |
| 140 | }; |
| 141 | |
| 142 | template <> |
| 143 | template <> |
| 144 | __host__ __device__ void TmplStruct<int>::fn<int>() { host_fn(); } |
| 145 | // expected-error@-1 {{reference to __host__ function 'host_fn' in __host__ __device__ function}} |
| 146 | |
| 147 | __device__ void double_specialization() { TmplStruct<int>().fn<int>(); } |