global-initializers-host.cu 860 B

1234567891011121314151617181920212223242526272829303132
  1. // RUN: %clang_cc1 %s --std=c++11 -triple x86_64-linux-unknown -fsyntax-only -o - -verify
  2. #include "Inputs/cuda.h"
  3. // Check that we get an error if we try to call a __device__ function from a
  4. // module initializer.
  5. struct S {
  6. __device__ S() {}
  7. // expected-note@-1 {{'S' declared here}}
  8. };
  9. S s;
  10. // expected-error@-1 {{reference to __device__ function 'S' in global initializer}}
  11. struct T {
  12. __host__ __device__ T() {}
  13. };
  14. T t; // No error, this is OK.
  15. struct U {
  16. __host__ U() {}
  17. __device__ U(int) {}
  18. // expected-note@-1 {{'U' declared here}}
  19. };
  20. U u(42);
  21. // expected-error@-1 {{reference to __device__ function 'U' in global initializer}}
  22. __device__ int device_fn() { return 42; }
  23. // expected-note@-1 {{'device_fn' declared here}}
  24. int n = device_fn();
  25. // expected-error@-1 {{reference to __device__ function 'device_fn' in global initializer}}