73 lines · plain
1// RUN: %clang_cc1 -fsyntax-only -verify=host,expected %s2// RUN: %clang_cc1 -fcuda-is-device -fsyntax-only -verify=dev,expected %s3 4#include "Inputs/cuda.h"5 6//------------------------------------------------------------------------------7// Test 1: host method called from device function8 9struct 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 method19 20struct 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 function31 32struct S3 {33 __device__ void method() {} // host-note {{'method' declared here}}34};35 36void 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 function42 43struct 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 operators53 54struct 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 pointer65 66struct 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}73