1 // PR libgomp/69555 2 // { dg-do run } 3 4 #include <omp.h> 5 6 __attribute__((noinline, noclone)) void f1(int y)7f1 (int y) 8 { 9 int a[y - 2]; 10 int (&c)[y - 2] = a; 11 c[0] = 111; 12 int e = 0; 13 14 #pragma omp parallel private (c) num_threads (4) reduction (+:e) 15 { 16 int v = omp_get_thread_num (); 17 for (int i = 0; i < y - 2; i++) 18 c[i] = i + v; 19 #pragma omp barrier 20 for (int i = 0; i < y - 2; i++) 21 if (c[i] != i + v) 22 e++; 23 } 24 if (c[0] != 111 || e) 25 __builtin_abort (); 26 } 27 28 __attribute__((noinline, noclone)) void f2(int y)29f2 (int y) 30 { 31 int a[y - 2]; 32 int (&c)[y - 2] = a; 33 c[0] = 111; 34 35 #pragma omp task private (c) 36 { 37 int v = omp_get_thread_num (); 38 for (int i = 0; i < y - 2; i++) 39 c[i] = i + v; 40 asm volatile ("" : : "r" (&c[0]) : "memory"); 41 for (int i = 0; i < y - 2; i++) 42 if (c[i] != i + v) 43 __builtin_abort (); 44 } 45 if (c[0] != 111) 46 __builtin_abort (); 47 } 48 49 __attribute__((noinline, noclone)) void f3(int y)50f3 (int y) 51 { 52 int a[y - 2]; 53 int (&c)[y - 2] = a; 54 for (int i = 0; i < y - 2; i++) 55 c[i] = i + 4; 56 57 #pragma omp parallel firstprivate (c) num_threads (4) 58 { 59 int v = omp_get_thread_num (); 60 for (int i = 0; i < y - 2; i++) 61 { 62 if (c[i] != i + 4) 63 __builtin_abort (); 64 c[i] = i + v; 65 } 66 #pragma omp barrier 67 for (int i = 0; i < y - 2; i++) 68 if (c[i] != i + v) 69 __builtin_abort (); 70 } 71 for (int i = 0; i < y - 2; i++) 72 if (c[i] != i + 4) 73 __builtin_abort (); 74 } 75 76 __attribute__((noinline, noclone)) void f4(int y)77f4 (int y) 78 { 79 int a[y - 2]; 80 int (&c)[y - 2] = a; 81 for (int i = 0; i < y - 2; i++) 82 c[i] = i + 4; 83 84 #pragma omp task firstprivate (c) 85 { 86 int v = omp_get_thread_num (); 87 for (int i = 0; i < y - 2; i++) 88 { 89 if (c[i] != i + 4) 90 __builtin_abort (); 91 c[i] = i + v; 92 } 93 asm volatile ("" : : "r" (&c[0]) : "memory"); 94 for (int i = 0; i < y - 2; i++) 95 if (c[i] != i + v) 96 __builtin_abort (); 97 } 98 for (int i = 0; i < y - 2; i++) 99 if (c[i] != i + 4) 100 __builtin_abort (); 101 } 102 103 int main()104main () 105 { 106 f1 (6); 107 f3 (6); 108 #pragma omp parallel num_threads (4) 109 { 110 f2 (6); 111 f4 (6); 112 } 113 return 0; 114 } 115