pr27337.C 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // PR middle-end/27337
  2. // { dg-do run }
  3. #include <omp.h>
  4. extern "C" void abort (void);
  5. struct S
  6. {
  7. S ();
  8. ~S ();
  9. S (const S &);
  10. int i;
  11. };
  12. int n[3];
  13. S::S () : i(18)
  14. {
  15. if (omp_get_thread_num () != 0)
  16. #pragma omp atomic
  17. n[0]++;
  18. }
  19. S::~S ()
  20. {
  21. if (omp_get_thread_num () != 0)
  22. #pragma omp atomic
  23. n[1]++;
  24. }
  25. S::S (const S &x)
  26. {
  27. if (x.i != 18)
  28. abort ();
  29. i = 118;
  30. if (omp_get_thread_num () != 0)
  31. #pragma omp atomic
  32. n[2]++;
  33. }
  34. S
  35. foo ()
  36. {
  37. int i;
  38. S ret;
  39. #pragma omp parallel for firstprivate (ret) lastprivate (ret) \
  40. schedule (static, 1) num_threads (4)
  41. for (i = 0; i < 4; i++)
  42. ret.i += omp_get_thread_num ();
  43. return ret;
  44. }
  45. S
  46. bar ()
  47. {
  48. int i;
  49. S ret;
  50. #pragma omp parallel for num_threads (4)
  51. for (i = 0; i < 4; i++)
  52. #pragma omp atomic
  53. ret.i += omp_get_thread_num () + 1;
  54. return ret;
  55. }
  56. S x;
  57. int
  58. main (void)
  59. {
  60. omp_set_dynamic (false);
  61. x = foo ();
  62. if (n[0] != 0 || n[1] != 3 || n[2] != 3)
  63. abort ();
  64. if (x.i != 118 + 3)
  65. abort ();
  66. x = bar ();
  67. if (n[0] != 0 || n[1] != 3 || n[2] != 3)
  68. abort ();
  69. if (x.i != 18 + 0 + 1 + 2 + 3 + 4)
  70. abort ();
  71. return 0;
  72. }