method-target.cu 2.3 KB

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