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 | 9fdb46e | 2016-10-08 01:07:11 +0000 | [diff] [blame^] | 15 | // expected-note@-7 {{'host_fn' declared here}} |
| 16 | |
| 17 | struct Dummy {}; |
Justin Lebar | 18e2d82 | 2016-08-15 23:00:49 +0000 | [diff] [blame] | 18 | |
| 19 | struct S { |
| 20 | S() {} |
Justin Lebar | 26bb311 | 2016-08-16 00:48:21 +0000 | [diff] [blame] | 21 | // expected-note@-1 {{'S' declared here}} |
| 22 | // expected-note@-2 {{'S' declared here}} |
Justin Lebar | 18e2d82 | 2016-08-15 23:00:49 +0000 | [diff] [blame] | 23 | ~S() { host_fn(); } |
Justin Lebar | 26bb311 | 2016-08-16 00:48:21 +0000 | [diff] [blame] | 24 | // expected-note@-1 {{'~S' declared here}} |
Justin Lebar | 18e2d82 | 2016-08-15 23:00:49 +0000 | [diff] [blame] | 25 | int x; |
| 26 | }; |
| 27 | |
| 28 | struct T { |
| 29 | __host__ __device__ void hd() { host_fn(); } |
| 30 | // expected-error@-1 {{reference to __host__ function 'host_fn' in __host__ __device__ function}} |
| 31 | |
| 32 | // No error; this is (implicitly) inline and is never called, so isn't |
| 33 | // codegen'ed. |
| 34 | __host__ __device__ void hd2() { host_fn(); } |
| 35 | |
| 36 | __host__ __device__ void hd3(); |
| 37 | |
| 38 | void h() {} |
Justin Lebar | 26bb311 | 2016-08-16 00:48:21 +0000 | [diff] [blame] | 39 | // expected-note@-1 {{'h' declared here}} |
Justin Lebar | 9fdb46e | 2016-10-08 01:07:11 +0000 | [diff] [blame^] | 40 | |
| 41 | void operator+(); |
| 42 | // expected-note@-1 {{'operator+' declared here}} |
| 43 | |
| 44 | void operator-(const T&) {} |
| 45 | // expected-note@-1 {{'operator-' declared here}} |
| 46 | |
| 47 | operator Dummy() { return Dummy(); } |
| 48 | // expected-note@-1 {{'operator Dummy' declared here}} |
Justin Lebar | 18e2d82 | 2016-08-15 23:00:49 +0000 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | __host__ __device__ void T::hd3() { |
| 52 | host_fn(); |
| 53 | // expected-error@-1 {{reference to __host__ function 'host_fn' in __host__ __device__ function}} |
| 54 | } |
| 55 | |
| 56 | template <typename T> __host__ __device__ void hd2() { host_fn(); } |
| 57 | // expected-error@-1 {{reference to __host__ function 'host_fn' in __host__ __device__ function}} |
| 58 | __global__ void kernel() { hd2<int>(); } |
| 59 | |
| 60 | __host__ __device__ void hd() { host_fn(); } |
| 61 | // expected-error@-1 {{reference to __host__ function 'host_fn' in __host__ __device__ function}} |
| 62 | |
| 63 | template <typename T> __host__ __device__ void hd3() { host_fn(); } |
| 64 | // expected-error@-1 {{reference to __host__ function 'host_fn' in __host__ __device__ function}} |
| 65 | __device__ void device_fn() { hd3<int>(); } |
| 66 | |
| 67 | // No error because this is never instantiated. |
| 68 | template <typename T> __host__ __device__ void hd4() { host_fn(); } |
| 69 | |
| 70 | __host__ __device__ void local_var() { |
| 71 | S s; |
| 72 | // expected-error@-1 {{reference to __host__ function 'S' in __host__ __device__ function}} |
| 73 | } |
| 74 | |
| 75 | __host__ __device__ void placement_new(char *ptr) { |
| 76 | ::new(ptr) S(); |
| 77 | // expected-error@-1 {{reference to __host__ function 'S' in __host__ __device__ function}} |
| 78 | } |
| 79 | |
| 80 | __host__ __device__ void explicit_destructor(S *s) { |
| 81 | s->~S(); |
| 82 | // expected-error@-1 {{reference to __host__ function '~S' in __host__ __device__ function}} |
| 83 | } |
| 84 | |
| 85 | __host__ __device__ void hd_member_fn() { |
| 86 | T t; |
| 87 | // Necessary to trigger an error on T::hd. It's (implicitly) inline, so |
| 88 | // isn't codegen'ed until we call it. |
| 89 | t.hd(); |
| 90 | } |
| 91 | |
| 92 | __host__ __device__ void h_member_fn() { |
| 93 | T t; |
| 94 | t.h(); |
| 95 | // expected-error@-1 {{reference to __host__ function 'h' in __host__ __device__ function}} |
| 96 | } |
| 97 | |
| 98 | __host__ __device__ void fn_ptr() { |
| 99 | auto* ptr = &host_fn; |
| 100 | // expected-error@-1 {{reference to __host__ function 'host_fn' in __host__ __device__ function}} |
| 101 | } |
| 102 | |
| 103 | template <typename T> |
| 104 | __host__ __device__ void fn_ptr_template() { |
| 105 | auto* ptr = &host_fn; // Not an error because the template isn't instantiated. |
| 106 | } |
Justin Lebar | 9fdb46e | 2016-10-08 01:07:11 +0000 | [diff] [blame^] | 107 | |
| 108 | __host__ __device__ void unaryOp() { |
| 109 | T t; |
| 110 | (void) +t; // expected-error {{reference to __host__ function 'operator+' in __host__ __device__ function}} |
| 111 | } |
| 112 | |
| 113 | __host__ __device__ void binaryOp() { |
| 114 | T t; |
| 115 | (void) (t - t); // expected-error {{reference to __host__ function 'operator-' in __host__ __device__ function}} |
| 116 | } |
| 117 | |
| 118 | __host__ __device__ void implicitConversion() { |
| 119 | T t; |
| 120 | Dummy d = t; // expected-error {{reference to __host__ function 'operator Dummy' in __host__ __device__ function}} |
| 121 | } |
| 122 | |
| 123 | template <typename T> |
| 124 | struct TmplStruct { |
| 125 | template <typename U> __host__ __device__ void fn() {} |
| 126 | }; |
| 127 | |
| 128 | template <> |
| 129 | template <> |
| 130 | __host__ __device__ void TmplStruct<int>::fn<int>() { host_fn(); } |
| 131 | // expected-error@-1 {{reference to __host__ function 'host_fn' in __host__ __device__ function}} |
| 132 | |
| 133 | __device__ void double_specialization() { TmplStruct<int>().fn<int>(); } |