add-inline-in-definition.cu 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // RUN: %clang_cc1 -std=c++11 -fcuda-is-device -fsyntax-only -verify %s
  2. // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
  3. #include "Inputs/cuda.h"
  4. #ifndef __CUDA_ARCH__
  5. // expected-no-diagnostics
  6. #endif
  7. // When compiling for device, foo()'s call to host_fn() is an error, because
  8. // foo() is known-emitted.
  9. //
  10. // The trickiness here comes from the fact that the FunctionDecl bar() sees
  11. // foo() does not have the "inline" keyword, so we might incorrectly think that
  12. // foo() is a priori known-emitted. This would prevent us from marking foo()
  13. // as known-emitted when we see the call from bar() to foo(), which would
  14. // prevent us from emitting an error for foo()'s call to host_fn() when we
  15. // eventually see it.
  16. void host_fn() {}
  17. #ifdef __CUDA_ARCH__
  18. // expected-note@-2 {{declared here}}
  19. #endif
  20. __host__ __device__ void foo();
  21. __device__ void bar() {
  22. foo();
  23. #ifdef __CUDA_ARCH__
  24. // expected-note@-2 {{called by 'bar'}}
  25. #endif
  26. }
  27. inline __host__ __device__ void foo() {
  28. host_fn();
  29. #ifdef __CUDA_ARCH__
  30. // expected-error@-2 {{reference to __host__ function}}
  31. #endif
  32. }
  33. // This is similar to the above, except there's no error here. This code used
  34. // to trip an assertion due to us noticing, when emitting the definition of
  35. // boom(), that T::operator S() was (incorrectly) considered a priori
  36. // known-emitted.
  37. struct S {};
  38. struct T {
  39. __device__ operator S() const;
  40. };
  41. __device__ inline T::operator S() const { return S(); }
  42. __device__ T t;
  43. __device__ void boom() {
  44. S s = t;
  45. }