udr-7.C 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // { dg-do run }
  2. extern "C" void abort ();
  3. struct S
  4. {
  5. int s;
  6. void foo (S &x) { s += x.s; }
  7. S (const S &x) { s = x.s + 1; }
  8. S () { s = 6; }
  9. ~S () {}
  10. };
  11. void
  12. bar (S &x, S &y)
  13. {
  14. if (x.s != 6 || y.s != 6)
  15. abort ();
  16. x.s = 8;
  17. }
  18. #pragma omp declare reduction (foo: S: omp_out.foo (omp_in)) \
  19. initializer (omp_priv (omp_orig))
  20. #pragma omp declare reduction (bar : S: omp_out.foo (omp_in)) \
  21. initializer (bar (omp_priv, omp_orig))
  22. S
  23. baz (S x)
  24. {
  25. S r;
  26. int i = 0;
  27. if (x.s != 7 || r.s != 6)
  28. abort ();
  29. #pragma omp parallel reduction (foo: x) reduction (bar: r) \
  30. reduction (+: i)
  31. {
  32. if (x.s != 8 || r.s != 8)
  33. abort ();
  34. x.s = 12;
  35. r.s = 14;
  36. i = 1;
  37. }
  38. if (x.s != 7 + 12 * i || r.s != 6 + 14 * i)
  39. abort ();
  40. return r;
  41. }
  42. void
  43. baz (S &x, S &y)
  44. {
  45. int i = 0, &j = i;
  46. #pragma omp parallel reduction (foo: x) reduction (bar: y) \
  47. reduction (+: i)
  48. {
  49. if (x.s != 7 || y.s != 8)
  50. abort ();
  51. x.s = 12;
  52. y.s = 14;
  53. i = 1;
  54. }
  55. if (x.s != 6 + 12 * j || y.s != 6 + 14 * j)
  56. abort ();
  57. }
  58. int
  59. main ()
  60. {
  61. S s;
  62. baz (s);
  63. S t, u;
  64. baz (t, u);
  65. }