udr-2.C 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // { dg-do run }
  2. extern "C" void abort ();
  3. namespace NS
  4. {
  5. struct U
  6. {
  7. void foo (U &, bool);
  8. U ();
  9. };
  10. struct S
  11. {
  12. int s;
  13. #pragma omp declare reduction (foo : U, S : omp_out.foo (omp_in, false))
  14. #pragma omp declare reduction (foo : int : omp_out += omp_in) \
  15. initializer (omp_priv = int ())
  16. void baz (int v)
  17. {
  18. S s;
  19. int q = 0;
  20. if (s.s != 6 || v != 0) abort ();
  21. s.s = 20;
  22. #pragma omp parallel num_threads (4) reduction (foo : s, v) \
  23. reduction (::NS::U::operator + : q)
  24. {
  25. if (s.s != 6 || q != 0 || v != 0) abort ();
  26. asm volatile ("" : "+m" (s.s), "+r" (q), "+r" (v));
  27. s.s++; q++; v++;
  28. }
  29. if (s.s != 20 + q * 7 || q != v) abort ();
  30. }
  31. void foo (S &x) { s += x.s; }
  32. void foo (S &x, bool y) { s += x.s; if (y) abort (); }
  33. S (const S &x) { s = x.s + 1; }
  34. S (const S &x, bool y) { s = x.s + 2; if (y) abort (); }
  35. S () { s = 6; }
  36. S (int x) { s = x; }
  37. ~S ();
  38. };
  39. #pragma omp declare reduction (bar : S : omp_out.foo (omp_in)) \
  40. initializer (omp_priv (8))
  41. }
  42. NS::S::~S ()
  43. {
  44. if (s < 6) abort ();
  45. s = -1;
  46. /* Ensure the above store is not DSEd. */
  47. asm volatile ("" : : "r" (&s) : "memory");
  48. }
  49. struct T : public NS::S
  50. {
  51. void baz ()
  52. {
  53. S s;
  54. int q = 0;
  55. if (s.s != 6) abort ();
  56. #pragma omp parallel num_threads (4) reduction (foo:s) \
  57. reduction (+: q)
  58. {
  59. if (s.s != 6 || q != 0) abort ();
  60. asm volatile ("" : "+m" (s.s), "+r" (q));
  61. s.s += 2; q++;
  62. }
  63. if (s.s != 6 + q * 8) abort ();
  64. }
  65. };
  66. int
  67. main ()
  68. {
  69. NS::S s;
  70. s.baz (0);
  71. T t;
  72. t.baz ();
  73. int q = 0;
  74. if (s.s != 6) abort ();
  75. // Test ADL
  76. #pragma omp parallel num_threads (4) reduction (bar:s) reduction (+:q)
  77. {
  78. if (s.s != 8 || q != 0) abort ();
  79. asm volatile ("" : "+m" (s.s), "+r" (q));
  80. s.s += 4; q++;
  81. }
  82. if (s.s != 6 + q * 12) abort ();
  83. }