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