exceptions.cu 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // RUN: %clang_cc1 -fcxx-exceptions -fcuda-is-device -fsyntax-only -verify %s
  2. // RUN: %clang_cc1 -fcxx-exceptions -fsyntax-only -verify %s
  3. #include "Inputs/cuda.h"
  4. void host() {
  5. throw NULL;
  6. try {} catch(void*) {}
  7. }
  8. __device__ void device() {
  9. throw NULL;
  10. // expected-error@-1 {{cannot use 'throw' in __device__ function}}
  11. try {} catch(void*) {}
  12. // expected-error@-1 {{cannot use 'try' in __device__ function}}
  13. }
  14. __global__ void kernel() {
  15. throw NULL;
  16. // expected-error@-1 {{cannot use 'throw' in __global__ function}}
  17. try {} catch(void*) {}
  18. // expected-error@-1 {{cannot use 'try' in __global__ function}}
  19. }
  20. // Check that it's an error to use 'try' and 'throw' from a __host__ __device__
  21. // function if and only if it's codegen'ed for device.
  22. __host__ __device__ void hd1() {
  23. throw NULL;
  24. try {} catch(void*) {}
  25. #ifdef __CUDA_ARCH__
  26. // expected-error@-3 {{cannot use 'throw' in __host__ __device__ function}}
  27. // expected-error@-3 {{cannot use 'try' in __host__ __device__ function}}
  28. #endif
  29. }
  30. // No error, never instantiated on device.
  31. inline __host__ __device__ void hd2() {
  32. throw NULL;
  33. try {} catch(void*) {}
  34. }
  35. void call_hd2() { hd2(); }
  36. // Error, instantiated on device.
  37. inline __host__ __device__ void hd3() {
  38. throw NULL;
  39. try {} catch(void*) {}
  40. #ifdef __CUDA_ARCH__
  41. // expected-error@-3 {{cannot use 'throw' in __host__ __device__ function}}
  42. // expected-error@-3 {{cannot use 'try' in __host__ __device__ function}}
  43. #endif
  44. }
  45. __device__ void call_hd3() { hd3(); }
  46. #ifdef __CUDA_ARCH__
  47. // expected-note@-2 {{called by 'call_hd3'}}
  48. #endif