| 1 |
// RUN: %clang_cc1 -fsyntax-only -verify=host,expected %s |
| 2 |
// RUN: %clang_cc1 -fcuda-is-device -fsyntax-only -verify=dev,expected %s |
| 3 |
|
| 4 |
#include "Inputs/cuda.h" |
| 5 |
|
| 6 |
//------------------------------------------------------------------------------ |
| 7 |
// Test 1: host method called from device function |
| 8 |
|
| 9 |
struct S1 { |
| 10 |
void method() {} // dev-note {{'method' declared here}} |
| 11 |
}; |
| 12 |
|
| 13 |
__device__ void foo1(S1& s) { |
| 14 |
s.method(); // dev-error {{reference to __host__ function 'method' in __device__ function}} |
| 15 |
} |
| 16 |
|
| 17 |
//------------------------------------------------------------------------------ |
| 18 |
// Test 2: host method called from device function, for overloaded method |
| 19 |
|
| 20 |
struct S2 { |
| 21 |
void method(int) {} // expected-note {{candidate function not viable: call to __host__ function from __device__ function}} |
| 22 |
void method(float) {} // expected-note {{candidate function not viable: call to __host__ function from __device__ function}} |
| 23 |
}; |
| 24 |
|
| 25 |
__device__ void foo2(S2& s, int i, float f) { |
| 26 |
s.method(f); // expected-error {{no matching member function}} |
| 27 |
} |
| 28 |
|
| 29 |
//------------------------------------------------------------------------------ |
| 30 |
// Test 3: device method called from host function |
| 31 |
|
| 32 |
struct S3 { |
| 33 |
__device__ void method() {} // host-note {{'method' declared here}} |
| 34 |
}; |
| 35 |
|
| 36 |
void foo3(S3& s) { |
| 37 |
s.method(); // host-error {{reference to __device__ function 'method' in __host__ function}} |
| 38 |
} |
| 39 |
|
| 40 |
//------------------------------------------------------------------------------ |
| 41 |
// Test 4: device method called from host&device function |
| 42 |
|
| 43 |
struct S4 { |
| 44 |
__device__ void method() {} // host-note {{'method' declared here}} |
| 45 |
}; |
| 46 |
|
| 47 |
__host__ __device__ void foo4(S4& s) { |
| 48 |
s.method(); // host-error {{reference to __device__ function 'method' in __host__ __device__ function}} |
| 49 |
} |
| 50 |
|
| 51 |
//------------------------------------------------------------------------------ |
| 52 |
// Test 5: overloaded operators |
| 53 |
|
| 54 |
struct S5 { |
| 55 |
S5() {} |
| 56 |
S5& operator=(const S5&) {return *this;} // expected-note {{candidate function not viable}} |
| 57 |
}; |
| 58 |
|
| 59 |
__device__ void foo5(S5& s, S5& t) { |
| 60 |
s = t; // expected-error {{no viable overloaded '='}} |
| 61 |
} |
| 62 |
|
| 63 |
//------------------------------------------------------------------------------ |
| 64 |
// Test 6: call method through pointer |
| 65 |
|
| 66 |
struct S6 { |
| 67 |
void method() {} // dev-note {{'method' declared here}}; |
| 68 |
}; |
| 69 |
|
| 70 |
__device__ void foo6(S6* s) { |
| 71 |
s->method(); // dev-error {{reference to __host__ function 'method' in __device__ function}} |
| 72 |
} |