target-19.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. extern void abort (void);
  2. __attribute__((noinline, noclone)) void
  3. foo (int *p, int *q, int *r, int n, int m)
  4. {
  5. int i, err, *s = r;
  6. int sep = 1;
  7. #pragma omp target map(to:sep)
  8. sep = 0;
  9. #pragma omp target data map(to:p[0:8])
  10. {
  11. /* For zero length array sections, p points to the start of
  12. already mapped range, q to the end of it (with nothing mapped
  13. after it), and r does not point to an mapped range. */
  14. #pragma omp target map(alloc:p[:0]) map(to:q[:0]) map(from:r[:0]) private(i) map(from:err) firstprivate (s)
  15. {
  16. err = 0;
  17. for (i = 0; i < 8; i++)
  18. if (p[i] != i + 1)
  19. err = 1;
  20. if (sep)
  21. {
  22. if (q != (int *) 0 || r != (int *) 0)
  23. err = 1;
  24. }
  25. else if (p + 8 != q || r != s)
  26. err = 1;
  27. }
  28. if (err)
  29. abort ();
  30. /* Implicit mapping of pointers behaves the same way. */
  31. #pragma omp target private(i) map(from:err) firstprivate (s)
  32. {
  33. err = 0;
  34. for (i = 0; i < 8; i++)
  35. if (p[i] != i + 1)
  36. err = 1;
  37. if (sep)
  38. {
  39. if (q != (int *) 0 || r != (int *) 0)
  40. err = 1;
  41. }
  42. else if (p + 8 != q || r != s)
  43. err = 1;
  44. }
  45. if (err)
  46. abort ();
  47. /* And zero-length array sections, though not known at compile
  48. time, behave the same. */
  49. #pragma omp target map(p[:n]) map(tofrom:q[:n]) map(alloc:r[:n]) private(i) map(from:err) firstprivate (s)
  50. {
  51. err = 0;
  52. for (i = 0; i < 8; i++)
  53. if (p[i] != i + 1)
  54. err = 1;
  55. if (sep)
  56. {
  57. if (q != (int *) 0 || r != (int *) 0)
  58. err = 1;
  59. }
  60. else if (p + 8 != q || r != s)
  61. err = 1;
  62. }
  63. if (err)
  64. abort ();
  65. /* Non-zero length array sections, though not known at compile,
  66. behave differently. */
  67. #pragma omp target map(p[:m]) map(tofrom:q[:m]) map(to:r[:m]) private(i) map(from:err)
  68. {
  69. err = 0;
  70. for (i = 0; i < 8; i++)
  71. if (p[i] != i + 1)
  72. err = 1;
  73. if (q[0] != 9 || r[0] != 10)
  74. err = 1;
  75. }
  76. if (err)
  77. abort ();
  78. #pragma omp target data map(to:q[0:1])
  79. {
  80. /* For zero length array sections, p points to the start of
  81. already mapped range, q points to the start of another one,
  82. and r to the end of the second one. */
  83. #pragma omp target map(to:p[:0]) map(from:q[:0]) map(tofrom:r[:0]) private(i) map(from:err)
  84. {
  85. err = 0;
  86. for (i = 0; i < 8; i++)
  87. if (p[i] != i + 1)
  88. err = 1;
  89. if (q[0] != 9)
  90. err = 1;
  91. else if (sep)
  92. {
  93. if (r != (int *) 0)
  94. err = 1;
  95. }
  96. else if (r != q + 1)
  97. err = 1;
  98. }
  99. if (err)
  100. abort ();
  101. /* Implicit mapping of pointers behaves the same way. */
  102. #pragma omp target private(i) map(from:err)
  103. {
  104. err = 0;
  105. for (i = 0; i < 8; i++)
  106. if (p[i] != i + 1)
  107. err = 1;
  108. if (q[0] != 9)
  109. err = 1;
  110. else if (sep)
  111. {
  112. if (r != (int *) 0)
  113. err = 1;
  114. }
  115. else if (r != q + 1)
  116. err = 1;
  117. }
  118. if (err)
  119. abort ();
  120. /* And zero-length array sections, though not known at compile
  121. time, behave the same. */
  122. #pragma omp target map(p[:n]) map(alloc:q[:n]) map(from:r[:n]) private(i) map(from:err)
  123. {
  124. err = 0;
  125. for (i = 0; i < 8; i++)
  126. if (p[i] != i + 1)
  127. err = 1;
  128. if (q[0] != 9)
  129. err = 1;
  130. else if (sep)
  131. {
  132. if (r != (int *) 0)
  133. err = 1;
  134. }
  135. else if (r != q + 1)
  136. err = 1;
  137. }
  138. if (err)
  139. abort ();
  140. /* Non-zero length array sections, though not known at compile,
  141. behave differently. */
  142. #pragma omp target map(p[:m]) map(alloc:q[:m]) map(tofrom:r[:m]) private(i) map(from:err)
  143. {
  144. err = 0;
  145. for (i = 0; i < 8; i++)
  146. if (p[i] != i + 1)
  147. err = 1;
  148. if (q[0] != 9 || r[0] != 10)
  149. err = 1;
  150. }
  151. if (err)
  152. abort ();
  153. }
  154. }
  155. }
  156. int
  157. main ()
  158. {
  159. int a[32], i;
  160. for (i = 0; i < 32; i++)
  161. a[i] = i;
  162. foo (a + 1, a + 9, a + 10, 0, 1);
  163. return 0;
  164. }