diff options
Diffstat (limited to 'gcc-4.9/libgomp/testsuite/libgomp.c++')
127 files changed, 9854 insertions, 0 deletions
diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/affinity-1.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/affinity-1.C new file mode 100644 index 000000000..d20b392ba --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/affinity-1.C @@ -0,0 +1,4 @@ +// { dg-do run } +// { dg-set-target-env-var OMP_PROC_BIND "true" } + +#include "../libgomp.c/affinity-1.c" diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/atomic-1.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/atomic-1.C new file mode 100644 index 000000000..73f6e7c40 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/atomic-1.C @@ -0,0 +1,53 @@ +// PR c++/33894 +// { dg-do run } +// { dg-options "-O2" } + +extern "C" void abort (); + +int check; + +template<typename T> void +foo () +{ + #pragma omp atomic + check |= sizeof (T); +} + +template<typename T> void +bar (T *x, T y) +{ + #pragma omp atomic + *x += y; +} + +template<typename T> void +baz () +{ + #pragma omp atomic + check++; +} + +int +main () +{ + int i = 0; + long l = 0; + + check = 0; + foo<char> (); + if (check != sizeof (char)) + abort (); + foo<short> (); + if (check != (sizeof (char) | sizeof (short))) + abort (); + bar(&i, 4); + bar(&l, 8L); + if (i != 4 || l != 8L) + abort (); + baz<char> (); + if (check != (sizeof (char) | sizeof (short)) + 1) + abort (); + baz<long double> (); + if (check != (sizeof (char) | sizeof (short)) + 2) + abort (); +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/atomic-10.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/atomic-10.C new file mode 100644 index 000000000..2145f2882 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/atomic-10.C @@ -0,0 +1,99 @@ +// { dg-do run } + +extern "C" void abort (void); +int x = 6; + +int +main () +{ + int v, l = 2, s = 1; + #pragma omp atomic + x = -3 + x; + #pragma omp atomic read + v = x; + if (v != 3) + abort (); + #pragma omp atomic update + x = 3 * 2 * 1 + x; + #pragma omp atomic read + v = x; + if (v != 9) + abort (); + #pragma omp atomic capture + v = x = x | 16; + if (v != 25) + abort (); + #pragma omp atomic capture + v = x = x + 14 * 2 / 4; + if (v != 32) + abort (); + #pragma omp atomic capture + v = x = 5 | x; + if (v != 37) + abort (); + #pragma omp atomic capture + v = x = 40 + 12 - 2 - 7 - x; + if (v != 6) + abort (); + #pragma omp atomic read + v = x; + if (v != 6) + abort (); + #pragma omp atomic capture + { v = x; x = 3 + x; } + if (v != 6) + abort (); + #pragma omp atomic capture + { v = x; x = -1 * -1 * -1 * -1 - x; } + if (v != 9) + abort (); + #pragma omp atomic read + v = x; + if (v != -8) + abort (); + #pragma omp atomic capture + { x = 2 * 2 - x; v = x; } + if (v != 12) + abort (); + #pragma omp atomic capture + { x = 7 & x; v = x; } + if (v != 4) + abort (); + #pragma omp atomic capture + { v = x; x = 6; } + if (v != 4) + abort (); + #pragma omp atomic read + v = x; + if (v != 6) + abort (); + #pragma omp atomic capture + { v = x; x = 7 * 8 + 23; } + if (v != 6) + abort (); + #pragma omp atomic read + v = x; + if (v != 79) + abort (); + #pragma omp atomic capture + { v = x; x = 23 + 6 * 4; } + if (v != 79) + abort (); + #pragma omp atomic read + v = x; + if (v != 47) + abort (); + #pragma omp atomic capture + { v = x; x = l ? 17 : 12; } + if (v != 47) + abort (); + #pragma omp atomic capture + { v = x; x = l = s++ + 3; } + if (v != 17 || l != 4 || s != 2) + abort (); + #pragma omp atomic read + v = x; + if (v != 4) + abort (); + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/atomic-11.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/atomic-11.C new file mode 100644 index 000000000..c7101e014 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/atomic-11.C @@ -0,0 +1,108 @@ +// { dg-do run } + +extern "C" void abort (void); + +template <typename T> +void +foo () +{ + extern T x; + T v, l = 2, s = 1; + #pragma omp atomic + x = -3 + x; + #pragma omp atomic read + v = x; + if (v != 3) + abort (); + #pragma omp atomic update + x = 3 * 2 * 1 + x; + #pragma omp atomic read + v = x; + if (v != 9) + abort (); + #pragma omp atomic capture + v = x = x | 16; + if (v != 25) + abort (); + #pragma omp atomic capture + v = x = x + 14 * 2 / 4; + if (v != 32) + abort (); + #pragma omp atomic capture + v = x = 5 | x; + if (v != 37) + abort (); + #pragma omp atomic capture + v = x = 40 + 12 - 2 - 7 - x; + if (v != 6) + abort (); + #pragma omp atomic read + v = x; + if (v != 6) + abort (); + #pragma omp atomic capture + { v = x; x = 3 + x; } + if (v != 6) + abort (); + #pragma omp atomic capture + { v = x; x = -1 * -1 * -1 * -1 - x; } + if (v != 9) + abort (); + #pragma omp atomic read + v = x; + if (v != -8) + abort (); + #pragma omp atomic capture + { x = 2 * 2 - x; v = x; } + if (v != 12) + abort (); + #pragma omp atomic capture + { x = 7 & x; v = x; } + if (v != 4) + abort (); + #pragma omp atomic capture + { v = x; x = 6; } + if (v != 4) + abort (); + #pragma omp atomic read + v = x; + if (v != 6) + abort (); + #pragma omp atomic capture + { v = x; x = 7 * 8 + 23; } + if (v != 6) + abort (); + #pragma omp atomic read + v = x; + if (v != 79) + abort (); + #pragma omp atomic capture + { v = x; x = 23 + 6 * 4; } + if (v != 79) + abort (); + #pragma omp atomic read + v = x; + if (v != 47) + abort (); + #pragma omp atomic capture + { v = x; x = l ? 17 : 12; } + if (v != 47) + abort (); + #pragma omp atomic capture + { v = x; x = l = s++ + 3; } + if (v != 17 || l != 4 || s != 2) + abort (); + #pragma omp atomic read + v = x; + if (v != 4) + abort (); +} + +int x = 6; + +int +main () +{ + foo <int> (); + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/atomic-12.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/atomic-12.C new file mode 100644 index 000000000..d1ae9d8c8 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/atomic-12.C @@ -0,0 +1,58 @@ +// { dg-do run } + +extern "C" void abort (); +int x = 6, cnt; + +int +foo () +{ + return cnt++; +} + +int +main () +{ + int v, *p; + p = &x; + #pragma omp atomic update + p[foo (), 0] = 16 + 6 - p[foo (), 0]; + #pragma omp atomic read + v = x; + if (cnt != 2 || v != 16) + abort (); + #pragma omp atomic capture + v = p[foo () + foo (), 0] = p[foo () + foo (), 0] + 3; + if (cnt != 6 || v != 19) + abort (); + #pragma omp atomic capture + v = p[foo (), 0] = 12 * 1 / 2 + (foo (), 0) + p[foo (), 0]; + if (cnt != 9 || v != 25) + abort (); + #pragma omp atomic capture + { + v = p[foo () & 0]; p[foo () & 0] = (foo (), 1) * 9 - p[foo () & 0]; + } + if (cnt != 13 || v != 25) + abort (); + #pragma omp atomic read + v = x; + if (v != -16) + abort (); + #pragma omp atomic capture + { + p[0 & foo ()] = 16 - 2 + 3 + p[0 & foo ()]; v = p[0 & foo ()]; + } + if (cnt != 16 || v != 1) + abort (); + #pragma omp atomic capture + { + v = p[foo (), 0]; p[foo (), 0] = (foo (), 7) ? 13 : foo () + 6; + } + if (cnt != 19 || v != 1) + abort (); + #pragma omp atomic read + v = x; + if (v != 13) + abort (); + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/atomic-13.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/atomic-13.C new file mode 100644 index 000000000..0569d1c6d --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/atomic-13.C @@ -0,0 +1,68 @@ +// { dg-do run } + +extern "C" void abort (); +int cnt; + +int +foo () +{ + return cnt++; +} + +template <typename T> +void +bar () +{ + extern T x; + T v, *p; + p = &x; + #pragma omp atomic update + p[foo (), 0] = 16 + 6 - p[foo (), 0]; + #pragma omp atomic read + v = x; + if (cnt != 2 || v != 16) + abort (); + #pragma omp atomic capture + v = p[foo () + foo (), 0] = p[foo () + foo (), 0] + 3; + if (cnt != 6 || v != 19) + abort (); + #pragma omp atomic capture + v = p[foo (), 0] = 12 * 1 / 2 + (foo (), 0) + p[foo (), 0]; + if (cnt != 9 || v != 25) + abort (); + #pragma omp atomic capture + { + v = p[foo () & 0]; p[foo () & 0] = (foo (), 1) * 9 - p[foo () & 0]; + } + if (cnt != 13 || v != 25) + abort (); + #pragma omp atomic read + v = x; + if (v != -16) + abort (); + #pragma omp atomic capture + { + p[0 & foo ()] = 16 - 2 + 3 + p[0 & foo ()]; v = p[0 & foo ()]; + } + if (cnt != 16 || v != 1) + abort (); + #pragma omp atomic capture + { + v = p[foo (), 0]; p[foo (), 0] = (foo (), 7) ? 13 : foo () + 6; + } + if (cnt != 19 || v != 1) + abort (); + #pragma omp atomic read + v = x; + if (v != 13) + abort (); +} + +int x = 6; + +int +main () +{ + bar <int> (); + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/atomic-14.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/atomic-14.C new file mode 100644 index 000000000..4cd9df812 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/atomic-14.C @@ -0,0 +1,99 @@ +// { dg-do run } + +extern "C" void abort (void); +int x = 6; + +int +main () +{ + int v, l = 2, s = 1; + #pragma omp atomic seq_cst + x = -3 + x; + #pragma omp atomic read seq_cst + v = x; + if (v != 3) + abort (); + #pragma omp atomic update seq_cst + x = 3 * 2 * 1 + x; + #pragma omp atomic read seq_cst + v = x; + if (v != 9) + abort (); + #pragma omp atomic capture seq_cst + v = x = x | 16; + if (v != 25) + abort (); + #pragma omp atomic capture seq_cst + v = x = x + 14 * 2 / 4; + if (v != 32) + abort (); + #pragma omp atomic capture seq_cst + v = x = 5 | x; + if (v != 37) + abort (); + #pragma omp atomic capture seq_cst + v = x = 40 + 12 - 2 - 7 - x; + if (v != 6) + abort (); + #pragma omp atomic read seq_cst + v = x; + if (v != 6) + abort (); + #pragma omp atomic capture seq_cst + { v = x; x = 3 + x; } + if (v != 6) + abort (); + #pragma omp atomic capture seq_cst + { v = x; x = -1 * -1 * -1 * -1 - x; } + if (v != 9) + abort (); + #pragma omp atomic read seq_cst + v = x; + if (v != -8) + abort (); + #pragma omp atomic capture seq_cst + { x = 2 * 2 - x; v = x; } + if (v != 12) + abort (); + #pragma omp atomic capture seq_cst + { x = 7 & x; v = x; } + if (v != 4) + abort (); + #pragma omp atomic capture seq_cst + { v = x; x = 6; } + if (v != 4) + abort (); + #pragma omp atomic read seq_cst + v = x; + if (v != 6) + abort (); + #pragma omp atomic capture seq_cst + { v = x; x = 7 * 8 + 23; } + if (v != 6) + abort (); + #pragma omp atomic read seq_cst + v = x; + if (v != 79) + abort (); + #pragma omp atomic capture seq_cst + { v = x; x = 23 + 6 * 4; } + if (v != 79) + abort (); + #pragma omp atomic read seq_cst + v = x; + if (v != 47) + abort (); + #pragma omp atomic capture seq_cst + { v = x; x = l ? 17 : 12; } + if (v != 47) + abort (); + #pragma omp atomic capture seq_cst + { v = x; x = l = s++ + 3; } + if (v != 17 || l != 4 || s != 2) + abort (); + #pragma omp atomic read seq_cst + v = x; + if (v != 4) + abort (); + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/atomic-15.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/atomic-15.C new file mode 100644 index 000000000..1eabce7db --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/atomic-15.C @@ -0,0 +1,108 @@ +// { dg-do run } + +extern "C" void abort (void); + +template <typename T> +void +foo () +{ + extern T x; + T v, l = 2, s = 1; + #pragma omp atomic seq_cst + x = -3 + x; + #pragma omp atomic read seq_cst + v = x; + if (v != 3) + abort (); + #pragma omp atomic update seq_cst + x = 3 * 2 * 1 + x; + #pragma omp atomic read seq_cst + v = x; + if (v != 9) + abort (); + #pragma omp atomic capture seq_cst + v = x = x | 16; + if (v != 25) + abort (); + #pragma omp atomic capture seq_cst + v = x = x + 14 * 2 / 4; + if (v != 32) + abort (); + #pragma omp atomic capture seq_cst + v = x = 5 | x; + if (v != 37) + abort (); + #pragma omp atomic capture seq_cst + v = x = 40 + 12 - 2 - 7 - x; + if (v != 6) + abort (); + #pragma omp atomic read seq_cst + v = x; + if (v != 6) + abort (); + #pragma omp atomic capture seq_cst + { v = x; x = 3 + x; } + if (v != 6) + abort (); + #pragma omp atomic capture seq_cst + { v = x; x = -1 * -1 * -1 * -1 - x; } + if (v != 9) + abort (); + #pragma omp atomic read seq_cst + v = x; + if (v != -8) + abort (); + #pragma omp atomic capture seq_cst + { x = 2 * 2 - x; v = x; } + if (v != 12) + abort (); + #pragma omp atomic capture seq_cst + { x = 7 & x; v = x; } + if (v != 4) + abort (); + #pragma omp atomic capture seq_cst + { v = x; x = 6; } + if (v != 4) + abort (); + #pragma omp atomic read seq_cst + v = x; + if (v != 6) + abort (); + #pragma omp atomic capture seq_cst + { v = x; x = 7 * 8 + 23; } + if (v != 6) + abort (); + #pragma omp atomic read seq_cst + v = x; + if (v != 79) + abort (); + #pragma omp atomic capture seq_cst + { v = x; x = 23 + 6 * 4; } + if (v != 79) + abort (); + #pragma omp atomic read seq_cst + v = x; + if (v != 47) + abort (); + #pragma omp atomic capture seq_cst + { v = x; x = l ? 17 : 12; } + if (v != 47) + abort (); + #pragma omp atomic capture seq_cst + { v = x; x = l = s++ + 3; } + if (v != 17 || l != 4 || s != 2) + abort (); + #pragma omp atomic read seq_cst + v = x; + if (v != 4) + abort (); +} + +int x = 6; + +int +main () +{ + foo <int> (); + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/atomic-2.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/atomic-2.C new file mode 100644 index 000000000..e7217590a --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/atomic-2.C @@ -0,0 +1,156 @@ +// { dg-do run } + +extern "C" void abort (void); +int x = 6; +float y; + +int +main (void) +{ + int v; + float f; + #pragma omp atomic read + v = x; + if (v != 6) + abort (); + #pragma omp atomic write + x = 17; + #pragma omp atomic read + v = x; + if (v != 17) + abort (); + #pragma omp atomic update + x++; + #pragma omp atomic read + v = x; + if (v != 18) + abort (); + #pragma omp atomic capture + v = x++; + if (v != 18) + abort (); + #pragma omp atomic read + v = x; + if (v != 19) + abort (); + #pragma omp atomic capture + v = ++x; + if (v != 20) + abort (); + #pragma omp atomic read + v = x; + if (v != 20) + abort (); + #pragma omp atomic capture + { v = x; x *= 3; } + if (v != 20) + abort (); + #pragma omp atomic read + v = x; + if (v != 60) + abort (); + #pragma omp atomic capture + { + x |= 2; + v = x; + } + if (v != 62) + abort (); + #pragma omp atomic read + v = x; + if (v != 62) + abort (); + #pragma omp atomic capture + { v = x; x++; } + if (v != 62) + abort (); + #pragma omp atomic capture + { v = x; ++x; } + if (v != 63) + abort (); + #pragma omp atomic capture + { + ++x; + v = x; + } + if (v != 65) + abort (); +#pragma omp atomic capture +{x++;v=x;}if (v != 66) + abort (); + #pragma omp atomic read + v = x; + if (v != 66) + abort (); + #pragma omp atomic capture + { v = x; x--; } + if (v != 66) + abort (); + #pragma omp atomic capture + { v = x; --x; } + if (v != 65) + abort (); + #pragma omp atomic capture + { + --x; + v = x; + } + if (v != 63) + abort (); + #pragma omp atomic capture + { x--; v = x; } if (v != 62) + abort (); + #pragma omp atomic read + v = x; + if (v != 62) + abort (); + #pragma omp atomic write + y = 17.5f; + #pragma omp atomic read + f = y; + if (f != 17.5) + abort (); + #pragma omp atomic update + y *= 2.0f; + #pragma omp atomic read + f = y; + if (y != 35.0) + abort (); + #pragma omp atomic capture + f = y *= 2.0f; + if (f != 70.0) + abort (); + #pragma omp atomic capture + f = y++; + if (f != 70.0) + abort (); + #pragma omp atomic read + f = y; + if (f != 71.0) + abort (); + #pragma omp atomic capture + f = --y; + if (f != 70.0) + abort (); + #pragma omp atomic read + f = y; + if (f != 70.0) + abort (); + #pragma omp atomic capture + { f = y; y /= 2.0f; } + if (f != 70.0) + abort (); + #pragma omp atomic read + f = y; + if (f != 35.0) + abort (); + #pragma omp atomic capture + { y /= 2.0f; f = y; } + if (f != 17.5) + abort (); + #pragma omp atomic read + f = y; + if (f != 17.5) + abort (); + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/atomic-3.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/atomic-3.C new file mode 100644 index 000000000..660b260e1 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/atomic-3.C @@ -0,0 +1,74 @@ +// { dg-do run } + +extern "C" void abort (void); +bool v, x1, x2, x3, x4, x5, x6; + +void +foo () +{ + #pragma omp atomic capture + v = ++x1; + if (!v) + abort (); + #pragma omp atomic capture + v = x2++; + if (v) + abort (); + #pragma omp atomic read + v = x3; + if (!v) + abort (); + #pragma omp atomic read + v = x4; + if (!v) + abort (); + #pragma omp atomic capture + { v = x5; x5 |= 1; } + if (v) + abort (); + #pragma omp atomic capture + { x6 |= 1; v = x6; } + if (!v) + abort (); +} + +void +bar () +{ + #pragma omp atomic write + x1 = false; + #pragma omp atomic write + x2 = false; + #pragma omp atomic capture + { ++x1; v = x1; } + if (!v) + abort (); + #pragma omp atomic capture + { v = x2; x2++; } + if (v) + abort (); + #pragma omp atomic write + x1 = false; + #pragma omp atomic write + x2 = false; + #pragma omp atomic capture + { x1++; v = x1; } + if (!v) + abort (); + #pragma omp atomic capture + { v = x2; ++x2; } + if (v) + abort (); +} + +int +main () +{ + #pragma omp atomic write + x3 = true; + #pragma omp atomic write + x4 = true; + foo (); + bar (); + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/atomic-4.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/atomic-4.C new file mode 100644 index 000000000..82439df2b --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/atomic-4.C @@ -0,0 +1,166 @@ +// { dg-do run } + +extern "C" void abort (void); +template <typename T, typename T2> +int +foo (void) +{ + extern T x; + extern T2 y; + T v; + T2 f; + #pragma omp atomic read + v = x; + if (v != 6) + abort (); + #pragma omp atomic write + x = 17; + #pragma omp atomic read + v = x; + if (v != 17) + abort (); + #pragma omp atomic update + x++; + #pragma omp atomic read + v = x; + if (v != 18) + abort (); + #pragma omp atomic capture + v = x++; + if (v != 18) + abort (); + #pragma omp atomic read + v = x; + if (v != 19) + abort (); + #pragma omp atomic capture + v = ++x; + if (v != 20) + abort (); + #pragma omp atomic read + v = x; + if (v != 20) + abort (); + #pragma omp atomic capture + { v = x; x *= 3; } + if (v != 20) + abort (); + #pragma omp atomic read + v = x; + if (v != 60) + abort (); + #pragma omp atomic capture + { + x |= 2; + v = x; + } + if (v != 62) + abort (); + #pragma omp atomic read + v = x; + if (v != 62) + abort (); + #pragma omp atomic capture + { v = x; x++; } + if (v != 62) + abort (); + #pragma omp atomic capture + { v = x; ++x; } + if (v != 63) + abort (); + #pragma omp atomic capture + { + ++x; + v = x; + } + if (v != 65) + abort (); +#pragma omp atomic capture +{x++;v=x;}if (v != 66) + abort (); + #pragma omp atomic read + v = x; + if (v != 66) + abort (); + #pragma omp atomic capture + { v = x; x--; } + if (v != 66) + abort (); + #pragma omp atomic capture + { v = x; --x; } + if (v != 65) + abort (); + #pragma omp atomic capture + { + --x; + v = x; + } + if (v != 63) + abort (); + #pragma omp atomic capture + { x--; v = x; } if (v != 62) + abort (); + #pragma omp atomic read + v = x; + if (v != 62) + abort (); + #pragma omp atomic write + y = 17.5f; + #pragma omp atomic read + f = y; + if (f != 17.5) + abort (); + #pragma omp atomic update + y *= 2.0f; + #pragma omp atomic read + f = y; + if (y != 35.0) + abort (); + #pragma omp atomic capture + f = y *= 2.0f; + if (f != 70.0) + abort (); + #pragma omp atomic capture + f = y++; + if (f != 70.0) + abort (); + #pragma omp atomic read + f = y; + if (f != 71.0) + abort (); + #pragma omp atomic capture + f = --y; + if (f != 70.0) + abort (); + #pragma omp atomic read + f = y; + if (f != 70.0) + abort (); + #pragma omp atomic capture + { f = y; y /= 2.0f; } + if (f != 70.0) + abort (); + #pragma omp atomic read + f = y; + if (f != 35.0) + abort (); + #pragma omp atomic capture + { y /= 2.0f; f = y; } + if (f != 17.5) + abort (); + #pragma omp atomic read + f = y; + if (f != 17.5) + abort (); + return 0; +} + +int x = 6; +float y; + +int +main () +{ + foo <int, float> (); + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/atomic-5.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/atomic-5.C new file mode 100644 index 000000000..e9bd2cc1c --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/atomic-5.C @@ -0,0 +1,79 @@ +// { dg-do run } + +extern "C" void abort (void); + +template <typename T> +void +foo () +{ + extern T v, x1, x2, x3, x4, x5, x6; + #pragma omp atomic capture + v = ++x1; + if (!v) + abort (); + #pragma omp atomic capture + v = x2++; + if (v) + abort (); + #pragma omp atomic read + v = x3; + if (!v) + abort (); + #pragma omp atomic read + v = x4; + if (!v) + abort (); + #pragma omp atomic capture + { v = x5; x5 |= 1; } + if (v) + abort (); + #pragma omp atomic capture + { x6 |= 1; v = x6; } + if (!v) + abort (); +} + +template <typename T> +void +bar () +{ + extern T v, x1, x2; + #pragma omp atomic write + x1 = false; + #pragma omp atomic write + x2 = false; + #pragma omp atomic capture + { ++x1; v = x1; } + if (!v) + abort (); + #pragma omp atomic capture + { v = x2; x2++; } + if (v) + abort (); + #pragma omp atomic write + x1 = false; + #pragma omp atomic write + x2 = false; + #pragma omp atomic capture + { x1++; v = x1; } + if (!v) + abort (); + #pragma omp atomic capture + { v = x2; ++x2; } + if (v) + abort (); +} + +bool v, x1, x2, x3, x4, x5, x6; + +int +main () +{ + #pragma omp atomic write + x3 = true; + #pragma omp atomic write + x4 = true; + foo <bool> (); + bar <bool> (); + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/atomic-6.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/atomic-6.C new file mode 100644 index 000000000..d7d0eb981 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/atomic-6.C @@ -0,0 +1,58 @@ +// { dg-do run } + +extern "C" void abort (void); +long long l, m; +int i, j; + +void +foo (void) +{ + #pragma omp atomic read + i = l; + #pragma omp atomic read + m = j; + if (i != 77 || m != 88) + abort (); + #pragma omp atomic write + l = 1 + i + 6 * 1; + #pragma omp atomic write + j = 170 - 170 + m + 1 * 7; + #pragma omp atomic capture + i = l += 4; + #pragma omp atomic capture + m = j += 4; + if (i != 88 || m != 99) + abort (); + #pragma omp atomic capture + { + i = l; + l += 4; + } + #pragma omp atomic capture + { + m = j; + j += 4; + } + if (i != 88 || m != 99) + abort (); + #pragma omp atomic capture + { + l += 4; + i = l; + } + #pragma omp atomic capture + { + j += 4; + m = j; + } + if (i != 96 || m != 107) + abort (); +} + +int +main () +{ + l = 77; + j = 88; + foo (); +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/atomic-7.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/atomic-7.C new file mode 100644 index 000000000..fe1b4d7aa --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/atomic-7.C @@ -0,0 +1,63 @@ +// { dg-do run } + +extern "C" void abort (void); + +template <typename S, typename T> +void +foo (void) +{ + extern S l, m; + extern T i, j; + + #pragma omp atomic read + i = l; + #pragma omp atomic read + m = j; + if (i != 77 || m != 88) + abort (); + #pragma omp atomic write + l = 1 + i + 6 * 1; + #pragma omp atomic write + j = 170 - 170 + m + 1 * 7; + #pragma omp atomic capture + i = l += 4; + #pragma omp atomic capture + m = j += 4; + if (i != 88 || m != 99) + abort (); + #pragma omp atomic capture + { + i = l; + l += 4; + } + #pragma omp atomic capture + { + m = j; + j += 4; + } + if (i != 88 || m != 99) + abort (); + #pragma omp atomic capture + { + l += 4; + i = l; + } + #pragma omp atomic capture + { + j += 4; + m = j; + } + if (i != 96 || m != 107) + abort (); +} + +long long l, m; +int i, j; + +int +main () +{ + l = 77; + j = 88; + foo <long long, int> (); +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/atomic-8.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/atomic-8.C new file mode 100644 index 000000000..744b3409c --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/atomic-8.C @@ -0,0 +1,137 @@ +// { dg-do run } + +extern "C" void abort (); +int x = 6, cnt; + +int +foo () +{ + return cnt++; +} + +int +main () +{ + int v, *p; + #pragma omp atomic update + x = x + 7; + #pragma omp atomic + x = x + 7 + 6; + #pragma omp atomic update + x = x + 2 * 3; + #pragma omp atomic + x = x * (2 - 1); + #pragma omp atomic read + v = x; + if (v != 32) + abort (); + #pragma omp atomic write + x = 0; + #pragma omp atomic capture + { + v = x; + x = x | 1 ^ 2; + } + if (v != 0) + abort (); + #pragma omp atomic capture + { + v = x; + x = x | 4 | 2; + } + if (v != 3) + abort (); + #pragma omp atomic read + v = x; + if (v != 7) + abort (); + #pragma omp atomic capture + { + x = x ^ 6 & 2; + v = x; + } + if (v != 5) + abort (); + #pragma omp atomic capture + { x = x - (6 + 4); v = x; } + if (v != -5) + abort (); + #pragma omp atomic capture + { v = x; x = x - (1 | 2); } + if (v != -5) + abort (); + #pragma omp atomic read + v = x; + if (v != -8) + abort (); + #pragma omp atomic + x = x * -4 / 2; + #pragma omp atomic read + v = x; + if (v != 16) + abort (); + p = &x; + #pragma omp atomic update + p[foo (), 0] = p[foo (), 0] - 16; + #pragma omp atomic read + v = x; + if (cnt != 2 || v != 0) + abort (); + #pragma omp atomic capture + { + p[foo (), 0] += 6; + v = p[foo (), 0]; + } + if (cnt != 4 || v != 6) + abort (); + #pragma omp atomic capture + { + v = p[foo (), 0]; + p[foo (), 0] += 6; + } + if (cnt != 6 || v != 6) + abort (); + #pragma omp atomic read + v = x; + if (v != 12) + abort (); + #pragma omp atomic capture + { + p[foo (), 0] = p[foo (), 0] + 6; + v = p[foo (), 0]; + } + if (cnt != 9 || v != 18) + abort (); + #pragma omp atomic capture + { + v = p[foo (), 0]; + p[foo (), 0] = p[foo (), 0] + 6; + } + if (cnt != 12 || v != 18) + abort (); + #pragma omp atomic read + v = x; + if (v != 24) + abort (); + #pragma omp atomic capture + { v = p[foo (), 0]; p[foo (), 0]++; } + #pragma omp atomic capture + { v = p[foo (), 0]; ++p[foo (), 0]; } + #pragma omp atomic capture + { p[foo (), 0]++; v = p[foo (), 0]; } + #pragma omp atomic capture + { ++p[foo (), 0]; v = p[foo (), 0]; } + if (cnt != 20 || v != 28) + abort (); + #pragma omp atomic capture + { v = p[foo (), 0]; p[foo (), 0]--; } + #pragma omp atomic capture + { v = p[foo (), 0]; --p[foo (), 0]; } + #pragma omp atomic capture + { p[foo (), 0]--; v = p[foo (), 0]; } + #pragma omp atomic capture + { --p[foo (), 0]; v = p[foo (), 0]; } + if (cnt != 28 || v != 24) + abort (); + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/atomic-9.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/atomic-9.C new file mode 100644 index 000000000..ece1bf3f0 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/atomic-9.C @@ -0,0 +1,148 @@ +// { dg-do run } + +extern "C" void abort (); + +int cnt; + +int +foo () +{ + return cnt++; +} + +template <typename T> +void +bar () +{ + extern T x; + T v, *p; + #pragma omp atomic update + x = x + 7; + #pragma omp atomic + x = x + 7 + 6; + #pragma omp atomic update + x = x + 2 * 3; + #pragma omp atomic + x = x * (2 - 1); + #pragma omp atomic read + v = x; + if (v != 32) + abort (); + #pragma omp atomic write + x = 0; + #pragma omp atomic capture + { + v = x; + x = x | 1 ^ 2; + } + if (v != 0) + abort (); + #pragma omp atomic capture + { + v = x; + x = x | 4 | 2; + } + if (v != 3) + abort (); + #pragma omp atomic read + v = x; + if (v != 7) + abort (); + #pragma omp atomic capture + { + x = x ^ 6 & 2; + v = x; + } + if (v != 5) + abort (); + #pragma omp atomic capture + { x = x - (6 + 4); v = x; } + if (v != -5) + abort (); + #pragma omp atomic capture + { v = x; x = x - (1 | 2); } + if (v != -5) + abort (); + #pragma omp atomic read + v = x; + if (v != -8) + abort (); + #pragma omp atomic + x = x * -4 / 2; + #pragma omp atomic read + v = x; + if (v != 16) + abort (); + p = &x; + #pragma omp atomic update + p[foo (), 0] = p[foo (), 0] - 16; + #pragma omp atomic read + v = x; + if (cnt != 2 || v != 0) + abort (); + #pragma omp atomic capture + { + p[foo (), 0] += 6; + v = p[foo (), 0]; + } + if (cnt != 4 || v != 6) + abort (); + #pragma omp atomic capture + { + v = p[foo (), 0]; + p[foo (), 0] += 6; + } + if (cnt != 6 || v != 6) + abort (); + #pragma omp atomic read + v = x; + if (v != 12) + abort (); + #pragma omp atomic capture + { + p[foo (), 0] = p[foo (), 0] + 6; + v = p[foo (), 0]; + } + if (cnt != 9 || v != 18) + abort (); + #pragma omp atomic capture + { + v = p[foo (), 0]; + p[foo (), 0] = p[foo (), 0] + 6; + } + if (cnt != 12 || v != 18) + abort (); + #pragma omp atomic read + v = x; + if (v != 24) + abort (); + #pragma omp atomic capture + { v = p[foo (), 0]; p[foo (), 0]++; } + #pragma omp atomic capture + { v = p[foo (), 0]; ++p[foo (), 0]; } + #pragma omp atomic capture + { p[foo (), 0]++; v = p[foo (), 0]; } + #pragma omp atomic capture + { ++p[foo (), 0]; v = p[foo (), 0]; } + if (cnt != 20 || v != 28) + abort (); + #pragma omp atomic capture + { v = p[foo (), 0]; p[foo (), 0]--; } + #pragma omp atomic capture + { v = p[foo (), 0]; --p[foo (), 0]; } + #pragma omp atomic capture + { p[foo (), 0]--; v = p[foo (), 0]; } + #pragma omp atomic capture + { --p[foo (), 0]; v = p[foo (), 0]; } + if (cnt != 28 || v != 24) + abort (); +} + +int x = 6; + +int +main () +{ + bar <int> (); + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/c++.exp b/gcc-4.9/libgomp/testsuite/libgomp.c++/c++.exp new file mode 100644 index 000000000..88e017e4e --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/c++.exp @@ -0,0 +1,64 @@ +load_lib libgomp-dg.exp +load_gcc_lib gcc-dg.exp + +global shlib_ext + +set shlib_ext [get_shlib_extension] +set lang_link_flags "-lstdc++" +set lang_test_file_found 0 +set lang_library_path "../libstdc++-v3/src/.libs" + +# Initialize dg. +dg-init + +# Turn on OpenMP. +lappend ALWAYS_CFLAGS "additional_flags=-fopenmp" + +set blddir [lookfor_file [get_multilibs] libgomp] + + +if { $blddir != "" } { + # Look for a static libstdc++ first. + if [file exists "${blddir}/${lang_library_path}/libstdc++.a"] { + set lang_test_file "${lang_library_path}/libstdc++.a" + set lang_test_file_found 1 + # We may have a shared only build, so look for a shared libstdc++. + } elseif [file exists "${blddir}/${lang_library_path}/libstdc++.${shlib_ext}"] { + set lang_test_file "${lang_library_path}/libstdc++.${shlib_ext}" + set lang_test_file_found 1 + } else { + puts "No libstdc++ library found, will not execute c++ tests" + } +} elseif { [info exists GXX_UNDER_TEST] } { + set lang_test_file_found 1 + # Needs to exist for libgomp.exp. + set lang_test_file "" +} else { + puts "GXX_UNDER_TEST not defined, will not execute c++ tests" +} + +if { $lang_test_file_found } { + # Gather a list of all tests. + set tests [lsort [glob -nocomplain $srcdir/$subdir/*.C]] + + if { $blddir != "" } { + set ld_library_path "$always_ld_library_path:${blddir}/${lang_library_path}" + } else { + set ld_library_path "$always_ld_library_path" + } + append ld_library_path [gcc-set-multilib-library-path $GCC_UNDER_TEST] + set_ld_library_path_env_vars + + set flags_file "${blddir}/../libstdc++-v3/scripts/testsuite_flags" + if { [file exists $flags_file] } { + set libstdcxx_includes [exec sh $flags_file --build-includes] + } else { + set libstdcxx_includes "" + } + + # Main loop. + dg-runtest $tests "" $libstdcxx_includes +} + +# All done. +dg-finish diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/cancel-for-1.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/cancel-for-1.C new file mode 100644 index 000000000..8183a2d06 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/cancel-for-1.C @@ -0,0 +1,29 @@ +// { dg-do run } +// { dg-set-target-env-var OMP_CANCELLATION "true" } + +#include <omp.h> +#include "cancel-test.h" + +int +main () +{ + { + S c; + #pragma omp parallel num_threads (32) + { + S a, b; + int i; + #pragma omp for private (b) firstprivate (c) + for (i = 0; i < 1000; ++i) + { + S d; + #pragma omp cancel for + if (omp_get_cancellation ()) + abort (); + b.bump (); + c.bump (); + } + } + } + S::verify (); +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/cancel-for-2.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/cancel-for-2.C new file mode 100644 index 000000000..1595a239c --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/cancel-for-2.C @@ -0,0 +1,126 @@ +// { dg-do run } +// { dg-set-target-env-var OMP_CANCELLATION "true" } + +#include <omp.h> +#include "cancel-test.h" + +__attribute__((noinline, noclone)) int +foo (int *x) +{ + S a, b, c, d, e; + int v = 0, w = 0; + #pragma omp parallel num_threads (32) shared (v, w) private (c, d) firstprivate (e) + { + S g; + int i; + c.bump (); + e.bump (); + #pragma omp for private (d, g) firstprivate (b) + for (i = 0; i < 1000; ++i) + { + b.bump (); + d.bump (); + g.bump (); + #pragma omp cancel for if (x[0]) + abort (); + } + #pragma omp for private (d, g) firstprivate (b) + for (i = 0; i < 1000; ++i) + { + b.bump (); + d.bump (); + g.bump (); + #pragma omp cancel for if (x[1]) + #pragma omp atomic + v++; + } + #pragma omp for private (d, g) firstprivate (b) + for (i = 0; i < 1000; ++i) + { + b.bump (); + d.bump (); + g.bump (); + #pragma omp cancel for if (x[2]) + #pragma omp atomic + w += 8; + } + #pragma omp for private (d, g) firstprivate (b) + for (i = 0; i < 1000; ++i) + { + b.bump (); + d.bump (); + g.bump (); + #pragma omp cancel for if (x[3]) + #pragma omp atomic + v += 2; + } + } + if (v != 3000 || w != 0) + abort (); + #pragma omp parallel num_threads (32) shared (v, w) private (c, d) firstprivate (e) + { + S g, h; + int i; + c.bump (); + e.bump (); + /* None of these cancel directives should actually cancel anything, + but the compiler shouldn't know that and thus should use cancellable + barriers at the end of all the workshares. */ + #pragma omp cancel parallel if (omp_get_thread_num () == 1 && x[4]) + #pragma omp for private (d, g) firstprivate (b) + for (i = 0; i < 1000; ++i) + { + b.bump (); + d.bump (); + g.bump (); + #pragma omp cancel for if (x[0]) + abort (); + } + #pragma omp cancel parallel if (omp_get_thread_num () == 2 && x[4]) + #pragma omp for private (d, g) firstprivate (b) + for (i = 0; i < 1000; ++i) + { + b.bump (); + d.bump (); + g.bump (); + #pragma omp cancel for if (x[1]) + #pragma omp atomic + v++; + } + #pragma omp cancel parallel if (omp_get_thread_num () == 3 && x[4]) + #pragma omp for private (d, g) firstprivate (b) + for (i = 0; i < 1000; ++i) + { + b.bump (); + d.bump (); + g.bump (); + #pragma omp cancel for if (x[2]) + #pragma omp atomic + w += 8; + } + #pragma omp cancel parallel if (omp_get_thread_num () == 4 && x[4]) + #pragma omp for private (d, g) firstprivate (b) + for (i = 0; i < 1000; ++i) + { + b.bump (); + d.bump (); + g.bump (); + #pragma omp cancel for if (x[3]) + #pragma omp atomic + v += 2; + } + #pragma omp cancel parallel if (omp_get_thread_num () == 5 && x[4]) + } + if (v != 6000 || w != 0) + abort (); + return 0; +} + +int +main () +{ + int x[] = { 1, 0, 1, 0, 0 }; + if (omp_get_cancellation ()) + foo (x); + S::verify (); +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/cancel-parallel-1.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/cancel-parallel-1.C new file mode 100644 index 000000000..033d676b3 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/cancel-parallel-1.C @@ -0,0 +1,18 @@ +// { dg-do run } +// { dg-set-target-env-var OMP_CANCELLATION "true" } + +#include <omp.h> +#include "cancel-test.h" + +int +main () +{ + #pragma omp parallel num_threads (32) + { + S a; + #pragma omp cancel parallel + if (omp_get_cancellation ()) + abort (); + } + S::verify (); +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/cancel-parallel-2.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/cancel-parallel-2.C new file mode 100644 index 000000000..340423b55 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/cancel-parallel-2.C @@ -0,0 +1,57 @@ +// { dg-do run } +// { dg-set-target-env-var OMP_CANCELLATION "true" } + +#include <unistd.h> +#include <omp.h> +#include "cancel-test.h" + +static void +foo (int *x) +{ + S a, b, c; + #pragma omp parallel firstprivate(x, c) num_threads (32) private (b) + { + S d; + b.bump (); + c.bump (); + int thr = omp_get_thread_num (); + switch (x[thr]) + { + case 4: + #pragma omp cancel parallel + break; + case 3: + #pragma omp task + usleep (1000); + #pragma omp task + usleep (2000); + #pragma omp task + usleep (4000); + break; + case 2: + usleep (1000); + /* FALLTHRU */ + case 1: + #pragma omp cancellation point parallel + break; + } + #pragma omp barrier + if (omp_get_cancellation ()) + abort (); + } +} + +int +main () +{ + int i, j, x[32] = { 0, 1, 2, 4, 2, 2, 1, 0 }; + foo (x); + for (i = 0; i < 32; i++) + { + for (j = 0; j < 32; j++) + x[j] = rand () & 3; + x[rand () & 31] = 4; + foo (x); + } + S::verify (); +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/cancel-parallel-3.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/cancel-parallel-3.C new file mode 100644 index 000000000..9db7a4f7b --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/cancel-parallel-3.C @@ -0,0 +1,50 @@ +// { dg-do run } +// { dg-set-target-env-var OMP_CANCELLATION "true" } + +#include <omp.h> +#include <unistd.h> +#include "cancel-test.h" + +static inline void +do_some_work (void) +{ + asm volatile ("" : : : "memory"); +} + +void +foo () +{ + S a, b, c; + omp_set_dynamic (0); + omp_set_schedule (omp_sched_static, 1); + #pragma omp parallel num_threads (16) private (b) firstprivate (c) + { + S d; + int i, j; + b.bump (); + c.bump (); + do_some_work (); + #pragma omp barrier + if (omp_get_thread_num () == 1) + { + sleep (2); + #pragma omp cancellation point parallel + } + for (j = 3; j <= 16; j++) + #pragma omp for schedule (runtime) nowait + for (i = 0; i < j; i++) + do_some_work (); + if (omp_get_thread_num () == 0) + { + sleep (1); + #pragma omp cancel parallel + } + } +} + +int +main () +{ + foo (); + S::verify (); +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/cancel-sections-1.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/cancel-sections-1.C new file mode 100644 index 000000000..81a9c3520 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/cancel-sections-1.C @@ -0,0 +1,43 @@ +// { dg-do run } +// { dg-set-target-env-var OMP_CANCELLATION "true" } + +#include <omp.h> +#include "cancel-test.h" + +int +main () +{ + if (!omp_get_cancellation ()) + return 0; + #pragma omp parallel num_threads (32) + { + S a; + #pragma omp sections + { + { + S b; + #pragma omp cancel sections + abort (); + } + #pragma omp section + { + S c; + #pragma omp cancel sections + abort (); + } + #pragma omp section + { + S d; + #pragma omp cancel sections + abort (); + } + #pragma omp section + { + S e; + #pragma omp cancel sections + abort (); + } + } + } + S::verify (); +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/cancel-taskgroup-1.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/cancel-taskgroup-1.C new file mode 100644 index 000000000..4f66859d1 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/cancel-taskgroup-1.C @@ -0,0 +1,4 @@ +// { dg-do run } +// { dg-set-target-env-var OMP_CANCELLATION "true" } + +#include "../libgomp.c/cancel-taskgroup-1.c" diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/cancel-taskgroup-2.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/cancel-taskgroup-2.C new file mode 100644 index 000000000..d4a02e911 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/cancel-taskgroup-2.C @@ -0,0 +1,4 @@ +// { dg-do run } +// { dg-set-target-env-var OMP_CANCELLATION "true" } + +#include "../libgomp.c/cancel-taskgroup-2.c" diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/cancel-taskgroup-3.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/cancel-taskgroup-3.C new file mode 100644 index 000000000..c897265ef --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/cancel-taskgroup-3.C @@ -0,0 +1,58 @@ +// { dg-do run } +// { dg-set-target-env-var OMP_CANCELLATION "true" } + +#include <unistd.h> +#include <omp.h> +#include "cancel-test.h" + +void +foo () +{ + S a, b, c, d, e, f; + #pragma omp parallel private (c, d) firstprivate (e, f) + #pragma omp taskgroup + { + c.bump (); + e.bump (); + #pragma omp task firstprivate (b, f) private (d) + { + S h; + b.bump (); + d.bump (); + f.bump (); + #pragma omp cancel taskgroup + if (omp_get_cancellation ()) + abort (); + } + } + #pragma omp parallel private (c, d) firstprivate (e, f) + { + #pragma omp barrier + #pragma omp single + #pragma omp taskgroup + { + int i; + c.bump (); + e.bump (); + for (i = 0; i < 50; i++) + #pragma omp task firstprivate (b, f) private (d) + { + S h; + b.bump (); + d.bump (); + f.bump (); + #pragma omp cancellation point taskgroup + usleep (30); + #pragma omp cancel taskgroup if (i > 5) + } + } + usleep (10); + } +} + +int +main () +{ + foo (); + S::verify (); +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/cancel-test.h b/gcc-4.9/libgomp/testsuite/libgomp.c++/cancel-test.h new file mode 100644 index 000000000..776d6ee63 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/cancel-test.h @@ -0,0 +1,47 @@ +#include <stdlib.h> +#include <omp.h> + +struct S +{ + static int s; + int v; + S () + { + #pragma omp atomic + s++; + } + + S (int x) + { + #pragma omp atomic + s++; + v = x; + } + + ~S () + { + #pragma omp atomic + s--; + } + + S (const S &x) + { + #pragma omp atomic + s++; + v = x.v; + } + + static void + verify () + { + if (s) abort (); + } + + void + bump () + { + v++; + } +}; + +int S::s = 0; diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/collapse-1.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/collapse-1.C new file mode 100644 index 000000000..132d35cf4 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/collapse-1.C @@ -0,0 +1,29 @@ +// { dg-do run } + +#include <string.h> +#include <stdlib.h> + +int +main () +{ + int i, j, k, l = 0; + int a[3][3][3]; + + memset (a, '\0', sizeof (a)); + #pragma omp parallel for collapse(4 - 1) schedule(static, 4) + for (i = 0; i < 2; i++) + for (j = 0; j < 2; j++) + for (k = 0; k < 2; k++) + a[i][j][k] = i + j * 4 + k * 16; + #pragma omp parallel + { + #pragma omp for collapse(2) reduction(|:l) private (k) + for (i = 0; i < 2; i++) + for (j = 0; j < 2; j++) + for (k = 0; k < 2; k++) + if (a[i][j][k] != i + j * 4 + k * 16) + l = 1; + } + if (l) + abort (); +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/collapse-2.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/collapse-2.C new file mode 100644 index 000000000..a42a1f07f --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/collapse-2.C @@ -0,0 +1,371 @@ +// { dg-do run } + +#include <omp.h> +typedef __PTRDIFF_TYPE__ ptrdiff_t; +extern "C" void abort (); + +template <typename T> +class I +{ +public: + typedef ptrdiff_t difference_type; + I (); + ~I (); + I (T *); + I (const I &); + T &operator * (); + T *operator -> (); + T &operator [] (const difference_type &) const; + I &operator = (const I &); + I &operator ++ (); + I operator ++ (int); + I &operator -- (); + I operator -- (int); + I &operator += (const difference_type &); + I &operator -= (const difference_type &); + I operator + (const difference_type &) const; + I operator - (const difference_type &) const; + template <typename S> friend bool operator == (I<S> &, I<S> &); + template <typename S> friend bool operator == (const I<S> &, const I<S> &); + template <typename S> friend bool operator < (I<S> &, I<S> &); + template <typename S> friend bool operator < (const I<S> &, const I<S> &); + template <typename S> friend bool operator <= (I<S> &, I<S> &); + template <typename S> friend bool operator <= (const I<S> &, const I<S> &); + template <typename S> friend bool operator > (I<S> &, I<S> &); + template <typename S> friend bool operator > (const I<S> &, const I<S> &); + template <typename S> friend bool operator >= (I<S> &, I<S> &); + template <typename S> friend bool operator >= (const I<S> &, const I<S> &); + template <typename S> friend typename I<S>::difference_type operator - (I<S> &, I<S> &); + template <typename S> friend typename I<S>::difference_type operator - (const I<S> &, const I<S> &); + template <typename S> friend I<S> operator + (typename I<S>::difference_type , const I<S> &); +private: + T *p; +}; +template <typename T> I<T>::I () : p (0) {} +template <typename T> I<T>::~I () { p = (T *) 0; } +template <typename T> I<T>::I (T *x) : p (x) {} +template <typename T> I<T>::I (const I &x) : p (x.p) {} +template <typename T> T &I<T>::operator * () { return *p; } +template <typename T> T *I<T>::operator -> () { return p; } +template <typename T> T &I<T>::operator [] (const difference_type &x) const { return p[x]; } +template <typename T> I<T> &I<T>::operator = (const I &x) { p = x.p; return *this; } +template <typename T> I<T> &I<T>::operator ++ () { ++p; return *this; } +template <typename T> I<T> I<T>::operator ++ (int) { return I (p++); } +template <typename T> I<T> &I<T>::operator -- () { --p; return *this; } +template <typename T> I<T> I<T>::operator -- (int) { return I (p--); } +template <typename T> I<T> &I<T>::operator += (const difference_type &x) { p += x; return *this; } +template <typename T> I<T> &I<T>::operator -= (const difference_type &x) { p -= x; return *this; } +template <typename T> I<T> I<T>::operator + (const difference_type &x) const { return I (p + x); } +template <typename T> I<T> I<T>::operator - (const difference_type &x) const { return I (p - x); } +template <typename T> bool operator == (I<T> &x, I<T> &y) { return x.p == y.p; } +template <typename T> bool operator == (const I<T> &x, const I<T> &y) { return x.p == y.p; } +template <typename T> bool operator != (I<T> &x, I<T> &y) { return !(x == y); } +template <typename T> bool operator != (const I<T> &x, const I<T> &y) { return !(x == y); } +template <typename T> bool operator < (I<T> &x, I<T> &y) { return x.p < y.p; } +template <typename T> bool operator < (const I<T> &x, const I<T> &y) { return x.p < y.p; } +template <typename T> bool operator <= (I<T> &x, I<T> &y) { return x.p <= y.p; } +template <typename T> bool operator <= (const I<T> &x, const I<T> &y) { return x.p <= y.p; } +template <typename T> bool operator > (I<T> &x, I<T> &y) { return x.p > y.p; } +template <typename T> bool operator > (const I<T> &x, const I<T> &y) { return x.p > y.p; } +template <typename T> bool operator >= (I<T> &x, I<T> &y) { return x.p >= y.p; } +template <typename T> bool operator >= (const I<T> &x, const I<T> &y) { return x.p >= y.p; } +template <typename T> typename I<T>::difference_type operator - (I<T> &x, I<T> &y) { return x.p - y.p; } +template <typename T> typename I<T>::difference_type operator - (const I<T> &x, const I<T> &y) { return x.p - y.p; } +template <typename T> I<T> operator + (typename I<T>::difference_type x, const I<T> &y) { return I<T> (x + y.p); } + +template <typename T> +class J +{ +public: + J(const I<T> &x, const I<T> &y) : b (x), e (y) {} + const I<T> &begin (); + const I<T> &end (); +private: + I<T> b, e; +}; + +template <typename T> const I<T> &J<T>::begin () { return b; } +template <typename T> const I<T> &J<T>::end () { return e; } + +int results[2000]; + +void +f1 (J<int> x, J<int> y, J<int> z) +{ + I<int> i, j, k; + int l, f = 0, n = 0, m = 0; +#pragma omp parallel shared (i, j, k, l) firstprivate (f) \ + reduction (+:n, m) num_threads (8) + { + #pragma omp for lastprivate (i, j, k, l) schedule (static, 9) \ + collapse (4) + for (i = x.begin (); i < x.end (); ++i) + for (j = y.begin (); j <= y.end (); j += 1) + for (l = 0; l < 1; l++) + for (k = z.begin () + 3; k < z.end () - 3; k++) + if (omp_get_num_threads () == 8 + && ((*i + 2) * 12 + (*j + 5) * 4 + (*k - 13) + != (omp_get_thread_num () * 9 + f++))) + n++; + else + m++; + } + if (n || i != x.end () || j != y.end () + 1 || k != z.end () - 3 + || m != 72 || l != 1) + abort (); +} + +void +f2 (J<int> x, J<int> y, J<int> z) +{ + int f = 0, n = 0, m = 0; +#pragma omp parallel for firstprivate (f) reduction (+:n, m) \ + num_threads (8) schedule (static, 9) \ + collapse (6 - 2) + for (I<int> i = x.end () - 1; i >= x.begin (); --i) + for (int l = -131; l >= -131; l--) + for (I<int> j = y.end (); j > y.begin () - 1; j -= 1) + { + for (I<int> k = z.end () - 4; k >= z.begin () + 3; k--) + if (omp_get_num_threads () == 8 + && ((3 - *i) * 12 + (-3 - *j) * 4 + (16 - *k) + != (omp_get_thread_num () * 9 + f++))) + n++; + else + m++; + } + if (n || m != 72) + abort (); +} + +template <typename T> +void +f3 (J<int> x, J<int> y, J<int> z) +{ + I<int> i, j, k; + int l, f = 0, n = 0, m = 0; +#pragma omp parallel shared (i, j, k, l) firstprivate (f) \ + reduction (+:n, m) num_threads (8) + { + #pragma omp for lastprivate (i, j, k, l) schedule (static, 9) \ + collapse (4) + for (i = x.begin (); i < x.end (); ++i) + for (j = y.begin (); j <= y.end (); j += 1) + for (k = z.begin () + 3; k < z.end () - 3; k++) + for (l = 7; l <= 7; l++) + if (omp_get_num_threads () == 8 + && ((*i + 2) * 12 + (*j + 5) * 4 + (*k - 13) + != (omp_get_thread_num () * 9 + f++))) + n++; + else + m++; + } + if (n || i != x.end () || j != y.end () + 1 || k != z.end () - 3 + || m != 72 || l != 8) + abort (); +} + +template <typename T> +void +f4 (J<int> x, J<int> y, J<int> z) +{ + int f = 0, n = 0, m = 0; +#pragma omp parallel for firstprivate (f) reduction (+:n, m) \ + num_threads (8) schedule (static, 9) \ + collapse (5 - 2) + for (I<int> i = x.end () - 1; i >= x.begin (); --i) + { + for (I<int> j = y.end (); j > y.begin () - 1; j -= 1) + { + for (I<int> k = z.end () - 4; k >= z.begin () + 3; k--) + if (omp_get_num_threads () == 8 + && ((3 - *i) * 12 + (-3 - *j) * 4 + (16 - *k) + != (omp_get_thread_num () * 9 + f++))) + n++; + else + m++; + } + } + if (n || m != 72) + abort (); +} + +template <typename T> +void +f5 (J<int> x, J<int> y, J<int> z) +{ + I<int> i, j, k; + int f = 0, n = 0, m = 0; +#pragma omp parallel shared (i, j, k) firstprivate (f) \ + reduction (+:n, m) num_threads (8) + { + #pragma omp for lastprivate (i, j, k) schedule (static, 9) \ + collapse (3) + for (i = x.begin (); i < x.end (); ++i) + for (j = y.begin (); j <= y.end (); j += (T) 1) + { + for (k = z.begin () + 3; k < z.end () - 3; k++) + if (omp_get_num_threads () == 8 + && ((*i + 2) * 12 + (*j + 5) * 4 + (*k - 13) + != (omp_get_thread_num () * 9 + f++))) + n++; + else + m++; + } + } + if (n || i != x.end () || j != y.end () + 1 || k != z.end () - 3 + || m != 72) + abort (); +} + +template <typename T> +void +f6 (J<int> x, J<int> y, J<int> z) +{ + int f = 0, n = 0, m = 0; +#pragma omp parallel for firstprivate (f) reduction (+:n, m) \ + num_threads (8) schedule (static, 9) \ + collapse (5 - 2) + for (I<int> i = x.end () - 1; i >= x.begin (); --i) + { + for (I<int> j = y.end (); j > y.begin () - 1; j -= 1) + { + for (I<int> k = z.end () - 4; k >= z.begin () + (T) 3; k--) + if (omp_get_num_threads () == 8 + && ((3 - *i) * 12 + (-3 - *j) * 4 + (16 - *k) + != (omp_get_thread_num () * 9 + f++))) + n++; + else + m++; + } + } + if (n || m != 72) + abort (); +} + +template <typename T> +void +f7 (J<T> x, J<T> y, J<T> z) +{ + I<T> i, j, k, o = y.begin (); + T l, f = 0, n = 0, m = 0; +#pragma omp parallel shared (i, j, k, l) firstprivate (f) \ + reduction (+:n, m) num_threads (8) + { + #pragma omp for lastprivate (i, j, k, l) schedule (static, 9) \ + collapse (4) + for (i = x.begin (); i < x.end (); ++i) + for (j = y.begin (); j <= y.end (); j += 1) + for (l = *o; l <= *o; l = 1 + l) + for (k = z.begin () + 3; k < z.end () - 3; k++) + if (omp_get_num_threads () == 8 + && ((*i + 2) * 12 + (*j + 5) * 4 + (*k - 13) + != (omp_get_thread_num () * 9 + f++))) + n++; + else + m++; + } + if (n || i != x.end () || j != y.end () + 1 || k != z.end () - 3 + || m != 72 || l != *o + 1) + abort (); +} + +template <typename T> +void +f8 (J<T> x, J<T> y, J<T> z) +{ + T f = 0, n = 0, m = 0; +#pragma omp parallel for firstprivate (f) reduction (+:n, m) \ + num_threads (8) schedule (static, 9) \ + collapse (6 - 2) + for (I<T> i = x.end () - 1; i >= x.begin (); --i) + for (T l = 0; l < 1; l++) + for (I<T> j = y.end (); j > y.begin () - 1; j -= 1) + { + for (I<T> k = z.end () - 4; k >= z.begin () + 3; k--) + if (omp_get_num_threads () == 8 + && ((3 - *i) * 12 + (-3 - *j) * 4 + (16 - *k) + != (omp_get_thread_num () * 9 + f++))) + n++; + else + m++; + } + if (n || m != 72) + abort (); +} + +template <typename S, typename T> +void +f9 (J<T> x, J<T> y, J<T> z) +{ + S i, j, k, o = y.begin (); + T l, f = 0, n = 0, m = 0; +#pragma omp parallel shared (i, j, k, l) firstprivate (f) \ + reduction (+:n, m) num_threads (8) + { + #pragma omp for lastprivate (i, j, k, l) schedule (static, 9) \ + collapse (4) + for (i = x.begin (); i < x.end (); ++i) + for (j = y.begin (); j <= y.end (); j += 1) + for (l = *o; l <= *o; l = 1 + l) + for (k = z.begin () + 3; k < z.end () - 3; k++) + if (omp_get_num_threads () == 8 + && ((*i + 2) * 12 + (*j + 5) * 4 + (*k - 13) + != (omp_get_thread_num () * 9 + f++))) + n++; + else + m++; + } + if (n || i != x.end () || j != y.end () + 1 || k != z.end () - 3 + || m != 72 || l != *o + 1) + abort (); +} + +template <typename S, typename T> +void +f10 (J<T> x, J<T> y, J<T> z) +{ + T f = 0, n = 0, m = 0; +#pragma omp parallel for firstprivate (f) reduction (+:n, m) \ + num_threads (8) schedule (static, 9) \ + collapse (6 - 2) + for (S i = x.end () - 1; i >= x.begin (); --i) + for (T l = 0; l < 1; l++) + for (S j = y.end (); j > y.begin () - 1; j -= 1) + { + for (S k = z.end () - 4; k >= z.begin () + 3; k--) + if (omp_get_num_threads () == 8 + && ((3 - *i) * 12 + (-3 - *j) * 4 + (16 - *k) + != (omp_get_thread_num () * 9 + f++))) + n++; + else + m++; + } + if (n || m != 72) + abort (); +} + +int +main () +{ + int a[2000]; + long b[2000]; + for (int i = 0; i < 2000; i++) + { + a[i] = i - 1000; + b[i] = i - 1000; + } + J<int> x (&a[998], &a[1004]); + J<int> y (&a[995], &a[997]); + J<int> z (&a[1010], &a[1020]); + f1 (x, y, z); + f2 (x, y, z); + f3 <int> (x, y, z); + f4 <int> (x, y, z); + f5 <int> (x, y, z); + f6 <int> (x, y, z); + f7 <int> (x, y, z); + f8 <int> (x, y, z); + f9 <I<int>, int> (x, y, z); + f10 <I<int>, int> (x, y, z); +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/copyin-1.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/copyin-1.C new file mode 100644 index 000000000..bc12be2d2 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/copyin-1.C @@ -0,0 +1,34 @@ +// { dg-do run } +// { dg-require-effective-target tls_runtime } + +#include <omp.h> + +extern "C" void abort (void); + +int thr = 32; +#pragma omp threadprivate (thr) + +int +main (void) +{ + int l = 0; + + omp_set_dynamic (0); + omp_set_num_threads (6); + +#pragma omp parallel copyin (thr) reduction (||:l) + { + l = thr != 32; + thr = omp_get_thread_num () + 11; + } + + if (l || thr != 11) + abort (); + +#pragma omp parallel reduction (||:l) + l = thr != omp_get_thread_num () + 11; + + if (l) + abort (); + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/copyin-2.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/copyin-2.C new file mode 100644 index 000000000..024f59980 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/copyin-2.C @@ -0,0 +1,34 @@ +// { dg-do run } +// { dg-require-effective-target tls_runtime } + +#include <omp.h> + +extern "C" void abort (void); + +struct S { int t; char buf[64]; } thr = { 32, "" }; +#pragma omp threadprivate (thr) + +int +main (void) +{ + int l = 0; + + omp_set_dynamic (0); + omp_set_num_threads (6); + +#pragma omp parallel copyin (thr) reduction (||:l) + { + l = thr.t != 32; + thr.t = omp_get_thread_num () + 11; + } + + if (l || thr.t != 11) + abort (); + +#pragma omp parallel reduction (||:l) + l = thr.t != omp_get_thread_num () + 11; + + if (l) + abort (); + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/ctor-1.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/ctor-1.C new file mode 100644 index 000000000..2ad3b3a6e --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/ctor-1.C @@ -0,0 +1,65 @@ +// { dg-do run } + +#include <omp.h> +#include <assert.h> + +struct B +{ + static int icount; + static int dcount; + static int xcount; + + B(); + B(const B &); + ~B(); + B& operator=(const B &); + void doit(); +}; + +int B::icount; +int B::dcount; +int B::xcount; + +B::B() +{ + #pragma omp atomic + icount++; +} + +B::~B() +{ + #pragma omp atomic + dcount++; +} + +void B::doit() +{ + #pragma omp atomic + xcount++; +} + +static int nthreads; + +void foo() +{ + B b; + #pragma omp parallel private(b) + { + #pragma omp master + nthreads = omp_get_num_threads (); + b.doit(); + } +} + +int main() +{ + omp_set_dynamic (0); + omp_set_num_threads (4); + foo(); + + assert (B::xcount == nthreads); + assert (B::icount == nthreads+1); + assert (B::dcount == nthreads+1); + + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/ctor-10.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/ctor-10.C new file mode 100644 index 000000000..f46e45ec4 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/ctor-10.C @@ -0,0 +1,78 @@ +// { dg-do run } +// { dg-require-effective-target tls_runtime } + +#include <omp.h> +#include <assert.h> + +#define N 10 +#define THR 4 + +struct B +{ + B(); + B(const B &); + ~B(); + B& operator=(const B &); + void doit(); + static B *base; + static B *threadbase; +#pragma omp threadprivate(threadbase) +}; + +B *B::base; +B *B::threadbase; +static unsigned cmask[THR]; +static unsigned dmask[THR]; + +B::B() +{ + assert (base == 0); +} + +B::B(const B &b) +{ + unsigned index = &b - base; + assert (index < N); + cmask[omp_get_thread_num()] |= 1u << index; +} + +B::~B() +{ + if (threadbase) + { + unsigned index = this - threadbase; + assert (index < N); + dmask[omp_get_thread_num()] |= 1u << index; + } +} + +void foo() +{ + B b[N]; + + B::base = b; + + #pragma omp parallel firstprivate(b) + { + assert (omp_get_num_threads () == THR); + B::threadbase = b; + } + + B::threadbase = 0; +} + +int main() +{ + omp_set_dynamic (0); + omp_set_num_threads (THR); + foo(); + + for (int i = 0; i < THR; ++i) + { + unsigned xmask = (1u << N) - 1; + assert (cmask[i] == xmask); + assert (dmask[i] == xmask); + } + + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/ctor-11.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/ctor-11.C new file mode 100644 index 000000000..8f501e8c8 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/ctor-11.C @@ -0,0 +1,100 @@ +// PR c++/36308 +// { dg-do run } + +#include <omp.h> +#include <assert.h> + +#define N 10 + +struct B +{ + static int icount; + static int ccount; + static int dcount; + static int xcount; + + B (); + B (const B &); + virtual ~B (); + B& operator= (const B &); + void doit (); + static void clear () { icount = ccount = dcount = xcount = 0; } +}; + +int B::icount; +int B::ccount; +int B::dcount; +int B::xcount; + +B::B () +{ + #pragma omp atomic + icount++; +} + +B::B (const B &) +{ + #pragma omp atomic + ccount++; +} + +B::~B () +{ + #pragma omp atomic + dcount++; +} + +void +B::doit () +{ + #pragma omp atomic + xcount++; +} + +static int nthreads; + +void +test1 () +{ + B b[N]; + #pragma omp parallel private (b) + { + #pragma omp master + nthreads = omp_get_num_threads (); + b[0].doit (); + } +} + +void +test2 () +{ + B b; + #pragma omp parallel firstprivate (b) + { + #pragma omp single + nthreads = omp_get_num_threads (); + b.doit (); + } +} + +int +main () +{ + omp_set_dynamic (0); + omp_set_num_threads (4); + + B::clear (); + test1 (); + assert (B::xcount == nthreads); + assert (B::ccount == 0); + assert (B::icount == (nthreads + 1) * N); + assert (B::dcount == (nthreads + 1) * N); + + B::clear (); + test2 (); + assert (B::xcount == nthreads); + assert (B::ccount == nthreads); + assert (B::icount == 1); + assert (B::dcount == nthreads + 1); + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/ctor-12.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/ctor-12.C new file mode 100644 index 000000000..8bd53de3f --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/ctor-12.C @@ -0,0 +1,65 @@ +// PR c++/36308 +// { dg-do run } + +extern "C" void abort (); + +static int n; + +struct A +{ + A () + { + l = 0; + #pragma omp atomic + ctors++; + } + A (const A &x) + { + l = x.l; + #pragma omp atomic + copyctors++; + } + virtual A& operator= (const A &x) + { + l = x.l; + #pragma omp atomic + assignops++; + return *this; + } + virtual ~A () + { + #pragma omp atomic + dtors++; + } + int l; + static int ctors, dtors, copyctors, assignops; +}; + +int A::ctors; +int A::dtors; +int A::copyctors; +int A::assignops; + +int +main () +{ + A a; +#pragma omp parallel private (a) + { + a.l = 6; + #pragma omp single copyprivate (a) + { + a.l = 3; + } + if (a.l != 3) + abort (); + #pragma omp atomic + n++; + } + if (A::ctors != n + 1 + || A::copyctors != 0 + || A::dtors != n + || A::assignops != n - 1) + abort (); + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/ctor-2.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/ctor-2.C new file mode 100644 index 000000000..6611c592f --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/ctor-2.C @@ -0,0 +1,76 @@ +// { dg-do run } + +#include <omp.h> +#include <assert.h> + +struct B +{ + static int ccount; + static int dcount; + static int xcount; + static B *expected; + + B(); + B(int); + B(const B &); + ~B(); + B& operator=(const B &); + void doit(); +}; + +int B::ccount; +int B::dcount; +int B::xcount; +B * B::expected; + +B::B(int) +{ + expected = this; +} + +B::B(const B &b) +{ + #pragma omp atomic + ccount++; + assert (&b == expected); +} + +B::~B() +{ + #pragma omp atomic + dcount++; +} + +void B::doit() +{ + #pragma omp atomic + xcount++; + assert (this != expected); +} + +static int nthreads; + +void foo() +{ + B b(0); + + #pragma omp parallel firstprivate(b) + { + #pragma omp master + nthreads = omp_get_num_threads (); + b.doit(); + } +} + +int main() +{ + omp_set_dynamic (0); + omp_set_num_threads (4); + foo(); + + assert (B::xcount == nthreads); + assert (B::ccount == nthreads); + assert (B::dcount == nthreads+1); + + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/ctor-3.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/ctor-3.C new file mode 100644 index 000000000..e65e4ea52 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/ctor-3.C @@ -0,0 +1,89 @@ +// { dg-do run } + +#include <omp.h> +#include <assert.h> + +struct B +{ + static int icount; + static int dcount; + static int ccount; + static B *e_inner; + static B *e_outer; + + B(); + B(int); + B(const B &); + ~B(); + B& operator=(const B &); + void doit(); +}; + +int B::icount; +int B::dcount; +int B::ccount; +B * B::e_inner; +B * B::e_outer; + +B::B() +{ + #pragma omp atomic + icount++; +} + +B::B(int) +{ + e_outer = this; +} + +B::~B() +{ + #pragma omp atomic + dcount++; +} + +B& B::operator= (const B &b) +{ + assert (&b == e_inner); + assert (this == e_outer); + #pragma omp atomic + ccount++; + return *this; +} + +void B::doit() +{ + #pragma omp critical + { + assert (e_inner == 0); + e_inner = this; + } +} + +static int nthreads; + +void foo() +{ + B b(0); + + #pragma omp parallel sections lastprivate(b) + { + #pragma omp section + nthreads = omp_get_num_threads (); + #pragma omp section + b.doit (); + } +} + +int main() +{ + omp_set_dynamic (0); + omp_set_num_threads (4); + foo(); + + assert (B::ccount == 1); + assert (B::icount == nthreads); + assert (B::dcount == nthreads+1); + + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/ctor-4.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/ctor-4.C new file mode 100644 index 000000000..e4f8f82db --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/ctor-4.C @@ -0,0 +1,90 @@ +// { dg-do run } + +#include <omp.h> +#include <assert.h> + +struct B +{ + static int ccount; + static int dcount; + static int ecount; + static B *e_inner; + static B *e_outer; + + B(); + B(int); + B(const B &); + ~B(); + B& operator=(const B &); + void doit(); +}; + +int B::ccount; +int B::dcount; +int B::ecount; +B * B::e_inner; +B * B::e_outer; + +B::B(int) +{ + e_outer = this; +} + +B::B(const B &b) +{ + assert (&b == e_outer); + #pragma omp atomic + ccount++; +} + +B::~B() +{ + #pragma omp atomic + dcount++; +} + +B& B::operator= (const B &b) +{ + assert (&b == e_inner); + assert (this == e_outer); + #pragma omp atomic + ecount++; + return *this; +} + +void B::doit() +{ + #pragma omp critical + { + assert (e_inner == 0); + e_inner = this; + } +} + +static int nthreads; + +void foo() +{ + B b(0); + + #pragma omp parallel sections firstprivate(b) lastprivate(b) + { + #pragma omp section + nthreads = omp_get_num_threads (); + #pragma omp section + b.doit (); + } +} + +int main() +{ + omp_set_dynamic (0); + omp_set_num_threads (4); + foo(); + + assert (B::ecount == 1); + assert (B::ccount == nthreads); + assert (B::dcount == nthreads+1); + + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/ctor-5.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/ctor-5.C new file mode 100644 index 000000000..d99a1d462 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/ctor-5.C @@ -0,0 +1,52 @@ +// { dg-do run } +// { dg-require-effective-target tls_runtime } + +#include <omp.h> +#include <assert.h> + +struct B +{ + static int count; + static B *expected; + + B& operator=(const B &); +}; + +int B::count; +B * B::expected; + +static B thr; +#pragma omp threadprivate(thr) + +B& B::operator= (const B &b) +{ + assert (&b == expected); + assert (this != expected); + #pragma omp atomic + count++; + return *this; +} + +static int nthreads; + +void foo() +{ + B::expected = &thr; + + #pragma omp parallel copyin(thr) + { + #pragma omp master + nthreads = omp_get_num_threads (); + } +} + +int main() +{ + omp_set_dynamic (0); + omp_set_num_threads (4); + foo(); + + assert (B::count == nthreads-1); + + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/ctor-6.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/ctor-6.C new file mode 100644 index 000000000..eab74e089 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/ctor-6.C @@ -0,0 +1,50 @@ +// { dg-do run } + +#include <omp.h> +#include <assert.h> + +struct B +{ + static int count; + static B *expected; + + B& operator=(const B &); +}; + +int B::count; +B * B::expected; + +B& B::operator= (const B &b) +{ + assert (&b == expected); + assert (this != expected); + #pragma omp atomic + count++; + return *this; +} + +static int nthreads; + +void foo() +{ + #pragma omp parallel + { + B b; + #pragma omp single copyprivate(b) + { + nthreads = omp_get_num_threads (); + B::expected = &b; + } + } +} + +int main() +{ + omp_set_dynamic (0); + omp_set_num_threads (4); + foo(); + + assert (B::count == nthreads-1); + + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/ctor-7.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/ctor-7.C new file mode 100644 index 000000000..3d669a707 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/ctor-7.C @@ -0,0 +1,67 @@ +// { dg-do run } + +#include <omp.h> +#include <assert.h> + +#define N 10 + +struct B +{ + static int icount; + static int dcount; + static int xcount; + + B(); + B(const B &); + ~B(); + B& operator=(const B &); + void doit(); +}; + +int B::icount; +int B::dcount; +int B::xcount; + +B::B() +{ + #pragma omp atomic + icount++; +} + +B::~B() +{ + #pragma omp atomic + dcount++; +} + +void B::doit() +{ + #pragma omp atomic + xcount++; +} + +static int nthreads; + +void foo() +{ + B b[N]; + #pragma omp parallel private(b) + { + #pragma omp master + nthreads = omp_get_num_threads (); + b[0].doit(); + } +} + +int main() +{ + omp_set_dynamic (0); + omp_set_num_threads (4); + foo(); + + assert (B::xcount == nthreads); + assert (B::icount == (nthreads+1)*N); + assert (B::dcount == (nthreads+1)*N); + + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/ctor-8.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/ctor-8.C new file mode 100644 index 000000000..5c0d81b73 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/ctor-8.C @@ -0,0 +1,77 @@ +// { dg-do run } +// { dg-require-effective-target tls_runtime } + +#include <omp.h> +#include <assert.h> + +#define N 10 +#define THR 4 + +struct B +{ + B(); + B(const B &); + ~B(); + B& operator=(const B &); + void doit(); +}; + +static B *base; +static B *threadbase; +static unsigned cmask[THR]; +static unsigned dmask[THR]; + +#pragma omp threadprivate(threadbase) + +B::B() +{ + assert (base == 0); +} + +B::B(const B &b) +{ + unsigned index = &b - base; + assert (index < N); + cmask[omp_get_thread_num()] |= 1u << index; +} + +B::~B() +{ + if (threadbase) + { + unsigned index = this - threadbase; + assert (index < N); + dmask[omp_get_thread_num()] |= 1u << index; + } +} + +void foo() +{ + B b[N]; + + base = b; + + #pragma omp parallel firstprivate(b) + { + assert (omp_get_num_threads () == THR); + threadbase = b; + } + + threadbase = 0; +} + +int main() +{ + omp_set_dynamic (0); + omp_set_num_threads (THR); + foo(); + + for (int i = 0; i < THR; ++i) + { + unsigned xmask = (1u << N) - 1; + assert (cmask[i] == xmask); + assert (dmask[i] == xmask); + } + + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/ctor-9.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/ctor-9.C new file mode 100644 index 000000000..215a901f8 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/ctor-9.C @@ -0,0 +1,60 @@ +// { dg-do run } +// { dg-require-effective-target tls_runtime } + +#include <omp.h> +#include <assert.h> + +#define N 10 +#define THR 4 + +struct B +{ + B& operator=(const B &); +}; + +static B *base; +static B *threadbase; +static int singlethread; +#pragma omp threadprivate(threadbase) + +static unsigned cmask[THR]; + +B& B::operator= (const B &b) +{ + unsigned sindex = &b - base; + unsigned tindex = this - threadbase; + assert(sindex < N); + assert(sindex == tindex); + cmask[omp_get_thread_num ()] |= 1u << tindex; + return *this; +} + +void foo() +{ + #pragma omp parallel + { + B b[N]; + threadbase = b; + #pragma omp single copyprivate(b) + { + assert(omp_get_num_threads () == THR); + singlethread = omp_get_thread_num (); + base = b; + } + } +} + +int main() +{ + omp_set_dynamic (0); + omp_set_num_threads (THR); + foo(); + + for (int i = 0; i < THR; ++i) + if (i == singlethread) + assert(cmask[singlethread] == 0); + else + assert(cmask[i] == (1u << N) - 1); + + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/for-1.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/for-1.C new file mode 100644 index 000000000..1c713464e --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/for-1.C @@ -0,0 +1,291 @@ +// { dg-do run } + +typedef __PTRDIFF_TYPE__ ptrdiff_t; +extern "C" void abort (); + +template <typename T> +class I +{ +public: + typedef ptrdiff_t difference_type; + I (); + ~I (); + I (T *); + I (const I &); + T &operator * (); + T *operator -> (); + T &operator [] (const difference_type &) const; + I &operator = (const I &); + I &operator ++ (); + I operator ++ (int); + I &operator -- (); + I operator -- (int); + I &operator += (const difference_type &); + I &operator -= (const difference_type &); + I operator + (const difference_type &) const; + I operator - (const difference_type &) const; + template <typename S> friend bool operator == (I<S> &, I<S> &); + template <typename S> friend bool operator == (const I<S> &, const I<S> &); + template <typename S> friend bool operator < (I<S> &, I<S> &); + template <typename S> friend bool operator < (const I<S> &, const I<S> &); + template <typename S> friend bool operator <= (I<S> &, I<S> &); + template <typename S> friend bool operator <= (const I<S> &, const I<S> &); + template <typename S> friend bool operator > (I<S> &, I<S> &); + template <typename S> friend bool operator > (const I<S> &, const I<S> &); + template <typename S> friend bool operator >= (I<S> &, I<S> &); + template <typename S> friend bool operator >= (const I<S> &, const I<S> &); + template <typename S> friend typename I<S>::difference_type operator - (I<S> &, I<S> &); + template <typename S> friend typename I<S>::difference_type operator - (const I<S> &, const I<S> &); + template <typename S> friend I<S> operator + (typename I<S>::difference_type , const I<S> &); +private: + T *p; +}; +template <typename T> I<T>::I () : p (0) {} +template <typename T> I<T>::~I () {} +template <typename T> I<T>::I (T *x) : p (x) {} +template <typename T> I<T>::I (const I &x) : p (x.p) {} +template <typename T> T &I<T>::operator * () { return *p; } +template <typename T> T *I<T>::operator -> () { return p; } +template <typename T> T &I<T>::operator [] (const difference_type &x) const { return p[x]; } +template <typename T> I<T> &I<T>::operator = (const I &x) { p = x.p; return *this; } +template <typename T> I<T> &I<T>::operator ++ () { ++p; return *this; } +template <typename T> I<T> I<T>::operator ++ (int) { return I (p++); } +template <typename T> I<T> &I<T>::operator -- () { --p; return *this; } +template <typename T> I<T> I<T>::operator -- (int) { return I (p--); } +template <typename T> I<T> &I<T>::operator += (const difference_type &x) { p += x; return *this; } +template <typename T> I<T> &I<T>::operator -= (const difference_type &x) { p -= x; return *this; } +template <typename T> I<T> I<T>::operator + (const difference_type &x) const { return I (p + x); } +template <typename T> I<T> I<T>::operator - (const difference_type &x) const { return I (p - x); } +template <typename T> bool operator == (I<T> &x, I<T> &y) { return x.p == y.p; } +template <typename T> bool operator == (const I<T> &x, const I<T> &y) { return x.p == y.p; } +template <typename T> bool operator != (I<T> &x, I<T> &y) { return !(x == y); } +template <typename T> bool operator != (const I<T> &x, const I<T> &y) { return !(x == y); } +template <typename T> bool operator < (I<T> &x, I<T> &y) { return x.p < y.p; } +template <typename T> bool operator < (const I<T> &x, const I<T> &y) { return x.p < y.p; } +template <typename T> bool operator <= (I<T> &x, I<T> &y) { return x.p <= y.p; } +template <typename T> bool operator <= (const I<T> &x, const I<T> &y) { return x.p <= y.p; } +template <typename T> bool operator > (I<T> &x, I<T> &y) { return x.p > y.p; } +template <typename T> bool operator > (const I<T> &x, const I<T> &y) { return x.p > y.p; } +template <typename T> bool operator >= (I<T> &x, I<T> &y) { return x.p >= y.p; } +template <typename T> bool operator >= (const I<T> &x, const I<T> &y) { return x.p >= y.p; } +template <typename T> typename I<T>::difference_type operator - (I<T> &x, I<T> &y) { return x.p - y.p; } +template <typename T> typename I<T>::difference_type operator - (const I<T> &x, const I<T> &y) { return x.p - y.p; } +template <typename T> I<T> operator + (typename I<T>::difference_type x, const I<T> &y) { return I<T> (x + y.p); } + +template <typename T> +class J +{ +public: + J(const I<T> &x, const I<T> &y) : b (x), e (y) {} + const I<T> &begin (); + const I<T> &end (); +private: + I<T> b, e; +}; + +template <typename T> const I<T> &J<T>::begin () { return b; } +template <typename T> const I<T> &J<T>::end () { return e; } + +int results[2000]; + +template <typename T> +void +baz (I<T> &i) +{ + if (*i < 0 || *i >= 2000) + abort (); + results[*i]++; +} + +void +f1 (const I<int> &x, const I<int> &y) +{ +#pragma omp parallel for + for (I<int> i = x; i <= y; i += 6) + baz (i); +} + +void +f2 (const I<int> &x, const I<int> &y) +{ + I<int> i; +#pragma omp parallel for private(i) + for (i = x; i < y - 1; i = 1 - 6 + 7 + i) + baz (i); +} + +template <typename T> +void +f3 (const I<int> &x, const I<int> &y) +{ +#pragma omp parallel for + for (I<int> i = x; i <= y; i = i + 9 - 8) + baz (i); +} + +template <typename T> +void +f4 (const I<int> &x, const I<int> &y) +{ + I<int> i; +#pragma omp parallel for lastprivate(i) + for (i = x + 2000 - 64; i > y + 10; --i) + baz (i); +} + +void +f5 (const I<int> &x, const I<int> &y) +{ +#pragma omp parallel for + for (I<int> i = x + 2000 - 64; i > y + 10; i -= 10) + baz (i); +} + +template <int N> +void +f6 (const I<int> &x, const I<int> &y) +{ +#pragma omp parallel for + for (I<int> i = x + 2000 - 64; i > y + 10; i = i - 12 + 2) + { + I<int> j = i + N; + baz (j); + } +} + +template <int N> +void +f7 (I<int> i, const I<int> &x, const I<int> &y) +{ +#pragma omp parallel for + for (i = x - 10; i <= y + 10; i += N) + baz (i); +} + +template <int N> +void +f8 (J<int> j) +{ + I<int> i; +#pragma omp parallel for + for (i = j.begin (); i <= j.end () + N; i += 2) + baz (i); +} + +template <typename T, int N> +void +f9 (const I<T> &x, const I<T> &y) +{ +#pragma omp parallel for + for (I<T> i = x; i <= y; i = i + N) + baz (i); +} + +template <typename T, int N> +void +f10 (const I<T> &x, const I<T> &y) +{ + I<T> i; +#pragma omp parallel for + for (i = x; i > y; i = i + N) + baz (i); +} + +template <typename T> +void +f11 (const T &x, const T &y) +{ +#pragma omp parallel + { +#pragma omp for nowait + for (T i = x; i <= y; i += 3) + baz (i); +#pragma omp single + { + T j = y + 3; + baz (j); + } + } +} + +template <typename T> +void +f12 (const T &x, const T &y) +{ + T i; +#pragma omp parallel for + for (i = x; i > y; --i) + baz (i); +} + +template <int N> +struct K +{ + template <typename T> + static void + f13 (const T &x, const T &y) + { +#pragma omp parallel for + for (T i = x; i <= y + N; i += N) + baz (i); + } +}; + +#define check(expr) \ + for (int i = 0; i < 2000; i++) \ + if (expr) \ + { \ + if (results[i] != 1) \ + abort (); \ + results[i] = 0; \ + } \ + else if (results[i]) \ + abort () + +int +main () +{ + int a[2000]; + long b[2000]; + for (int i = 0; i < 2000; i++) + { + a[i] = i; + b[i] = i; + } + f1 (&a[10], &a[1990]); + check (i >= 10 && i <= 1990 && (i - 10) % 6 == 0); + f2 (&a[0], &a[1999]); + check (i < 1998 && (i & 1) == 0); + f3<char> (&a[20], &a[1837]); + check (i >= 20 && i <= 1837); + f4<int> (&a[0], &a[30]); + check (i > 40 && i <= 2000 - 64); + f5 (&a[0], &a[100]); + check (i >= 116 && i <= 2000 - 64 && (i - 116) % 10 == 0); + f6<-10> (&a[10], &a[110]); + check (i >= 116 && i <= 2000 - 64 && (i - 116) % 10 == 0); + f7<6> (I<int> (), &a[12], &a[1800]); + check (i >= 2 && i <= 1808 && (i - 2) % 6 == 0); + f8<121> (J<int> (&a[14], &a[1803])); + check (i >= 14 && i <= 1924 && (i & 1) == 0); + f9<int, 7> (&a[33], &a[1967]); + check (i >= 33 && i <= 1967 && (i - 33) % 7 == 0); + f10<int, -7> (&a[1939], &a[17]); + check (i >= 21 && i <= 1939 && (i - 21) % 7 == 0); + f11<I<int> > (&a[16], &a[1981]); + check (i >= 16 && i <= 1984 && (i - 16) % 3 == 0); + f12<I<int> > (&a[1761], &a[37]); + check (i > 37 && i <= 1761); + K<5>::f13<I<int> > (&a[1], &a[1935]); + check (i >= 1 && i <= 1936 && (i - 1) % 5 == 0); + f9<long, 7> (&b[33], &b[1967]); + check (i >= 33 && i <= 1967 && (i - 33) % 7 == 0); + f10<long, -7> (&b[1939], &b[17]); + check (i >= 21 && i <= 1939 && (i - 21) % 7 == 0); + f11<I<long> > (&b[16], &b[1981]); + check (i >= 16 && i <= 1984 && (i - 16) % 3 == 0); + f12<I<long> > (&b[1761], &b[37]); + check (i > 37 && i <= 1761); + K<5>::f13<I<long> > (&b[1], &b[1935]); + check (i >= 1 && i <= 1936 && (i - 1) % 5 == 0); +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/for-10.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/for-10.C new file mode 100644 index 000000000..fb1a3e952 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/for-10.C @@ -0,0 +1,44 @@ +extern "C" void abort (); + +#define M(x, y, z) O(x, y, z) +#define O(x, y, z) x ## _ ## y ## _ ## z + +#define F simd +#define G simd +#define S +#define N(x) M(x, G, normal) +#include "../libgomp.c/for-2.h" +#undef S +#undef N +#undef F +#undef G + +#define F parallel for simd +#define G pf_simd +#include "../libgomp.c/for-1.h" +#undef F +#undef G + +#define F for simd +#define G f_simd +#include "../libgomp.c/for-1.h" +#undef F +#undef G + +int +main () +{ + if (test_simd_normal () + || test_pf_simd_static () + || test_pf_simd_static32 () + || test_pf_simd_auto () + || test_pf_simd_guided32 () + || test_pf_simd_runtime () + || test_f_simd_static () + || test_f_simd_static32 () + || test_f_simd_auto () + || test_f_simd_guided32 () + || test_f_simd_runtime ()) + abort (); + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/for-11.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/for-11.C new file mode 100644 index 000000000..0244e4de1 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/for-11.C @@ -0,0 +1,108 @@ +extern "C" void abort (); + +#define M(x, y, z) O(x, y, z) +#define O(x, y, z) x ## _ ## y ## _ ## z + +#pragma omp declare target + +#define F distribute +#define G d +#define S +#define N(x) M(x, G, normal) +#include "../libgomp.c/for-2.h" +#undef S +#undef N +#undef F +#undef G + +#define F distribute +#define G d_ds128 +#define S dist_schedule(static, 128) +#define N(x) M(x, G, normal) +#include "../libgomp.c/for-2.h" +#undef S +#undef N +#undef F +#undef G + +#define F distribute simd +#define G ds +#define S +#define N(x) M(x, G, normal) +#include "../libgomp.c/for-2.h" +#undef S +#undef N +#undef F +#undef G + +#define F distribute simd +#define G ds_ds128 +#define S dist_schedule(static, 128) +#define N(x) M(x, G, normal) +#include "../libgomp.c/for-2.h" +#undef S +#undef N +#undef F +#undef G + +#define F distribute parallel for +#define G dpf +#include "../libgomp.c/for-1.h" +#undef F +#undef G + +#define F distribute parallel for dist_schedule(static, 128) +#define G dpf_ds128 +#include "../libgomp.c/for-1.h" +#undef F +#undef G + +#define F distribute parallel for simd +#define G dpfs +#include "../libgomp.c/for-1.h" +#undef F +#undef G + +#define F distribute parallel for simd dist_schedule(static, 128) +#define G dpfs_ds128 +#include "../libgomp.c/for-1.h" +#undef F +#undef G + +#pragma omp end declare target + +int +main () +{ + int err = 0; + #pragma omp target teams reduction(|:err) + { + err |= test_d_normal (); + err |= test_d_ds128_normal (); + err |= test_ds_normal (); + err |= test_ds_ds128_normal (); + err |= test_dpf_static (); + err |= test_dpf_static32 (); + err |= test_dpf_auto (); + err |= test_dpf_guided32 (); + err |= test_dpf_runtime (); + err |= test_dpf_ds128_static (); + err |= test_dpf_ds128_static32 (); + err |= test_dpf_ds128_auto (); + err |= test_dpf_ds128_guided32 (); + err |= test_dpf_ds128_runtime (); + err |= test_dpfs_static (); + err |= test_dpfs_static32 (); + err |= test_dpfs_auto (); + err |= test_dpfs_guided32 (); + err |= test_dpfs_runtime (); + err |= test_dpfs_ds128_static (); + err |= test_dpfs_ds128_static32 (); + err |= test_dpfs_ds128_auto (); + err |= test_dpfs_ds128_guided32 (); + err |= test_dpfs_ds128_runtime (); + } + if (err) + abort (); + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/for-2.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/for-2.C new file mode 100644 index 000000000..98ffa1ae6 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/for-2.C @@ -0,0 +1,182 @@ +// { dg-do run } + +extern "C" void abort (); + +template <typename T> +class J +{ +public: + J(T x, T y) : b (x), e (y) {} + T begin (); + T end (); +private: + T b, e; +}; + +template <typename T> T J<T>::begin () { return b; } +template <typename T> T J<T>::end () { return e; } + +int results[2000]; + +void +baz (int i) +{ + if (i < 0 || i >= 2000) + abort (); + results[i]++; +} + +void +f1 (int x, int y) +{ +#pragma omp parallel for + for (int i = x; i <= y; i += 6) + baz (i); +} + +void +f2 (int x, int y) +{ + int i; +#pragma omp parallel for private(i) + for (i = x; i < y - 1; i = 1 - 6 + 7 + i) + baz (i); +} + +template <typename T> +void +f3 (int x, int y) +{ +#pragma omp parallel for + for (int i = x; i <= y; i = i + 9 - 8) + baz (i); +} + +template <typename T> +void +f4 (int x, int y) +{ + int i; +#pragma omp parallel for lastprivate(i) + for (i = x + 2000 - 64; i > y + 10; --i) + baz (i); +} + +void +f5 (int x, int y) +{ +#pragma omp parallel for + for (int i = x + 2000 - 64; i > y + 10L; i -= 10L) + baz (i); +} + +template <int N> +void +f6 (int x, int y) +{ +#pragma omp parallel for + for (int i = x + 2000 - 64; i > y + 10L; i = i - 12 + 2L) + baz (i + N); +} + +template <long N> +void +f7 (int i, int x, int y) +{ +#pragma omp parallel for + for (i = x - 10; i <= y + 10; i += N) + baz (i); +} + +template <long N> +void +f8 (J<int> j) +{ + int i; +#pragma omp parallel for + for (i = j.begin (); i <= j.end () + N; i += 2) + baz (i); +} + +template <typename T, long N> +void +f9 (T x, T y) +{ +#pragma omp parallel for + for (T i = x; i <= y; i = i + N) + baz (i); +} + +template <typename T, long N> +void +f10 (T x, T y) +{ + T i; +#pragma omp parallel for + for (i = x; i > y; i = i + N) + baz (i); +} + +template <typename T> +void +f11 (T x, long y) +{ +#pragma omp parallel + { +#pragma omp for nowait + for (T i = x; i <= y; i += 3L) + baz (i); +#pragma omp single + baz (y + 3); + } +} + +template <typename T> +void +f12 (T x, T y) +{ + T i; +#pragma omp parallel for + for (i = x; i > y; --i) + baz (i); +} + +#define check(expr) \ + for (int i = 0; i < 2000; i++) \ + if (expr) \ + { \ + if (results[i] != 1) \ + abort (); \ + results[i] = 0; \ + } \ + else if (results[i]) \ + abort () + +int +main () +{ + f1 (10, 1990); + check (i >= 10 && i <= 1990 && (i - 10) % 6 == 0); + f2 (0, 1999); + check (i < 1998 && (i & 1) == 0); + f3<char> (20, 1837); + check (i >= 20 && i <= 1837); + f4<int> (0, 30); + check (i > 40 && i <= 2000 - 64); + f5 (0, 100); + check (i >= 116 && i <= 2000 - 64 && (i - 116) % 10 == 0); + f6<-10> (10, 110); + check (i >= 116 && i <= 2000 - 64 && (i - 116) % 10 == 0); + f7<6> (0, 12, 1800); + check (i >= 2 && i <= 1808 && (i - 2) % 6 == 0); + f8<121> (J<int> (14, 1803)); + check (i >= 14 && i <= 1924 && (i & 1) == 0); + f9<int, 7> (33, 1967); + check (i >= 33 && i <= 1967 && (i - 33) % 7 == 0); + f10<int, -7> (1939, 17); + check (i >= 21 && i <= 1939 && (i - 21) % 7 == 0); + f11<int> (16, 1981); + check (i >= 16 && i <= 1984 && (i - 16) % 3 == 0); + f12<int> (1761, 37); + check (i > 37 && i <= 1761); +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/for-3.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/for-3.C new file mode 100644 index 000000000..235f83875 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/for-3.C @@ -0,0 +1,239 @@ +// { dg-do run } + +#include <vector> +#include <cstdlib> + +template <typename T> +class J +{ +public: + typedef typename std::vector<T>::const_iterator const_iterator; + J(const const_iterator &x, const const_iterator &y) : b (x), e (y) {} + const const_iterator &begin (); + const const_iterator &end (); +private: + const_iterator b, e; +}; + +template <typename T> +const typename std::vector<T>::const_iterator &J<T>::begin () { return b; } +template <typename T> +const typename std::vector<T>::const_iterator &J<T>::end () { return e; } + +int results[2000]; + +template <typename T> +void +baz (T &i) +{ + if (*i < 0 || *i >= 2000) + std::abort (); + results[*i]++; +} + +void +f1 (const std::vector<int>::const_iterator &x, + const std::vector<int>::const_iterator &y) +{ +#pragma omp parallel for + for (std::vector<int>::const_iterator i = x; i <= y; i += 6) + baz (i); +} + +void +f2 (const std::vector<int>::const_iterator &x, + const std::vector<int>::const_iterator &y) +{ + std::vector<int>::const_iterator i; +#pragma omp parallel for private(i) + for (i = x; i < y - 1; i = 1 - 6 + 7 + i) + baz (i); +} + +template <typename T> +void +f3 (const std::vector<int>::const_iterator &x, + const std::vector<int>::const_iterator &y) +{ +#pragma omp parallel for schedule (dynamic, 6) + for (std::vector<int>::const_iterator i = x; i <= y; i = i + 9 - 8) + baz (i); +} + +template <typename T> +void +f4 (const std::vector<int>::const_iterator &x, + const std::vector<int>::const_iterator &y) +{ + std::vector<int>::const_iterator i; +#pragma omp parallel for lastprivate(i) + for (i = x + 2000 - 64; i > y + 10; --i) + baz (i); +} + +void +f5 (const std::vector<int>::const_iterator &x, + const std::vector<int>::const_iterator &y) +{ +#pragma omp parallel for schedule (static, 10) + for (std::vector<int>::const_iterator i = x + 2000 - 64; i > y + 10; i -= 10) + baz (i); +} + +template <int N> +void +f6 (const std::vector<int>::const_iterator &x, + const std::vector<int>::const_iterator &y) +{ +#pragma omp parallel for schedule (runtime) + for (std::vector<int>::const_iterator i = x + 2000 - 64; + i > y + 10; i = i - 12 + 2) + { + std::vector<int>::const_iterator j = i + N; + baz (j); + } +} + +template <int N> +void +f7 (std::vector<int>::const_iterator i, + const std::vector<int>::const_iterator &x, + const std::vector<int>::const_iterator &y) +{ +#pragma omp parallel for schedule (dynamic, 6) + for (i = x - 10; i <= y + 10; i += N) + baz (i); +} + +template <int N> +void +f8 (J<int> j) +{ + std::vector<int>::const_iterator i; +#pragma omp parallel for schedule (dynamic, 40) + for (i = j.begin (); i <= j.end () + N; i += 2) + baz (i); +} + +template <typename T, int N> +void +f9 (const typename std::vector<T>::const_iterator &x, + const typename std::vector<T>::const_iterator &y) +{ +#pragma omp parallel for schedule (static, 25) + for (typename std::vector<T>::const_iterator i = x; i <= y; i = i + N) + baz (i); +} + +template <typename T, int N> +void +f10 (const typename std::vector<T>::const_iterator &x, + const typename std::vector<T>::const_iterator &y) +{ + typename std::vector<T>::const_iterator i; +#pragma omp parallel for + for (i = x; i > y; i = i + N) + baz (i); +} + +template <typename T> +void +f11 (const T &x, const T &y) +{ +#pragma omp parallel + { +#pragma omp for nowait schedule (static, 2) + for (T i = x; i <= y; i += 3) + baz (i); +#pragma omp single + { + T j = y + 3; + baz (j); + } + } +} + +template <typename T> +void +f12 (const T &x, const T &y) +{ + T i; +#pragma omp parallel for schedule (dynamic, 130) + for (i = x; i > y; --i) + baz (i); +} + +template <int N> +struct K +{ + template <typename T> + static void + f13 (const T &x, const T &y) + { +#pragma omp parallel for schedule (runtime) + for (T i = x; i <= y + N; i += N) + baz (i); + } +}; + +#define check(expr) \ + for (int i = 0; i < 2000; i++) \ + if (expr) \ + { \ + if (results[i] != 1) \ + std::abort (); \ + results[i] = 0; \ + } \ + else if (results[i]) \ + std::abort () + +int +main () +{ + std::vector<int> a(2000); + std::vector<long> b(2000); + for (int i = 0; i < 2000; i++) + { + a[i] = i; + b[i] = i; + } + f1 (a.begin () + 10, a.begin () + 1990); + check (i >= 10 && i <= 1990 && (i - 10) % 6 == 0); + f2 (a.begin () + 0, a.begin () + 1999); + check (i < 1998 && (i & 1) == 0); + f3<char> (a.begin () + 20, a.begin () + 1837); + check (i >= 20 && i <= 1837); + f4<int> (a.begin () + 0, a.begin () + 30); + check (i > 40 && i <= 2000 - 64); + f5 (a.begin () + 0, a.begin () + 100); + check (i >= 116 && i <= 2000 - 64 && (i - 116) % 10 == 0); + f6<-10> (a.begin () + 10, a.begin () + 110); + check (i >= 116 && i <= 2000 - 64 && (i - 116) % 10 == 0); + f7<6> (std::vector<int>::const_iterator (), a.begin () + 12, + a.begin () + 1800); + check (i >= 2 && i <= 1808 && (i - 2) % 6 == 0); + f8<121> (J<int> (a.begin () + 14, a.begin () + 1803)); + check (i >= 14 && i <= 1924 && (i & 1) == 0); + f9<int, 7> (a.begin () + 33, a.begin () + 1967); + check (i >= 33 && i <= 1967 && (i - 33) % 7 == 0); + f10<int, -7> (a.begin () + 1939, a.begin () + 17); + check (i >= 21 && i <= 1939 && (i - 21) % 7 == 0); + f11<std::vector<int>::const_iterator > (a.begin () + 16, a.begin () + 1981); + check (i >= 16 && i <= 1984 && (i - 16) % 3 == 0); + f12<std::vector<int>::const_iterator > (a.begin () + 1761, a.begin () + 37); + check (i > 37 && i <= 1761); + K<5>::f13<std::vector<int>::const_iterator > (a.begin () + 1, + a.begin () + 1935); + check (i >= 1 && i <= 1936 && (i - 1) % 5 == 0); + f9<long, 7> (b.begin () + 33, b.begin () + 1967); + check (i >= 33 && i <= 1967 && (i - 33) % 7 == 0); + f10<long, -7> (b.begin () + 1939, b.begin () + 17); + check (i >= 21 && i <= 1939 && (i - 21) % 7 == 0); + f11<std::vector<long>::const_iterator > (b.begin () + 16, b.begin () + 1981); + check (i >= 16 && i <= 1984 && (i - 16) % 3 == 0); + f12<std::vector<long>::const_iterator > (b.begin () + 1761, b.begin () + 37); + check (i > 37 && i <= 1761); + K<5>::f13<std::vector<long>::const_iterator > (b.begin () + 1, + b.begin () + 1935); + check (i >= 1 && i <= 1936 && (i - 1) % 5 == 0); +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/for-4.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/for-4.C new file mode 100644 index 000000000..c528ef9d1 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/for-4.C @@ -0,0 +1,225 @@ +// { dg-do run } + +#include <string> +#include <cstdlib> + +template <typename T> +class J +{ +public: + typedef typename std::basic_string<T>::iterator iterator; + J(const iterator &x, const iterator &y) : b (x), e (y) {} + const iterator &begin (); + const iterator &end (); +private: + iterator b, e; +}; + +template <typename T> +const typename std::basic_string<T>::iterator &J<T>::begin () { return b; } +template <typename T> +const typename std::basic_string<T>::iterator &J<T>::end () { return e; } + +template <typename T> +void +baz (T &i) +{ + if (*i < L'a' || *i >= L'a' + 2000) + std::abort (); + (*i)++; +} + +void +f1 (const std::basic_string<wchar_t>::iterator &x, + const std::basic_string<wchar_t>::iterator &y) +{ +#pragma omp parallel for + for (std::basic_string<wchar_t>::iterator i = x; i <= y; i += 6) + baz (i); +} + +void +f2 (const std::basic_string<wchar_t>::iterator &x, + const std::basic_string<wchar_t>::iterator &y) +{ + std::basic_string<wchar_t>::iterator i; +#pragma omp parallel for private(i) + for (i = x; i < y - 1; i = 1 - 6 + 7 + i) + baz (i); +} + +template <typename T> +void +f3 (const std::basic_string<wchar_t>::iterator &x, + const std::basic_string<wchar_t>::iterator &y) +{ +#pragma omp parallel for schedule (dynamic, 6) + for (std::basic_string<wchar_t>::iterator i = x; i <= y; i = i + 9 - 8) + baz (i); +} + +template <typename T> +void +f4 (const std::basic_string<wchar_t>::iterator &x, + const std::basic_string<wchar_t>::iterator &y) +{ + std::basic_string<wchar_t>::iterator i; +#pragma omp parallel for lastprivate(i) + for (i = x + 2000 - 64; i > y + 10; --i) + baz (i); +} + +void +f5 (const std::basic_string<wchar_t>::iterator &x, + const std::basic_string<wchar_t>::iterator &y) +{ +#pragma omp parallel for schedule (static, 10) + for (std::basic_string<wchar_t>::iterator i = x + 2000 - 64; + i > y + 10; i -= 10) + baz (i); +} + +template <int N> +void +f6 (const std::basic_string<wchar_t>::iterator &x, + const std::basic_string<wchar_t>::iterator &y) +{ +#pragma omp parallel for schedule (runtime) + for (std::basic_string<wchar_t>::iterator i = x + 2000 - 64; + i > y + 10; i = i - 12 + 2) + { + std::basic_string<wchar_t>::iterator j = i + N; + baz (j); + } +} + +template <int N> +void +f7 (std::basic_string<wchar_t>::iterator i, + const std::basic_string<wchar_t>::iterator &x, + const std::basic_string<wchar_t>::iterator &y) +{ +#pragma omp parallel for schedule (dynamic, 6) + for (i = x - 10; i <= y + 10; i += N) + baz (i); +} + +template <wchar_t N> +void +f8 (J<wchar_t> j) +{ + std::basic_string<wchar_t>::iterator i; +#pragma omp parallel for schedule (dynamic, 40) + for (i = j.begin (); i <= j.end () + N; i += 2) + baz (i); +} + +template <typename T, int N> +void +f9 (const typename std::basic_string<T>::iterator &x, + const typename std::basic_string<T>::iterator &y) +{ +#pragma omp parallel for schedule (static, 25) + for (typename std::basic_string<T>::iterator i = x; i <= y; i = i + N) + baz (i); +} + +template <typename T, int N> +void +f10 (const typename std::basic_string<T>::iterator &x, + const typename std::basic_string<T>::iterator &y) +{ + typename std::basic_string<T>::iterator i; +#pragma omp parallel for + for (i = x; i > y; i = i + N) + baz (i); +} + +template <typename T> +void +f11 (const T &x, const T &y) +{ +#pragma omp parallel + { +#pragma omp for nowait schedule (static, 2) + for (T i = x; i <= y; i += 3) + baz (i); +#pragma omp single + { + T j = y + 3; + baz (j); + } + } +} + +template <typename T> +void +f12 (const T &x, const T &y) +{ + T i; +#pragma omp parallel for schedule (dynamic, 130) + for (i = x; i > y; --i) + baz (i); +} + +template <int N> +struct K +{ + template <typename T> + static void + f13 (const T &x, const T &y) + { +#pragma omp parallel for schedule (runtime) + for (T i = x; i <= y + N; i += N) + baz (i); + } +}; + +#define check(expr) \ + for (int i = 0; i < 2000; i++) \ + if (expr) \ + { \ + if (a[i] != L'a' + i + 1) \ + std::abort (); \ + a[i] = L'a' + i; \ + } \ + else if (a[i] != L'a' + i) \ + std::abort () + +int +main () +{ + std::basic_string<wchar_t> a = L""; + for (int i = 0; i < 2000; i++) + a += L'a' + i; + f1 (a.begin () + 10, a.begin () + 1990); + check (i >= 10 && i <= 1990 && (i - 10) % 6 == 0); + f2 (a.begin () + 0, a.begin () + 1999); + check (i < 1998 && (i & 1) == 0); + f3<char> (a.begin () + 20, a.begin () + 1837); + check (i >= 20 && i <= 1837); + f4<int> (a.begin () + 0, a.begin () + 30); + check (i > 40 && i <= 2000 - 64); + f5 (a.begin () + 0, a.begin () + 100); + check (i >= 116 && i <= 2000 - 64 && (i - 116) % 10 == 0); + f6<-10> (a.begin () + 10, a.begin () + 110); + check (i >= 116 && i <= 2000 - 64 && (i - 116) % 10 == 0); + f7<6> (std::basic_string<wchar_t>::iterator (), a.begin () + 12, + a.begin () + 1800); + check (i >= 2 && i <= 1808 && (i - 2) % 6 == 0); + f8<121> (J<wchar_t> (a.begin () + 14, a.begin () + 1803)); + check (i >= 14 && i <= 1924 && (i & 1) == 0); + f9<wchar_t, 7> (a.begin () + 33, a.begin () + 1967); + check (i >= 33 && i <= 1967 && (i - 33) % 7 == 0); + f10<wchar_t, -7> (a.begin () + 1939, a.begin () + 17); + check (i >= 21 && i <= 1939 && (i - 21) % 7 == 0); + f11<std::basic_string<wchar_t>::iterator > (a.begin () + 16, + a.begin () + 1981); + check (i >= 16 && i <= 1984 && (i - 16) % 3 == 0); + f12<std::basic_string<wchar_t>::iterator > (a.begin () + 1761, + a.begin () + 37); + check (i > 37 && i <= 1761); + K<5>::f13<std::basic_string<wchar_t>::iterator > (a.begin () + 1, + a.begin () + 1935); + check (i >= 1 && i <= 1936 && (i - 1) % 5 == 0); +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/for-5.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/for-5.C new file mode 100644 index 000000000..9b75bf379 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/for-5.C @@ -0,0 +1,303 @@ +// { dg-do run } + +typedef __PTRDIFF_TYPE__ ptrdiff_t; +extern "C" void abort (); + +template <typename T> +class I +{ +public: + typedef ptrdiff_t difference_type; + I (); + ~I (); + I (T *); + I (const I &); + T &operator * (); + T *operator -> (); + T &operator [] (const difference_type &) const; + I &operator = (const I &); + I &operator ++ (); + I operator ++ (int); + I &operator -- (); + I operator -- (int); + I &operator += (const difference_type &); + I &operator -= (const difference_type &); + I operator + (const difference_type &) const; + I operator - (const difference_type &) const; + template <typename S> friend bool operator == (I<S> &, I<S> &); + template <typename S> friend bool operator == (const I<S> &, const I<S> &); + template <typename S> friend bool operator < (I<S> &, I<S> &); + template <typename S> friend bool operator < (const I<S> &, const I<S> &); + template <typename S> friend bool operator <= (I<S> &, I<S> &); + template <typename S> friend bool operator <= (const I<S> &, const I<S> &); + template <typename S> friend bool operator > (I<S> &, I<S> &); + template <typename S> friend bool operator > (const I<S> &, const I<S> &); + template <typename S> friend bool operator >= (I<S> &, I<S> &); + template <typename S> friend bool operator >= (const I<S> &, const I<S> &); + template <typename S> friend typename I<S>::difference_type operator - (I<S> &, I<S> &); + template <typename S> friend typename I<S>::difference_type operator - (const I<S> &, const I<S> &); + template <typename S> friend I<S> operator + (typename I<S>::difference_type , const I<S> &); +private: + T *p; +}; +template <typename T> I<T>::I () : p (0) {} +template <typename T> I<T>::~I () { p = (T *) 0; } +template <typename T> I<T>::I (T *x) : p (x) {} +template <typename T> I<T>::I (const I &x) : p (x.p) {} +template <typename T> T &I<T>::operator * () { return *p; } +template <typename T> T *I<T>::operator -> () { return p; } +template <typename T> T &I<T>::operator [] (const difference_type &x) const { return p[x]; } +template <typename T> I<T> &I<T>::operator = (const I &x) { p = x.p; return *this; } +template <typename T> I<T> &I<T>::operator ++ () { ++p; return *this; } +template <typename T> I<T> I<T>::operator ++ (int) { return I (p++); } +template <typename T> I<T> &I<T>::operator -- () { --p; return *this; } +template <typename T> I<T> I<T>::operator -- (int) { return I (p--); } +template <typename T> I<T> &I<T>::operator += (const difference_type &x) { p += x; return *this; } +template <typename T> I<T> &I<T>::operator -= (const difference_type &x) { p -= x; return *this; } +template <typename T> I<T> I<T>::operator + (const difference_type &x) const { return I (p + x); } +template <typename T> I<T> I<T>::operator - (const difference_type &x) const { return I (p - x); } +template <typename T> bool operator == (I<T> &x, I<T> &y) { return x.p == y.p; } +template <typename T> bool operator == (const I<T> &x, const I<T> &y) { return x.p == y.p; } +template <typename T> bool operator != (I<T> &x, I<T> &y) { return !(x == y); } +template <typename T> bool operator != (const I<T> &x, const I<T> &y) { return !(x == y); } +template <typename T> bool operator < (I<T> &x, I<T> &y) { return x.p < y.p; } +template <typename T> bool operator < (const I<T> &x, const I<T> &y) { return x.p < y.p; } +template <typename T> bool operator <= (I<T> &x, I<T> &y) { return x.p <= y.p; } +template <typename T> bool operator <= (const I<T> &x, const I<T> &y) { return x.p <= y.p; } +template <typename T> bool operator > (I<T> &x, I<T> &y) { return x.p > y.p; } +template <typename T> bool operator > (const I<T> &x, const I<T> &y) { return x.p > y.p; } +template <typename T> bool operator >= (I<T> &x, I<T> &y) { return x.p >= y.p; } +template <typename T> bool operator >= (const I<T> &x, const I<T> &y) { return x.p >= y.p; } +template <typename T> typename I<T>::difference_type operator - (I<T> &x, I<T> &y) { return x.p - y.p; } +template <typename T> typename I<T>::difference_type operator - (const I<T> &x, const I<T> &y) { return x.p - y.p; } +template <typename T> I<T> operator + (typename I<T>::difference_type x, const I<T> &y) { return I<T> (x + y.p); } + +template <typename T> +class J +{ +public: + J(const I<T> &x, const I<T> &y) : b (x), e (y) {} + const I<T> &begin (); + const I<T> &end (); +private: + I<T> b, e; +}; + +template <typename T> const I<T> &J<T>::begin () { return b; } +template <typename T> const I<T> &J<T>::end () { return e; } + +int results[2000]; + +template <typename T> +void +baz (I<T> &i) +{ + if (*i < 0 || *i >= 2000) + abort (); + results[*i]++; +} + +I<int> +f1 (const I<int> &x, const I<int> &y) +{ + I<int> i; +#pragma omp parallel shared (i) + { + #pragma omp for lastprivate (i) schedule(runtime) + for (i = x; i < y - 1; ++i) + baz (i); + #pragma omp single + i += 3; + } + return I<int> (i); +} + +I<int> +f2 (const I<int> &x, const I<int> &y) +{ + I<int> i; +#pragma omp parallel for lastprivate (i) + for (i = x; i < y - 1; i = 1 - 6 + 7 + i) + baz (i); + return I<int> (i); +} + +template <typename T> +I<int> +f3 (const I<int> &x, const I<int> &y) +{ + I<int> i; +#pragma omp parallel + #pragma omp for lastprivate (i) + for (i = x + 1000 - 64; i <= y - 10; i++) + baz (i); + return i; +} + +template <typename T> +I<int> +f4 (const I<int> &x, const I<int> &y) +{ + I<int> i; +#pragma omp parallel for lastprivate (i) + for (i = x + 2000 - 64; i > y + 10; --i) + baz (i); + return I<int> (i); +} + +template <typename T> +I<int> +f5 (const I<int> &x, const I<int> &y) +{ + I<int> i; +#pragma omp parallel for lastprivate (i) + for (i = x; i > y + T (6); i--) + baz (i); + return i; +} + +template <typename T> +I<int> +f6 (const I<int> &x, const I<int> &y) +{ + I<int> i; +#pragma omp parallel for lastprivate (i) + for (i = x - T (7); i > y; i -= T (2)) + baz (i); + return I<int> (i); +} + +template <int N> +I<int> +f7 (I<int> i, const I<int> &x, const I<int> &y) +{ +#pragma omp parallel for lastprivate (i) + for (i = x - 10; i <= y + 10; i += N) + baz (i); + return I<int> (i); +} + +template <int N> +I<int> +f8 (J<int> j) +{ + I<int> i; +#pragma omp parallel shared (i) + #pragma omp for lastprivate (i) + for (i = j.begin (); i <= j.end () + N; i += 2) + baz (i); + return i; +} + +I<int> i9; + +template <long N> +I<int> & +f9 (J<int> j) +{ +#pragma omp parallel for lastprivate (i9) + for (i9 = j.begin () + N; i9 <= j.end () - N; i9 = i9 - N) + baz (i9); + return i9; +} + +template <typename T, int N> +I<T> +f10 (const I<T> &x, const I<T> &y) +{ + I<T> i; +#pragma omp parallel for lastprivate (i) + for (i = x; i > y; i = i + N) + baz (i); + return i; +} + +template <typename T, typename U> +T +f11 (T i, const T &x, const T &y) +{ +#pragma omp parallel + #pragma omp for lastprivate (i) + for (i = x + U (2); i <= y + U (1); i = U (2) + U (3) + i) + baz (i); + return T (i); +} + +template <typename T> +T +f12 (const T &x, const T &y) +{ + T i; +#pragma omp parallel for lastprivate (i) + for (i = x; i > y; --i) + baz (i); + return i; +} + +#define check(expr) \ + for (int i = 0; i < 2000; i++) \ + if (expr) \ + { \ + if (results[i] != 1) \ + abort (); \ + results[i] = 0; \ + } \ + else if (results[i]) \ + abort () + +int +main () +{ + int a[2000]; + long b[2000]; + for (int i = 0; i < 2000; i++) + { + a[i] = i; + b[i] = i; + } + if (*f1 (&a[10], &a[1873]) != 1875) + abort (); + check (i >= 10 && i < 1872); + if (*f2 (&a[0], &a[1998]) != 1998) + abort (); + check (i < 1997 && (i & 1) == 0); + if (*f3<int> (&a[10], &a[1971]) != 1962) + abort (); + check (i >= 946 && i <= 1961); + if (*f4<int> (&a[0], &a[30]) != 40) + abort (); + check (i > 40 && i <= 2000 - 64); + if (*f5<short> (&a[1931], &a[17]) != 23) + abort (); + check (i > 23 && i <= 1931); + if (*f6<long> (&a[1931], &a[17]) != 16) + abort (); + check (i > 17 && i <= 1924 && (i & 1) == 0); + if (*f7<6> (I<int> (), &a[12], &a[1800]) != 1814) + abort (); + check (i >= 2 && i <= 1808 && (i - 2) % 6 == 0); + if (*f8<121> (J<int> (&a[14], &a[1803])) != 1926) + abort (); + check (i >= 14 && i <= 1924 && (i & 1) == 0); + if (*f9<-3L> (J<int> (&a[27], &a[1761])) != 1767) + abort (); + check (i >= 24 && i <= 1764 && (i % 3) == 0); + if (*f10<int, -7> (&a[1939], &a[17]) != 14) + abort (); + check (i >= 21 && i <= 1939 && i % 7 == 0); + if (*f11<I<int>, short> (I<int> (), &a[71], &a[1941]) != 1943) + abort (); + check (i >= 73 && i <= 1938 && (i - 73) % 5 == 0); + if (*f12<I<int> > (&a[1761], &a[37]) != 37) + abort (); + check (i > 37 && i <= 1761); + if (*f10<long, -7> (&b[1939], &b[17]) != 14) + abort (); + check (i >= 21 && i <= 1939 && i % 7 == 0); + if (*f11<I<long>, short> (I<long> (), &b[71], &b[1941]) != 1943) + abort (); + check (i >= 73 && i <= 1938 && (i - 73) % 5 == 0); + if (*f12<I<long> > (&b[1761], &b[37]) != 37) + abort (); + check (i > 37 && i <= 1761); +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/for-6.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/for-6.C new file mode 100644 index 000000000..0da21ce2f --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/for-6.C @@ -0,0 +1,109 @@ +// PR c++/38348 +// { dg-do run } + +extern "C" void abort (); +int cnt; + +template <typename T> +void +f0 (T, int) +{ + abort (); +} + +template <> +void +f0<int> (int, int type) +{ + if (type != 0) + abort (); +#pragma omp atomic + cnt++; +} + +template <> +void +f0<const char *> (const char *, int type) +{ + if (type != 1) + abort (); +#pragma omp atomic + cnt++; +} + +template <typename T> +void +f1 () +{ +#pragma omp parallel for + for (int i = 0; i < 10; i++) + f0 (i, 0); +} + +template <typename T> +void +f2 () +{ +#pragma omp parallel for + for (T i = T (0); i < T (10); i += T (1)) + f0 (i, 0); +} + +void +f3 () +{ +#pragma omp parallel for + for (int i = 0; i < 10; i++) + f0 (i, 0); +} + +const char *p = "abcdefghij"; + +template <typename T> +void +f4 () +{ +#pragma omp parallel for + for (const char *i = p; i < p + 10; i += 1) + f0 (i, 1); +} + +template <typename T> +void +f5 () +{ +#pragma omp parallel for + for (T i = T (p); i < T (p + 10); i += 1) + f0 (i, 1); +} + +void +f6 () +{ +#pragma omp parallel for + for (const char *i = p; i < p + 10; i++) + f0 (i, 1); +} + +int +main () +{ + f1<int> (); + if (cnt != 10) + abort (); + f2<int> (); + if (cnt != 20) + abort (); + f3 (); + if (cnt != 30) + abort (); + f4<int> (); + if (cnt != 40) + abort (); + f5<const char *> (); + if (cnt != 50) + abort (); + f6 (); + if (cnt != 60) + abort (); +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/for-7.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/for-7.C new file mode 100644 index 000000000..9d626c028 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/for-7.C @@ -0,0 +1,110 @@ +// PR c++/ +// { dg-do run } +// { dg-options "-std=c++0x -fopenmp" } + +extern "C" void abort (); +int cnt; + +template <typename T> +void +f0 (T, int) +{ + abort (); +} + +template <> +void +f0<int> (int, int type) +{ + if (type != 0) + abort (); +#pragma omp atomic + cnt++; +} + +template <> +void +f0<const char *> (const char *, int type) +{ + if (type != 1) + abort (); +#pragma omp atomic + cnt++; +} + +template <typename T> +void +f1 () +{ +#pragma omp parallel for + for (auto i = 0; i < 10; i++) + f0 (i, 0); +} + +template <typename T> +void +f2 () +{ +#pragma omp parallel for + for (auto i = T (0); i < T (10); i += T (1)) + f0 (i, 0); +} + +void +f3 () +{ +#pragma omp parallel for + for (auto i = 0; i < 10; i++) + f0 (i, 0); +} + +const char *p = "abcdefghij"; + +template <typename T> +void +f4 () +{ +#pragma omp parallel for + for (auto i = p; i < p + 10; i++) + f0 (i, 1); +} + +template <typename T> +void +f5 () +{ +#pragma omp parallel for + for (auto i = T (p); i < T (p + 10); i++) + f0 (i, 1); +} + +void +f6 () +{ +#pragma omp parallel for + for (auto i = p; i < p + 10; i++) + f0 (i, 1); +} + +int +main () +{ + f1<int> (); + if (cnt != 10) + abort (); + f2<int> (); + if (cnt != 20) + abort (); + f3 (); + if (cnt != 30) + abort (); + f4<int> (); + if (cnt != 40) + abort (); + f5<const char *> (); + if (cnt != 50) + abort (); + f6 (); + if (cnt != 60) + abort (); +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/for-8.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/for-8.C new file mode 100644 index 000000000..918de7cc8 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/for-8.C @@ -0,0 +1,291 @@ +// { dg-do run } + +typedef __PTRDIFF_TYPE__ ptrdiff_t; +extern "C" void abort (); + +template <typename T> +class I +{ +public: + typedef ptrdiff_t difference_type; + I (); + ~I (); + I (T *); + I (const I &); + T &operator * (); + T *operator -> (); + T &operator [] (const difference_type &) const; + I &operator = (const I &); + I &operator ++ (); + I operator ++ (int); + I &operator -- (); + I operator -- (int); + I &operator += (const difference_type &); + I &operator -= (const difference_type &); + I operator + (const difference_type &) const; + I operator - (const difference_type &) const; + template <typename S> friend bool operator == (I<S> &, I<S> &); + template <typename S> friend bool operator == (const I<S> &, const I<S> &); + template <typename S> friend bool operator < (I<S> &, I<S> &); + template <typename S> friend bool operator < (const I<S> &, const I<S> &); + template <typename S> friend bool operator <= (I<S> &, I<S> &); + template <typename S> friend bool operator <= (const I<S> &, const I<S> &); + template <typename S> friend bool operator > (I<S> &, I<S> &); + template <typename S> friend bool operator > (const I<S> &, const I<S> &); + template <typename S> friend bool operator >= (I<S> &, I<S> &); + template <typename S> friend bool operator >= (const I<S> &, const I<S> &); + template <typename S> friend typename I<S>::difference_type operator - (I<S> &, I<S> &); + template <typename S> friend typename I<S>::difference_type operator - (const I<S> &, const I<S> &); + template <typename S> friend I<S> operator + (typename I<S>::difference_type , const I<S> &); +private: + T *p; +}; +template <typename T> I<T>::I () : p (0) {} +template <typename T> I<T>::~I () {} +template <typename T> I<T>::I (T *x) : p (x) {} +template <typename T> I<T>::I (const I &x) : p (x.p) {} +template <typename T> T &I<T>::operator * () { return *p; } +template <typename T> T *I<T>::operator -> () { return p; } +template <typename T> T &I<T>::operator [] (const difference_type &x) const { return p[x]; } +template <typename T> I<T> &I<T>::operator = (const I &x) { p = x.p; return *this; } +template <typename T> I<T> &I<T>::operator ++ () { ++p; return *this; } +template <typename T> I<T> I<T>::operator ++ (int) { return I (p++); } +template <typename T> I<T> &I<T>::operator -- () { --p; return *this; } +template <typename T> I<T> I<T>::operator -- (int) { return I (p--); } +template <typename T> I<T> &I<T>::operator += (const difference_type &x) { p += x; return *this; } +template <typename T> I<T> &I<T>::operator -= (const difference_type &x) { p -= x; return *this; } +template <typename T> I<T> I<T>::operator + (const difference_type &x) const { return I (p + x); } +template <typename T> I<T> I<T>::operator - (const difference_type &x) const { return I (p - x); } +template <typename T> bool operator == (I<T> &x, I<T> &y) { return x.p == y.p; } +template <typename T> bool operator == (const I<T> &x, const I<T> &y) { return x.p == y.p; } +template <typename T> bool operator != (I<T> &x, I<T> &y) { return !(x == y); } +template <typename T> bool operator != (const I<T> &x, const I<T> &y) { return !(x == y); } +template <typename T> bool operator < (I<T> &x, I<T> &y) { return x.p < y.p; } +template <typename T> bool operator < (const I<T> &x, const I<T> &y) { return x.p < y.p; } +template <typename T> bool operator <= (I<T> &x, I<T> &y) { return x.p <= y.p; } +template <typename T> bool operator <= (const I<T> &x, const I<T> &y) { return x.p <= y.p; } +template <typename T> bool operator > (I<T> &x, I<T> &y) { return x.p > y.p; } +template <typename T> bool operator > (const I<T> &x, const I<T> &y) { return x.p > y.p; } +template <typename T> bool operator >= (I<T> &x, I<T> &y) { return x.p >= y.p; } +template <typename T> bool operator >= (const I<T> &x, const I<T> &y) { return x.p >= y.p; } +template <typename T> typename I<T>::difference_type operator - (I<T> &x, I<T> &y) { return x.p - y.p; } +template <typename T> typename I<T>::difference_type operator - (const I<T> &x, const I<T> &y) { return x.p - y.p; } +template <typename T> I<T> operator + (typename I<T>::difference_type x, const I<T> &y) { return I<T> (x + y.p); } + +template <typename T> +class J +{ +public: + J(const I<T> &x, const I<T> &y) : b (x), e (y) {} + const I<T> &begin (); + const I<T> &end (); +private: + I<T> b, e; +}; + +template <typename T> const I<T> &J<T>::begin () { return b; } +template <typename T> const I<T> &J<T>::end () { return e; } + +int results[2000]; + +template <typename T> +void +baz (I<T> &i) +{ + if (*i < 0 || *i >= 2000) + abort (); + results[*i]++; +} + +void +f1 (const I<int> &x, const I<int> &y) +{ +#pragma omp parallel for + for (I<int> i = x; y >= i; i += 6) + baz (i); +} + +void +f2 (const I<int> &x, const I<int> &y) +{ + I<int> i; +#pragma omp parallel for private(i) + for (i = x; y - 1 > i; i = 1 - 6 + 7 + i) + baz (i); +} + +template <typename T> +void +f3 (const I<int> &x, const I<int> &y) +{ +#pragma omp parallel for + for (I<int> i = x; y >= i; i = i + 9 - 8) + baz (i); +} + +template <typename T> +void +f4 (const I<int> &x, const I<int> &y) +{ + I<int> i; +#pragma omp parallel for lastprivate(i) + for (i = x + 2000 - 64; y + 10 < i; --i) + baz (i); +} + +void +f5 (const I<int> &x, const I<int> &y) +{ +#pragma omp parallel for + for (I<int> i = x + 2000 - 64; y + 10 < i; i -= 10) + baz (i); +} + +template <int N> +void +f6 (const I<int> &x, const I<int> &y) +{ +#pragma omp parallel for + for (I<int> i = x + 2000 - 64; y + 10 < i; i = i - 12 + 2) + { + I<int> j = i + N; + baz (j); + } +} + +template <int N> +void +f7 (I<int> i, const I<int> &x, const I<int> &y) +{ +#pragma omp parallel for + for (i = x - 10; y + 10 >= i; i += N) + baz (i); +} + +template <int N> +void +f8 (J<int> j) +{ + I<int> i; +#pragma omp parallel for + for (i = j.begin (); j.end () + N >= i; i += 2) + baz (i); +} + +template <typename T, int N> +void +f9 (const I<T> &x, const I<T> &y) +{ +#pragma omp parallel for + for (I<T> i = x; y >= i; i = i + N) + baz (i); +} + +template <typename T, int N> +void +f10 (const I<T> &x, const I<T> &y) +{ + I<T> i; +#pragma omp parallel for + for (i = x; y < i; i = i + N) + baz (i); +} + +template <typename T> +void +f11 (const T &x, const T &y) +{ +#pragma omp parallel + { +#pragma omp for nowait + for (T i = x; y >= i; i += 3) + baz (i); +#pragma omp single + { + T j = y + 3; + baz (j); + } + } +} + +template <typename T> +void +f12 (const T &x, const T &y) +{ + T i; +#pragma omp parallel for + for (i = x; y < i; --i) + baz (i); +} + +template <int N> +struct K +{ + template <typename T> + static void + f13 (const T &x, const T &y) + { +#pragma omp parallel for + for (T i = x; y + N >= i; i += N) + baz (i); + } +}; + +#define check(expr) \ + for (int i = 0; i < 2000; i++) \ + if (expr) \ + { \ + if (results[i] != 1) \ + abort (); \ + results[i] = 0; \ + } \ + else if (results[i]) \ + abort () + +int +main () +{ + int a[2000]; + long b[2000]; + for (int i = 0; i < 2000; i++) + { + a[i] = i; + b[i] = i; + } + f1 (&a[10], &a[1990]); + check (i >= 10 && i <= 1990 && (i - 10) % 6 == 0); + f2 (&a[0], &a[1999]); + check (i < 1998 && (i & 1) == 0); + f3<char> (&a[20], &a[1837]); + check (i >= 20 && i <= 1837); + f4<int> (&a[0], &a[30]); + check (i > 40 && i <= 2000 - 64); + f5 (&a[0], &a[100]); + check (i >= 116 && i <= 2000 - 64 && (i - 116) % 10 == 0); + f6<-10> (&a[10], &a[110]); + check (i >= 116 && i <= 2000 - 64 && (i - 116) % 10 == 0); + f7<6> (I<int> (), &a[12], &a[1800]); + check (i >= 2 && i <= 1808 && (i - 2) % 6 == 0); + f8<121> (J<int> (&a[14], &a[1803])); + check (i >= 14 && i <= 1924 && (i & 1) == 0); + f9<int, 7> (&a[33], &a[1967]); + check (i >= 33 && i <= 1967 && (i - 33) % 7 == 0); + f10<int, -7> (&a[1939], &a[17]); + check (i >= 21 && i <= 1939 && (i - 21) % 7 == 0); + f11<I<int> > (&a[16], &a[1981]); + check (i >= 16 && i <= 1984 && (i - 16) % 3 == 0); + f12<I<int> > (&a[1761], &a[37]); + check (i > 37 && i <= 1761); + K<5>::f13<I<int> > (&a[1], &a[1935]); + check (i >= 1 && i <= 1936 && (i - 1) % 5 == 0); + f9<long, 7> (&b[33], &b[1967]); + check (i >= 33 && i <= 1967 && (i - 33) % 7 == 0); + f10<long, -7> (&b[1939], &b[17]); + check (i >= 21 && i <= 1939 && (i - 21) % 7 == 0); + f11<I<long> > (&b[16], &b[1981]); + check (i >= 16 && i <= 1984 && (i - 16) % 3 == 0); + f12<I<long> > (&b[1761], &b[37]); + check (i > 37 && i <= 1761); + K<5>::f13<I<long> > (&b[1], &b[1935]); + check (i >= 1 && i <= 1936 && (i - 1) % 5 == 0); +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/for-9.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/for-9.C new file mode 100644 index 000000000..86b9d9318 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/for-9.C @@ -0,0 +1,33 @@ +extern "C" void abort (); + +#define M(x, y, z) O(x, y, z) +#define O(x, y, z) x ## _ ## y ## _ ## z + +#define F parallel for +#define G pf +#include "../libgomp.c/for-1.h" +#undef F +#undef G + +#define F for +#define G f +#include "../libgomp.c/for-1.h" +#undef F +#undef G + +int +main () +{ + if (test_pf_static () + || test_pf_static32 () + || test_pf_auto () + || test_pf_guided32 () + || test_pf_runtime () + || test_f_static () + || test_f_static32 () + || test_f_auto () + || test_f_guided32 () + || test_f_runtime ()) + abort (); + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/loop-1.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/loop-1.C new file mode 100644 index 000000000..0e83c9583 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/loop-1.C @@ -0,0 +1,96 @@ +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <omp.h> + +#define MAX 1000 + +void main1() +{ + int i, N1, N2, step; + int a[MAX], b[MAX]; + + N1 = rand () % 13; + N2 = rand () % (MAX - 51) + 50; + step = rand () % 7 + 1; + + printf ("N1 = %d\nN2 = %d\nstep = %d\n", N1, N2, step); + + for (i = N1; i <= N2; i += step) + a[i] = 42+ i; + + /* COUNTING UP (<). Fill in array 'b' in parallel. */ + memset (b, 0, sizeof b); +#pragma omp parallel shared(a,b,N1,N2,step) private(i) + { +#pragma omp for + for (i = N1; i < N2; i += step) + b[i] = a[i]; + } + + /* COUNTING UP (<). Check that all the cells were filled in properly. */ + for (i = N1; i < N2; i += step) + if (a[i] != b[i]) + abort (); + + printf ("for (i = %d; i < %d; i += %d) [OK]\n", N1, N2, step); + + /* COUNTING UP (<=). Fill in array 'b' in parallel. */ + memset (b, 0, sizeof b); +#pragma omp parallel shared(a,b,N1,N2,step) private(i) + { +#pragma omp for + for (i = N1; i <= N2; i += step) + b[i] = a[i]; + } + + /* COUNTING UP (<=). Check that all the cells were filled in properly. */ + for (i = N1; i <= N2; i += step) + if (a[i] != b[i]) + abort (); + + printf ("for (i = %d; i <= %d; i += %d) [OK]\n", N1, N2, step); + + /* COUNTING DOWN (>). Fill in array 'b' in parallel. */ + memset (b, 0, sizeof b); +#pragma omp parallel shared(a,b,N1,N2,step) private(i) + { +#pragma omp for + for (i = N2; i > N1; i -= step) + b[i] = a[i]; + } + + /* COUNTING DOWN (>). Check that all the cells were filled in properly. */ + for (i = N2; i > N1; i -= step) + if (a[i] != b[i]) + abort (); + + printf ("for (i = %d; i > %d; i -= %d) [OK]\n", N2, N1, step); + + /* COUNTING DOWN (>=). Fill in array 'b' in parallel. */ + memset (b, 0, sizeof b); +#pragma omp parallel shared(a,b,N1,N2,step) private(i) + { +#pragma omp for + for (i = N2; i >= N1; i -= step) + b[i] = a[i]; + } + + /* COUNTING DOWN (>=). Check that all the cells were filled in properly. */ + for (i = N2; i >= N1; i -= step) + if (a[i] != b[i]) + abort (); + + printf ("for (i = %d; i >= %d; i -= %d) [OK]\n", N2, N1, step); +} + +int +main () +{ + int i; + + srand (0); + for (i = 0; i < 10; ++i) + main1(); + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/loop-10.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/loop-10.C new file mode 100644 index 000000000..9c0de25d5 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/loop-10.C @@ -0,0 +1,105 @@ +// { dg-do run } + +#include <omp.h> + +extern "C" void abort (void); + +#define LLONG_MAX __LONG_LONG_MAX__ +#define ULLONG_MAX (LLONG_MAX * 2ULL + 1) +#define INT_MAX __INT_MAX__ + +int v; + +int +test1 (void) +{ + int e = 0, cnt = 0; + long long i; + unsigned long long j; + char buf[6], *p; + + #pragma omp for schedule(dynamic,1) collapse(2) nowait + for (i = LLONG_MAX - 30001; i <= LLONG_MAX - 10001; i += 10000) + for (j = 20; j <= LLONG_MAX - 70; j += LLONG_MAX + 50ULL) + if ((i != LLONG_MAX - 30001 + && i != LLONG_MAX - 20001 + && i != LLONG_MAX - 10001) + || j != 20) + e = 1; + else + cnt++; + if (e || cnt != 3) + abort (); + else + cnt = 0; + + #pragma omp for schedule(guided,1) collapse(2) nowait + for (i = -LLONG_MAX + 30000; i >= -LLONG_MAX + 10000; i -= 10000) + for (j = ULLONG_MAX - 3; j >= LLONG_MAX + 70ULL; j -= LLONG_MAX + 50ULL) + if ((i != -LLONG_MAX + 30000 + && i != -LLONG_MAX + 20000 + && i != -LLONG_MAX + 10000) + || j != ULLONG_MAX - 3) + e = 1; + else + cnt++; + if (e || cnt != 3) + abort (); + else + cnt = 0; + + #pragma omp for schedule(static,1) collapse(2) nowait + for (i = LLONG_MAX - 30001; i <= LLONG_MAX - 10001; i += 10000) + for (j = 20; j <= LLONG_MAX - 70 + v; j += LLONG_MAX + 50ULL) + if ((i != LLONG_MAX - 30001 + && i != LLONG_MAX - 20001 + && i != LLONG_MAX - 10001) + || j != 20) + e = 1; + else + cnt++; + if (e || cnt != 3) + abort (); + else + cnt = 0; + + #pragma omp for schedule(static) collapse(2) nowait + for (i = -LLONG_MAX + 30000 + v; i >= -LLONG_MAX + 10000; i -= 10000) + for (j = ULLONG_MAX - 3; j >= LLONG_MAX + 70ULL; j -= LLONG_MAX + 50ULL) + if ((i != -LLONG_MAX + 30000 + && i != -LLONG_MAX + 20000 + && i != -LLONG_MAX + 10000) + || j != ULLONG_MAX - 3) + e = 1; + else + cnt++; + if (e || cnt != 3) + abort (); + else + cnt = 0; + + #pragma omp for schedule(runtime) collapse(2) nowait + for (i = 10; i < 30; i++) + for (p = buf; p <= buf + 4; p += 2) + if (i < 10 || i >= 30 || (p != buf && p != buf + 2 && p != buf + 4)) + e = 1; + else + cnt++; + if (e || cnt != 60) + abort (); + else + cnt = 0; + + return 0; +} + +int +main (void) +{ + if (2 * sizeof (int) != sizeof (long long)) + return 0; + asm volatile ("" : "+r" (v)); + omp_set_schedule (omp_sched_dynamic, 1); + test1 (); + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/loop-11.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/loop-11.C new file mode 100644 index 000000000..7775b86b8 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/loop-11.C @@ -0,0 +1,276 @@ +#include <omp.h> +#include <stdlib.h> +#include <string.h> + +int +test1 () +{ + short int buf[64], *p; + int i; + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for + for (p = &buf[10]; &buf[54] > p; p++) + *p = 5; + for (i = 0; i < 64; i++) + if (buf[i] != 5 * (i >= 10 && i < 54)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for + for (p = &buf[3]; &buf[63] >= p; p += 2) + p[-2] = 6; + for (i = 0; i < 64; i++) + if (buf[i] != 6 * ((i & 1) && i <= 61)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for + for (p = &buf[16]; &buf[51] > p; p = 4 + p) + p[2] = 7; + for (i = 0; i < 64; i++) + if (buf[i] != 7 * ((i & 3) == 2 && i >= 18 && i < 53)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for + for (p = &buf[16]; &buf[40] >= p; p = p + 4ULL) + p[2] = -7; + for (i = 0; i < 64; i++) + if (buf[i] != -7 * ((i & 3) == 2 && i >= 18 && i <= 42)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for + for (p = &buf[53]; &buf[9] < p; --p) + *p = 5; + for (i = 0; i < 64; i++) + if (buf[i] != 5 * (i >= 10 && i < 54)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for + for (p = &buf[63]; &buf[3] <= p; p -= 2) + p[-2] = 6; + for (i = 0; i < 64; i++) + if (buf[i] != 6 * ((i & 1) && i <= 61)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for + for (p = &buf[48]; &buf[15] < p; p = -4 + p) + p[2] = 7; + for (i = 0; i < 64; i++) + if (buf[i] != 7 * ((i & 3) == 2 && i >= 18 && i < 53)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for + for (p = &buf[40]; &buf[16] <= p; p = p - 4ULL) + p[2] = -7; + for (i = 0; i < 64; i++) + if (buf[i] != -7 * ((i & 3) == 2 && i >= 18 && i <= 42)) + abort (); + return 0; +} + +int +test2 () +{ + int buf[64], *p; + int i; + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for schedule (static, 3) + for (p = &buf[10]; &buf[54] > p; p++) + *p = 5; + for (i = 0; i < 64; i++) + if (buf[i] != 5 * (i >= 10 && i < 54)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for schedule (static, 3) + for (p = &buf[3]; &buf[63] >= p; p += 2) + p[-2] = 6; + for (i = 0; i < 64; i++) + if (buf[i] != 6 * ((i & 1) && i <= 61)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for schedule (static, 3) + for (p = &buf[16]; &buf[51] > p; p = 4 + p) + p[2] = 7; + for (i = 0; i < 64; i++) + if (buf[i] != 7 * ((i & 3) == 2 && i >= 18 && i < 53)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for schedule (static, 3) + for (p = &buf[16]; &buf[40] >= p; p = p + 4ULL) + p[2] = -7; + for (i = 0; i < 64; i++) + if (buf[i] != -7 * ((i & 3) == 2 && i >= 18 && i <= 42)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for schedule (static, 3) + for (p = &buf[53]; &buf[9] < p; --p) + *p = 5; + for (i = 0; i < 64; i++) + if (buf[i] != 5 * (i >= 10 && i < 54)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for schedule (static, 3) + for (p = &buf[63]; &buf[3] <= p; p -= 2) + p[-2] = 6; + for (i = 0; i < 64; i++) + if (buf[i] != 6 * ((i & 1) && i <= 61)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for schedule (static, 3) + for (p = &buf[48]; &buf[15] < p; p = -4 + p) + p[2] = 7; + for (i = 0; i < 64; i++) + if (buf[i] != 7 * ((i & 3) == 2 && i >= 18 && i < 53)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for schedule (static, 3) + for (p = &buf[40]; &buf[16] <= p; p = p - 4ULL) + p[2] = -7; + for (i = 0; i < 64; i++) + if (buf[i] != -7 * ((i & 3) == 2 && i >= 18 && i <= 42)) + abort (); + return 0; +} + +int +test3 () +{ + int buf[64], *p; + int i; + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for schedule (dynamic, 3) + for (p = &buf[10]; &buf[54] > p; p++) + *p = 5; + for (i = 0; i < 64; i++) + if (buf[i] != 5 * (i >= 10 && i < 54)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for schedule (dynamic, 3) + for (p = &buf[3]; &buf[63] >= p; p += 2) + p[-2] = 6; + for (i = 0; i < 64; i++) + if (buf[i] != 6 * ((i & 1) && i <= 61)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for schedule (dynamic, 3) + for (p = &buf[16]; &buf[51] > p; p = 4 + p) + p[2] = 7; + for (i = 0; i < 64; i++) + if (buf[i] != 7 * ((i & 3) == 2 && i >= 18 && i < 53)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for schedule (dynamic, 3) + for (p = &buf[16]; &buf[40] >= p; p = p + 4ULL) + p[2] = -7; + for (i = 0; i < 64; i++) + if (buf[i] != -7 * ((i & 3) == 2 && i >= 18 && i <= 42)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for schedule (dynamic, 3) + for (p = &buf[53]; &buf[9] < p; --p) + *p = 5; + for (i = 0; i < 64; i++) + if (buf[i] != 5 * (i >= 10 && i < 54)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for schedule (dynamic, 3) + for (p = &buf[63]; &buf[3] <= p; p -= 2) + p[-2] = 6; + for (i = 0; i < 64; i++) + if (buf[i] != 6 * ((i & 1) && i <= 61)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for schedule (dynamic, 3) + for (p = &buf[48]; &buf[15] < p; p = -4 + p) + p[2] = 7; + for (i = 0; i < 64; i++) + if (buf[i] != 7 * ((i & 3) == 2 && i >= 18 && i < 53)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for schedule (dynamic, 3) + for (p = &buf[40]; &buf[16] <= p; p = p - 4ULL) + p[2] = -7; + for (i = 0; i < 64; i++) + if (buf[i] != -7 * ((i & 3) == 2 && i >= 18 && i <= 42)) + abort (); + return 0; +} + +int +test4 () +{ + int buf[64], *p; + int i; + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for schedule (runtime) + for (p = &buf[10]; &buf[54] > p; p++) + *p = 5; + for (i = 0; i < 64; i++) + if (buf[i] != 5 * (i >= 10 && i < 54)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for schedule (runtime) + for (p = &buf[3]; &buf[63] >= p; p += 2) + p[-2] = 6; + for (i = 0; i < 64; i++) + if (buf[i] != 6 * ((i & 1) && i <= 61)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for schedule (runtime) + for (p = &buf[16]; &buf[51] > p; p = 4 + p) + p[2] = 7; + for (i = 0; i < 64; i++) + if (buf[i] != 7 * ((i & 3) == 2 && i >= 18 && i < 53)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for schedule (runtime) + for (p = &buf[16]; &buf[40] >= p; p = p + 4ULL) + p[2] = -7; + for (i = 0; i < 64; i++) + if (buf[i] != -7 * ((i & 3) == 2 && i >= 18 && i <= 42)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for schedule (runtime) + for (p = &buf[53]; &buf[9] < p; --p) + *p = 5; + for (i = 0; i < 64; i++) + if (buf[i] != 5 * (i >= 10 && i < 54)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for schedule (runtime) + for (p = &buf[63]; &buf[3] <= p; p -= 2) + p[-2] = 6; + for (i = 0; i < 64; i++) + if (buf[i] != 6 * ((i & 1) && i <= 61)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for schedule (runtime) + for (p = &buf[48]; &buf[15] < p; p = -4 + p) + p[2] = 7; + for (i = 0; i < 64; i++) + if (buf[i] != 7 * ((i & 3) == 2 && i >= 18 && i < 53)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for schedule (runtime) + for (p = &buf[40]; &buf[16] <= p; p = p - 4ULL) + p[2] = -7; + for (i = 0; i < 64; i++) + if (buf[i] != -7 * ((i & 3) == 2 && i >= 18 && i <= 42)) + abort (); + return 0; +} + +int +main () +{ + test1 (); + test2 (); + test3 (); + omp_set_schedule (omp_sched_static, 0); + test4 (); + omp_set_schedule (omp_sched_static, 3); + test4 (); + omp_set_schedule (omp_sched_dynamic, 5); + test4 (); + omp_set_schedule (omp_sched_guided, 2); + test4 (); + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/loop-12.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/loop-12.C new file mode 100644 index 000000000..f8aca92b8 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/loop-12.C @@ -0,0 +1,387 @@ +// { dg-do run } + +#include <omp.h> + +extern "C" void abort (); + +#define LLONG_MAX __LONG_LONG_MAX__ +#define ULLONG_MAX (LLONG_MAX * 2ULL + 1) +#define INT_MAX __INT_MAX__ + +int arr[6 * 5]; + +void +set (int loopidx, int idx) +{ +#pragma omp atomic + arr[loopidx * 5 + idx]++; +} + +#define check(var, val, loopidx, idx) \ + if (var == (val)) set (loopidx, idx); else +#define test(loopidx, count) \ + for (idx = 0; idx < 5; idx++) \ + if (arr[loopidx * 5 + idx] != idx < count) \ + abort (); \ + else \ + arr[loopidx * 5 + idx] = 0 + +int +test1 () +{ + int e = 0, idx; + +#pragma omp parallel reduction(+:e) + { + long long i; + unsigned long long j; + #pragma omp for schedule(dynamic,1) nowait + for (i = LLONG_MAX - 30001; LLONG_MAX - 10001 >= i; i += 10000) + { + check (i, LLONG_MAX - 30001, 0, 0) + check (i, LLONG_MAX - 20001, 0, 1) + check (i, LLONG_MAX - 10001, 0, 2) + e = 1; + } + #pragma omp for schedule(dynamic,1) nowait + for (i = -LLONG_MAX + 30000; -LLONG_MAX + 10000 <= i; i -= 10000) + { + check (i, -LLONG_MAX + 30000, 1, 0) + check (i, -LLONG_MAX + 20000, 1, 1) + check (i, -LLONG_MAX + 10000, 1, 2) + e = 1; + } + #pragma omp for schedule(dynamic,1) nowait + for (j = 20; LLONG_MAX - 70 >= j; j += LLONG_MAX + 50ULL) + { + check (j, 20, 2, 0) + e = 1; + } + #pragma omp for schedule(dynamic,1) nowait + for (j = ULLONG_MAX - 3; LLONG_MAX + 70ULL <= j; j -= LLONG_MAX + 50ULL) + { + check (j, ULLONG_MAX - 3, 3, 0) + e = 1; + } + #pragma omp for schedule(dynamic,1) nowait + for (j = LLONG_MAX - 20000ULL; LLONG_MAX + 10000ULL >= j; j += 10000ULL) + { + check (j, LLONG_MAX - 20000ULL, 4, 0) + check (j, LLONG_MAX - 10000ULL, 4, 1) + check (j, LLONG_MAX, 4, 2) + check (j, LLONG_MAX + 10000ULL, 4, 3) + e = 1; + } + #pragma omp for schedule(dynamic,1) nowait + for (i = -3LL * INT_MAX - 20000LL; INT_MAX + 10000LL >= i; i += INT_MAX + 200LL) + { + check (i, -3LL * INT_MAX - 20000LL, 5, 0) + check (i, -2LL * INT_MAX - 20000LL + 200LL, 5, 1) + check (i, -INT_MAX - 20000LL + 400LL, 5, 2) + check (i, -20000LL + 600LL, 5, 3) + check (i, INT_MAX - 20000LL + 800LL, 5, 4) + e = 1; + } + } + if (e) + abort (); + test (0, 3); + test (1, 3); + test (2, 1); + test (3, 1); + test (4, 4); + test (5, 5); + return 0; +} + +int +test2 () +{ + int e = 0, idx; + +#pragma omp parallel reduction(+:e) + { + long long i; + unsigned long long j; + #pragma omp for schedule(guided,1) nowait + for (i = LLONG_MAX - 30001; LLONG_MAX - 10001 >= i; i += 10000) + { + check (i, LLONG_MAX - 30001, 0, 0) + check (i, LLONG_MAX - 20001, 0, 1) + check (i, LLONG_MAX - 10001, 0, 2) + e = 1; + } + #pragma omp for schedule(guided,1) nowait + for (i = -LLONG_MAX + 30000; -LLONG_MAX + 10000 <= i; i -= 10000) + { + check (i, -LLONG_MAX + 30000, 1, 0) + check (i, -LLONG_MAX + 20000, 1, 1) + check (i, -LLONG_MAX + 10000, 1, 2) + e = 1; + } + #pragma omp for schedule(guided,1) nowait + for (j = 20; LLONG_MAX - 70 >= j; j += LLONG_MAX + 50ULL) + { + check (j, 20, 2, 0) + e = 1; + } + #pragma omp for schedule(guided,1) nowait + for (j = ULLONG_MAX - 3; LLONG_MAX + 70ULL <= j; j -= LLONG_MAX + 50ULL) + { + check (j, ULLONG_MAX - 3, 3, 0) + e = 1; + } + #pragma omp for schedule(guided,1) nowait + for (j = LLONG_MAX - 20000ULL; LLONG_MAX + 10000ULL >= j; j += 10000ULL) + { + check (j, LLONG_MAX - 20000ULL, 4, 0) + check (j, LLONG_MAX - 10000ULL, 4, 1) + check (j, LLONG_MAX, 4, 2) + check (j, LLONG_MAX + 10000ULL, 4, 3) + e = 1; + } + #pragma omp for schedule(guided,1) nowait + for (i = -3LL * INT_MAX - 20000LL; INT_MAX + 10000LL >= i; i += INT_MAX + 200LL) + { + check (i, -3LL * INT_MAX - 20000LL, 5, 0) + check (i, -2LL * INT_MAX - 20000LL + 200LL, 5, 1) + check (i, -INT_MAX - 20000LL + 400LL, 5, 2) + check (i, -20000LL + 600LL, 5, 3) + check (i, INT_MAX - 20000LL + 800LL, 5, 4) + e = 1; + } + } + if (e) + abort (); + test (0, 3); + test (1, 3); + test (2, 1); + test (3, 1); + test (4, 4); + test (5, 5); + return 0; +} + +int +test3 () +{ + int e = 0, idx; + +#pragma omp parallel reduction(+:e) + { + long long i; + unsigned long long j; + #pragma omp for schedule(static) nowait + for (i = LLONG_MAX - 30001; LLONG_MAX - 10001 >= i; i += 10000) + { + check (i, LLONG_MAX - 30001, 0, 0) + check (i, LLONG_MAX - 20001, 0, 1) + check (i, LLONG_MAX - 10001, 0, 2) + e = 1; + } + #pragma omp for schedule(static) nowait + for (i = -LLONG_MAX + 30000; -LLONG_MAX + 10000 <= i; i -= 10000) + { + check (i, -LLONG_MAX + 30000, 1, 0) + check (i, -LLONG_MAX + 20000, 1, 1) + check (i, -LLONG_MAX + 10000, 1, 2) + e = 1; + } + #pragma omp for schedule(static) nowait + for (j = 20; LLONG_MAX - 70 >= j; j += LLONG_MAX + 50ULL) + { + check (j, 20, 2, 0) + e = 1; + } + #pragma omp for schedule(static) nowait + for (j = ULLONG_MAX - 3; LLONG_MAX + 70ULL <= j; j -= LLONG_MAX + 50ULL) + { + check (j, ULLONG_MAX - 3, 3, 0) + e = 1; + } + #pragma omp for schedule(static) nowait + for (j = LLONG_MAX - 20000ULL; LLONG_MAX + 10000ULL >= j; j += 10000ULL) + { + check (j, LLONG_MAX - 20000ULL, 4, 0) + check (j, LLONG_MAX - 10000ULL, 4, 1) + check (j, LLONG_MAX, 4, 2) + check (j, LLONG_MAX + 10000ULL, 4, 3) + e = 1; + } + #pragma omp for schedule(static) nowait + for (i = -3LL * INT_MAX - 20000LL; INT_MAX + 10000LL >= i; i += INT_MAX + 200LL) + { + check (i, -3LL * INT_MAX - 20000LL, 5, 0) + check (i, -2LL * INT_MAX - 20000LL + 200LL, 5, 1) + check (i, -INT_MAX - 20000LL + 400LL, 5, 2) + check (i, -20000LL + 600LL, 5, 3) + check (i, INT_MAX - 20000LL + 800LL, 5, 4) + e = 1; + } + } + if (e) + abort (); + test (0, 3); + test (1, 3); + test (2, 1); + test (3, 1); + test (4, 4); + test (5, 5); + return 0; +} + +int +test4 () +{ + int e = 0, idx; + +#pragma omp parallel reduction(+:e) + { + long long i; + unsigned long long j; + #pragma omp for schedule(static,1) nowait + for (i = LLONG_MAX - 30001; LLONG_MAX - 10001 >= i; i += 10000) + { + check (i, LLONG_MAX - 30001, 0, 0) + check (i, LLONG_MAX - 20001, 0, 1) + check (i, LLONG_MAX - 10001, 0, 2) + e = 1; + } + #pragma omp for schedule(static,1) nowait + for (i = -LLONG_MAX + 30000; -LLONG_MAX + 10000 <= i; i -= 10000) + { + check (i, -LLONG_MAX + 30000, 1, 0) + check (i, -LLONG_MAX + 20000, 1, 1) + check (i, -LLONG_MAX + 10000, 1, 2) + e = 1; + } + #pragma omp for schedule(static,1) nowait + for (j = 20; LLONG_MAX - 70 >= j; j += LLONG_MAX + 50ULL) + { + check (j, 20, 2, 0) + e = 1; + } + #pragma omp for schedule(static,1) nowait + for (j = ULLONG_MAX - 3; LLONG_MAX + 70ULL <= j; j -= LLONG_MAX + 50ULL) + { + check (j, ULLONG_MAX - 3, 3, 0) + e = 1; + } + #pragma omp for schedule(static,1) nowait + for (j = LLONG_MAX - 20000ULL; LLONG_MAX + 10000ULL >= j; j += 10000ULL) + { + check (j, LLONG_MAX - 20000ULL, 4, 0) + check (j, LLONG_MAX - 10000ULL, 4, 1) + check (j, LLONG_MAX, 4, 2) + check (j, LLONG_MAX + 10000ULL, 4, 3) + e = 1; + } + #pragma omp for schedule(static,1) nowait + for (i = -3LL * INT_MAX - 20000LL; INT_MAX + 10000LL >= i; i += INT_MAX + 200LL) + { + check (i, -3LL * INT_MAX - 20000LL, 5, 0) + check (i, -2LL * INT_MAX - 20000LL + 200LL, 5, 1) + check (i, -INT_MAX - 20000LL + 400LL, 5, 2) + check (i, -20000LL + 600LL, 5, 3) + check (i, INT_MAX - 20000LL + 800LL, 5, 4) + e = 1; + } + } + if (e) + abort (); + test (0, 3); + test (1, 3); + test (2, 1); + test (3, 1); + test (4, 4); + test (5, 5); + return 0; +} + +int +test5 () +{ + int e = 0, idx; + +#pragma omp parallel reduction(+:e) + { + long long i; + unsigned long long j; + #pragma omp for schedule(runtime) nowait + for (i = LLONG_MAX - 30001; LLONG_MAX - 10001 >= i; i += 10000) + { + check (i, LLONG_MAX - 30001, 0, 0) + check (i, LLONG_MAX - 20001, 0, 1) + check (i, LLONG_MAX - 10001, 0, 2) + e = 1; + } + #pragma omp for schedule(runtime) nowait + for (i = -LLONG_MAX + 30000; -LLONG_MAX + 10000 <= i; i -= 10000) + { + check (i, -LLONG_MAX + 30000, 1, 0) + check (i, -LLONG_MAX + 20000, 1, 1) + check (i, -LLONG_MAX + 10000, 1, 2) + e = 1; + } + #pragma omp for schedule(runtime) nowait + for (j = 20; LLONG_MAX - 70 >= j; j += LLONG_MAX + 50ULL) + { + check (j, 20, 2, 0) + e = 1; + } + #pragma omp for schedule(runtime) nowait + for (j = ULLONG_MAX - 3; LLONG_MAX + 70ULL <= j; j -= LLONG_MAX + 50ULL) + { + check (j, ULLONG_MAX - 3, 3, 0) + e = 1; + } + #pragma omp for schedule(runtime) nowait + for (j = LLONG_MAX - 20000ULL; LLONG_MAX + 10000ULL >= j; j += 10000ULL) + { + check (j, LLONG_MAX - 20000ULL, 4, 0) + check (j, LLONG_MAX - 10000ULL, 4, 1) + check (j, LLONG_MAX, 4, 2) + check (j, LLONG_MAX + 10000ULL, 4, 3) + e = 1; + } + #pragma omp for schedule(runtime) nowait + for (i = -3LL * INT_MAX - 20000LL; INT_MAX + 10000LL >= i; i += INT_MAX + 200LL) + { + check (i, -3LL * INT_MAX - 20000LL, 5, 0) + check (i, -2LL * INT_MAX - 20000LL + 200LL, 5, 1) + check (i, -INT_MAX - 20000LL + 400LL, 5, 2) + check (i, -20000LL + 600LL, 5, 3) + check (i, INT_MAX - 20000LL + 800LL, 5, 4) + e = 1; + } + } + if (e) + abort (); + test (0, 3); + test (1, 3); + test (2, 1); + test (3, 1); + test (4, 4); + test (5, 5); + return 0; +} + +int +main () +{ + if (2 * sizeof (int) != sizeof (long long)) + return 0; + test1 (); + test2 (); + test3 (); + test4 (); + omp_set_schedule (omp_sched_static, 0); + test5 (); + omp_set_schedule (omp_sched_static, 3); + test5 (); + omp_set_schedule (omp_sched_dynamic, 5); + test5 (); + omp_set_schedule (omp_sched_guided, 2); + test5 (); + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/loop-13.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/loop-13.C new file mode 100644 index 000000000..31572be0f --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/loop-13.C @@ -0,0 +1,3 @@ +/* { dg-do run } */ + +#include "../libgomp.c/loop-13.c" diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/loop-14.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/loop-14.C new file mode 100644 index 000000000..ba2856ac1 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/loop-14.C @@ -0,0 +1,3 @@ +/* { dg-do run } */ + +#include "../libgomp.c/loop-14.c" diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/loop-15.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/loop-15.C new file mode 100644 index 000000000..9bde48e3a --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/loop-15.C @@ -0,0 +1,3 @@ +/* { dg-do run } */ + +#include "../libgomp.c/loop-15.c" diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/loop-2.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/loop-2.C new file mode 100644 index 000000000..ea3dc588a --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/loop-2.C @@ -0,0 +1,32 @@ +#include <omp.h> + +/* Orphaned work sharing. */ + +extern "C" void abort (void); + +#define N 10 + +void parloop (int *a) +{ + int i; + +#pragma omp for + for (i = 0; i < N; i++) + a[i] = i + 3; +} + +main() +{ + int i, a[N]; + +#pragma omp parallel shared(a) + { + parloop (a); + } + + for (i = 0; i < N; i++) + if (a[i] != i + 3) + abort (); + + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/loop-3.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/loop-3.C new file mode 100644 index 000000000..fa50f099f --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/loop-3.C @@ -0,0 +1,26 @@ +extern "C" void abort (void); +int a; + +void +foo () +{ + int i; + a = 30; +#pragma omp barrier +#pragma omp for lastprivate (a) + for (i = 0; i < 1024; i++) + { + a = i; + } + if (a != 1023) + abort (); +} + +int +main (void) +{ +#pragma omp parallel num_threads (64) + foo (); + + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/loop-4.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/loop-4.C new file mode 100644 index 000000000..731f23450 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/loop-4.C @@ -0,0 +1,20 @@ +extern "C" void abort (void); + +main() +{ + int i, a; + + a = 30; + +#pragma omp parallel for firstprivate (a) lastprivate (a) \ + num_threads (2) schedule(static) + for (i = 0; i < 10; i++) + a = a + i; + + /* The thread that owns the last iteration will have computed + 30 + 5 + 6 + 7 + 8 + 9 = 65. */ + if (a != 65) + abort (); + + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/loop-5.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/loop-5.C new file mode 100644 index 000000000..c427efa85 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/loop-5.C @@ -0,0 +1,19 @@ +extern "C" void abort (); + +int check; +int f1() { check |= 1; return 1; } +int f2() { check |= 2; return 11; } +int f3() { check |= 4; return 2; } + +int a[12]; + +int main() +{ + #pragma omp for + for (int i = f1(); i <= f2(); i += f3()) + a[i] = 1; + + for (int i = 0; i < 12; ++i) + if (a[i] != (i & 1)) + abort (); +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/loop-6.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/loop-6.C new file mode 100644 index 000000000..f4a6925a4 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/loop-6.C @@ -0,0 +1,25 @@ +// { dg-do run } + +extern "C" void abort (void); + +volatile int count; +static int test(void) +{ + return ++count > 0; +} + +int i; + +int main() +{ + #pragma omp for lastprivate (i) + for (i = 0; i < 10; ++i) + { + if (test()) + continue; + abort (); + } + if (i != count) + abort (); + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/loop-7.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/loop-7.C new file mode 100644 index 000000000..4eccb7fca --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/loop-7.C @@ -0,0 +1,22 @@ +// PR c++/24502 +// { dg-do run } + +extern "C" void abort (); + +template <typename T> T +foo (T r) +{ + T i; +#pragma omp for + for (i = 0; i < 10; i++) + r += i; + return r; +} + +int +main () +{ + if (foo (0) != 10 * 9 / 2 || foo (2L) != 10L * 9 / 2 + 2) + abort (); + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/loop-8.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/loop-8.C new file mode 100644 index 000000000..bc20c68a1 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/loop-8.C @@ -0,0 +1,276 @@ +#include <omp.h> +#include <stdlib.h> +#include <string.h> + +int +test1 () +{ + short int buf[64], *p; + int i; + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for + for (p = &buf[10]; p < &buf[54]; p++) + *p = 5; + for (i = 0; i < 64; i++) + if (buf[i] != 5 * (i >= 10 && i < 54)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for + for (p = &buf[3]; p <= &buf[63]; p += 2) + p[-2] = 6; + for (i = 0; i < 64; i++) + if (buf[i] != 6 * ((i & 1) && i <= 61)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for + for (p = &buf[16]; p < &buf[51]; p = 4 + p) + p[2] = 7; + for (i = 0; i < 64; i++) + if (buf[i] != 7 * ((i & 3) == 2 && i >= 18 && i < 53)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for + for (p = &buf[16]; p <= &buf[40]; p = p + 4ULL) + p[2] = -7; + for (i = 0; i < 64; i++) + if (buf[i] != -7 * ((i & 3) == 2 && i >= 18 && i <= 42)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for + for (p = &buf[53]; p > &buf[9]; --p) + *p = 5; + for (i = 0; i < 64; i++) + if (buf[i] != 5 * (i >= 10 && i < 54)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for + for (p = &buf[63]; p >= &buf[3]; p -= 2) + p[-2] = 6; + for (i = 0; i < 64; i++) + if (buf[i] != 6 * ((i & 1) && i <= 61)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for + for (p = &buf[48]; p > &buf[15]; p = -4 + p) + p[2] = 7; + for (i = 0; i < 64; i++) + if (buf[i] != 7 * ((i & 3) == 2 && i >= 18 && i < 53)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for + for (p = &buf[40]; p >= &buf[16]; p = p - 4ULL) + p[2] = -7; + for (i = 0; i < 64; i++) + if (buf[i] != -7 * ((i & 3) == 2 && i >= 18 && i <= 42)) + abort (); + return 0; +} + +int +test2 () +{ + int buf[64], *p; + int i; + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for schedule (static, 3) + for (p = &buf[10]; p < &buf[54]; p++) + *p = 5; + for (i = 0; i < 64; i++) + if (buf[i] != 5 * (i >= 10 && i < 54)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for schedule (static, 3) + for (p = &buf[3]; p <= &buf[63]; p += 2) + p[-2] = 6; + for (i = 0; i < 64; i++) + if (buf[i] != 6 * ((i & 1) && i <= 61)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for schedule (static, 3) + for (p = &buf[16]; p < &buf[51]; p = 4 + p) + p[2] = 7; + for (i = 0; i < 64; i++) + if (buf[i] != 7 * ((i & 3) == 2 && i >= 18 && i < 53)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for schedule (static, 3) + for (p = &buf[16]; p <= &buf[40]; p = p + 4ULL) + p[2] = -7; + for (i = 0; i < 64; i++) + if (buf[i] != -7 * ((i & 3) == 2 && i >= 18 && i <= 42)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for schedule (static, 3) + for (p = &buf[53]; p > &buf[9]; --p) + *p = 5; + for (i = 0; i < 64; i++) + if (buf[i] != 5 * (i >= 10 && i < 54)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for schedule (static, 3) + for (p = &buf[63]; p >= &buf[3]; p -= 2) + p[-2] = 6; + for (i = 0; i < 64; i++) + if (buf[i] != 6 * ((i & 1) && i <= 61)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for schedule (static, 3) + for (p = &buf[48]; p > &buf[15]; p = -4 + p) + p[2] = 7; + for (i = 0; i < 64; i++) + if (buf[i] != 7 * ((i & 3) == 2 && i >= 18 && i < 53)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for schedule (static, 3) + for (p = &buf[40]; p >= &buf[16]; p = p - 4ULL) + p[2] = -7; + for (i = 0; i < 64; i++) + if (buf[i] != -7 * ((i & 3) == 2 && i >= 18 && i <= 42)) + abort (); + return 0; +} + +int +test3 () +{ + int buf[64], *p; + int i; + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for schedule (dynamic, 3) + for (p = &buf[10]; p < &buf[54]; p++) + *p = 5; + for (i = 0; i < 64; i++) + if (buf[i] != 5 * (i >= 10 && i < 54)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for schedule (dynamic, 3) + for (p = &buf[3]; p <= &buf[63]; p += 2) + p[-2] = 6; + for (i = 0; i < 64; i++) + if (buf[i] != 6 * ((i & 1) && i <= 61)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for schedule (dynamic, 3) + for (p = &buf[16]; p < &buf[51]; p = 4 + p) + p[2] = 7; + for (i = 0; i < 64; i++) + if (buf[i] != 7 * ((i & 3) == 2 && i >= 18 && i < 53)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for schedule (dynamic, 3) + for (p = &buf[16]; p <= &buf[40]; p = p + 4ULL) + p[2] = -7; + for (i = 0; i < 64; i++) + if (buf[i] != -7 * ((i & 3) == 2 && i >= 18 && i <= 42)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for schedule (dynamic, 3) + for (p = &buf[53]; p > &buf[9]; --p) + *p = 5; + for (i = 0; i < 64; i++) + if (buf[i] != 5 * (i >= 10 && i < 54)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for schedule (dynamic, 3) + for (p = &buf[63]; p >= &buf[3]; p -= 2) + p[-2] = 6; + for (i = 0; i < 64; i++) + if (buf[i] != 6 * ((i & 1) && i <= 61)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for schedule (dynamic, 3) + for (p = &buf[48]; p > &buf[15]; p = -4 + p) + p[2] = 7; + for (i = 0; i < 64; i++) + if (buf[i] != 7 * ((i & 3) == 2 && i >= 18 && i < 53)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for schedule (dynamic, 3) + for (p = &buf[40]; p >= &buf[16]; p = p - 4ULL) + p[2] = -7; + for (i = 0; i < 64; i++) + if (buf[i] != -7 * ((i & 3) == 2 && i >= 18 && i <= 42)) + abort (); + return 0; +} + +int +test4 () +{ + int buf[64], *p; + int i; + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for schedule (runtime) + for (p = &buf[10]; p < &buf[54]; p++) + *p = 5; + for (i = 0; i < 64; i++) + if (buf[i] != 5 * (i >= 10 && i < 54)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for schedule (runtime) + for (p = &buf[3]; p <= &buf[63]; p += 2) + p[-2] = 6; + for (i = 0; i < 64; i++) + if (buf[i] != 6 * ((i & 1) && i <= 61)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for schedule (runtime) + for (p = &buf[16]; p < &buf[51]; p = 4 + p) + p[2] = 7; + for (i = 0; i < 64; i++) + if (buf[i] != 7 * ((i & 3) == 2 && i >= 18 && i < 53)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for schedule (runtime) + for (p = &buf[16]; p <= &buf[40]; p = p + 4ULL) + p[2] = -7; + for (i = 0; i < 64; i++) + if (buf[i] != -7 * ((i & 3) == 2 && i >= 18 && i <= 42)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for schedule (runtime) + for (p = &buf[53]; p > &buf[9]; --p) + *p = 5; + for (i = 0; i < 64; i++) + if (buf[i] != 5 * (i >= 10 && i < 54)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for schedule (runtime) + for (p = &buf[63]; p >= &buf[3]; p -= 2) + p[-2] = 6; + for (i = 0; i < 64; i++) + if (buf[i] != 6 * ((i & 1) && i <= 61)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for schedule (runtime) + for (p = &buf[48]; p > &buf[15]; p = -4 + p) + p[2] = 7; + for (i = 0; i < 64; i++) + if (buf[i] != 7 * ((i & 3) == 2 && i >= 18 && i < 53)) + abort (); + memset (buf, '\0', sizeof (buf)); +#pragma omp parallel for schedule (runtime) + for (p = &buf[40]; p >= &buf[16]; p = p - 4ULL) + p[2] = -7; + for (i = 0; i < 64; i++) + if (buf[i] != -7 * ((i & 3) == 2 && i >= 18 && i <= 42)) + abort (); + return 0; +} + +int +main () +{ + test1 (); + test2 (); + test3 (); + omp_set_schedule (omp_sched_static, 0); + test4 (); + omp_set_schedule (omp_sched_static, 3); + test4 (); + omp_set_schedule (omp_sched_dynamic, 5); + test4 (); + omp_set_schedule (omp_sched_guided, 2); + test4 (); + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/loop-9.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/loop-9.C new file mode 100644 index 000000000..35daf2276 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/loop-9.C @@ -0,0 +1,387 @@ +// { dg-do run } + +#include <omp.h> + +extern "C" void abort (); + +#define LLONG_MAX __LONG_LONG_MAX__ +#define ULLONG_MAX (LLONG_MAX * 2ULL + 1) +#define INT_MAX __INT_MAX__ + +int arr[6 * 5]; + +void +set (int loopidx, int idx) +{ +#pragma omp atomic + arr[loopidx * 5 + idx]++; +} + +#define check(var, val, loopidx, idx) \ + if (var == (val)) set (loopidx, idx); else +#define test(loopidx, count) \ + for (idx = 0; idx < 5; idx++) \ + if (arr[loopidx * 5 + idx] != idx < count) \ + abort (); \ + else \ + arr[loopidx * 5 + idx] = 0 + +int +test1 () +{ + int e = 0, idx; + +#pragma omp parallel reduction(+:e) + { + long long i; + unsigned long long j; + #pragma omp for schedule(dynamic,1) nowait + for (i = LLONG_MAX - 30001; i <= LLONG_MAX - 10001; i += 10000) + { + check (i, LLONG_MAX - 30001, 0, 0) + check (i, LLONG_MAX - 20001, 0, 1) + check (i, LLONG_MAX - 10001, 0, 2) + e = 1; + } + #pragma omp for schedule(dynamic,1) nowait + for (i = -LLONG_MAX + 30000; i >= -LLONG_MAX + 10000; i -= 10000) + { + check (i, -LLONG_MAX + 30000, 1, 0) + check (i, -LLONG_MAX + 20000, 1, 1) + check (i, -LLONG_MAX + 10000, 1, 2) + e = 1; + } + #pragma omp for schedule(dynamic,1) nowait + for (j = 20; j <= LLONG_MAX - 70; j += LLONG_MAX + 50ULL) + { + check (j, 20, 2, 0) + e = 1; + } + #pragma omp for schedule(dynamic,1) nowait + for (j = ULLONG_MAX - 3; j >= LLONG_MAX + 70ULL; j -= LLONG_MAX + 50ULL) + { + check (j, ULLONG_MAX - 3, 3, 0) + e = 1; + } + #pragma omp for schedule(dynamic,1) nowait + for (j = LLONG_MAX - 20000ULL; j <= LLONG_MAX + 10000ULL; j += 10000ULL) + { + check (j, LLONG_MAX - 20000ULL, 4, 0) + check (j, LLONG_MAX - 10000ULL, 4, 1) + check (j, LLONG_MAX, 4, 2) + check (j, LLONG_MAX + 10000ULL, 4, 3) + e = 1; + } + #pragma omp for schedule(dynamic,1) nowait + for (i = -3LL * INT_MAX - 20000LL; i <= INT_MAX + 10000LL; i += INT_MAX + 200LL) + { + check (i, -3LL * INT_MAX - 20000LL, 5, 0) + check (i, -2LL * INT_MAX - 20000LL + 200LL, 5, 1) + check (i, -INT_MAX - 20000LL + 400LL, 5, 2) + check (i, -20000LL + 600LL, 5, 3) + check (i, INT_MAX - 20000LL + 800LL, 5, 4) + e = 1; + } + } + if (e) + abort (); + test (0, 3); + test (1, 3); + test (2, 1); + test (3, 1); + test (4, 4); + test (5, 5); + return 0; +} + +int +test2 () +{ + int e = 0, idx; + +#pragma omp parallel reduction(+:e) + { + long long i; + unsigned long long j; + #pragma omp for schedule(guided,1) nowait + for (i = LLONG_MAX - 30001; i <= LLONG_MAX - 10001; i += 10000) + { + check (i, LLONG_MAX - 30001, 0, 0) + check (i, LLONG_MAX - 20001, 0, 1) + check (i, LLONG_MAX - 10001, 0, 2) + e = 1; + } + #pragma omp for schedule(guided,1) nowait + for (i = -LLONG_MAX + 30000; i >= -LLONG_MAX + 10000; i -= 10000) + { + check (i, -LLONG_MAX + 30000, 1, 0) + check (i, -LLONG_MAX + 20000, 1, 1) + check (i, -LLONG_MAX + 10000, 1, 2) + e = 1; + } + #pragma omp for schedule(guided,1) nowait + for (j = 20; j <= LLONG_MAX - 70; j += LLONG_MAX + 50ULL) + { + check (j, 20, 2, 0) + e = 1; + } + #pragma omp for schedule(guided,1) nowait + for (j = ULLONG_MAX - 3; j >= LLONG_MAX + 70ULL; j -= LLONG_MAX + 50ULL) + { + check (j, ULLONG_MAX - 3, 3, 0) + e = 1; + } + #pragma omp for schedule(guided,1) nowait + for (j = LLONG_MAX - 20000ULL; j <= LLONG_MAX + 10000ULL; j += 10000ULL) + { + check (j, LLONG_MAX - 20000ULL, 4, 0) + check (j, LLONG_MAX - 10000ULL, 4, 1) + check (j, LLONG_MAX, 4, 2) + check (j, LLONG_MAX + 10000ULL, 4, 3) + e = 1; + } + #pragma omp for schedule(guided,1) nowait + for (i = -3LL * INT_MAX - 20000LL; i <= INT_MAX + 10000LL; i += INT_MAX + 200LL) + { + check (i, -3LL * INT_MAX - 20000LL, 5, 0) + check (i, -2LL * INT_MAX - 20000LL + 200LL, 5, 1) + check (i, -INT_MAX - 20000LL + 400LL, 5, 2) + check (i, -20000LL + 600LL, 5, 3) + check (i, INT_MAX - 20000LL + 800LL, 5, 4) + e = 1; + } + } + if (e) + abort (); + test (0, 3); + test (1, 3); + test (2, 1); + test (3, 1); + test (4, 4); + test (5, 5); + return 0; +} + +int +test3 () +{ + int e = 0, idx; + +#pragma omp parallel reduction(+:e) + { + long long i; + unsigned long long j; + #pragma omp for schedule(static) nowait + for (i = LLONG_MAX - 30001; i <= LLONG_MAX - 10001; i += 10000) + { + check (i, LLONG_MAX - 30001, 0, 0) + check (i, LLONG_MAX - 20001, 0, 1) + check (i, LLONG_MAX - 10001, 0, 2) + e = 1; + } + #pragma omp for schedule(static) nowait + for (i = -LLONG_MAX + 30000; i >= -LLONG_MAX + 10000; i -= 10000) + { + check (i, -LLONG_MAX + 30000, 1, 0) + check (i, -LLONG_MAX + 20000, 1, 1) + check (i, -LLONG_MAX + 10000, 1, 2) + e = 1; + } + #pragma omp for schedule(static) nowait + for (j = 20; j <= LLONG_MAX - 70; j += LLONG_MAX + 50ULL) + { + check (j, 20, 2, 0) + e = 1; + } + #pragma omp for schedule(static) nowait + for (j = ULLONG_MAX - 3; j >= LLONG_MAX + 70ULL; j -= LLONG_MAX + 50ULL) + { + check (j, ULLONG_MAX - 3, 3, 0) + e = 1; + } + #pragma omp for schedule(static) nowait + for (j = LLONG_MAX - 20000ULL; j <= LLONG_MAX + 10000ULL; j += 10000ULL) + { + check (j, LLONG_MAX - 20000ULL, 4, 0) + check (j, LLONG_MAX - 10000ULL, 4, 1) + check (j, LLONG_MAX, 4, 2) + check (j, LLONG_MAX + 10000ULL, 4, 3) + e = 1; + } + #pragma omp for schedule(static) nowait + for (i = -3LL * INT_MAX - 20000LL; i <= INT_MAX + 10000LL; i += INT_MAX + 200LL) + { + check (i, -3LL * INT_MAX - 20000LL, 5, 0) + check (i, -2LL * INT_MAX - 20000LL + 200LL, 5, 1) + check (i, -INT_MAX - 20000LL + 400LL, 5, 2) + check (i, -20000LL + 600LL, 5, 3) + check (i, INT_MAX - 20000LL + 800LL, 5, 4) + e = 1; + } + } + if (e) + abort (); + test (0, 3); + test (1, 3); + test (2, 1); + test (3, 1); + test (4, 4); + test (5, 5); + return 0; +} + +int +test4 () +{ + int e = 0, idx; + +#pragma omp parallel reduction(+:e) + { + long long i; + unsigned long long j; + #pragma omp for schedule(static,1) nowait + for (i = LLONG_MAX - 30001; i <= LLONG_MAX - 10001; i += 10000) + { + check (i, LLONG_MAX - 30001, 0, 0) + check (i, LLONG_MAX - 20001, 0, 1) + check (i, LLONG_MAX - 10001, 0, 2) + e = 1; + } + #pragma omp for schedule(static,1) nowait + for (i = -LLONG_MAX + 30000; i >= -LLONG_MAX + 10000; i -= 10000) + { + check (i, -LLONG_MAX + 30000, 1, 0) + check (i, -LLONG_MAX + 20000, 1, 1) + check (i, -LLONG_MAX + 10000, 1, 2) + e = 1; + } + #pragma omp for schedule(static,1) nowait + for (j = 20; j <= LLONG_MAX - 70; j += LLONG_MAX + 50ULL) + { + check (j, 20, 2, 0) + e = 1; + } + #pragma omp for schedule(static,1) nowait + for (j = ULLONG_MAX - 3; j >= LLONG_MAX + 70ULL; j -= LLONG_MAX + 50ULL) + { + check (j, ULLONG_MAX - 3, 3, 0) + e = 1; + } + #pragma omp for schedule(static,1) nowait + for (j = LLONG_MAX - 20000ULL; j <= LLONG_MAX + 10000ULL; j += 10000ULL) + { + check (j, LLONG_MAX - 20000ULL, 4, 0) + check (j, LLONG_MAX - 10000ULL, 4, 1) + check (j, LLONG_MAX, 4, 2) + check (j, LLONG_MAX + 10000ULL, 4, 3) + e = 1; + } + #pragma omp for schedule(static,1) nowait + for (i = -3LL * INT_MAX - 20000LL; i <= INT_MAX + 10000LL; i += INT_MAX + 200LL) + { + check (i, -3LL * INT_MAX - 20000LL, 5, 0) + check (i, -2LL * INT_MAX - 20000LL + 200LL, 5, 1) + check (i, -INT_MAX - 20000LL + 400LL, 5, 2) + check (i, -20000LL + 600LL, 5, 3) + check (i, INT_MAX - 20000LL + 800LL, 5, 4) + e = 1; + } + } + if (e) + abort (); + test (0, 3); + test (1, 3); + test (2, 1); + test (3, 1); + test (4, 4); + test (5, 5); + return 0; +} + +int +test5 () +{ + int e = 0, idx; + +#pragma omp parallel reduction(+:e) + { + long long i; + unsigned long long j; + #pragma omp for schedule(runtime) nowait + for (i = LLONG_MAX - 30001; i <= LLONG_MAX - 10001; i += 10000) + { + check (i, LLONG_MAX - 30001, 0, 0) + check (i, LLONG_MAX - 20001, 0, 1) + check (i, LLONG_MAX - 10001, 0, 2) + e = 1; + } + #pragma omp for schedule(runtime) nowait + for (i = -LLONG_MAX + 30000; i >= -LLONG_MAX + 10000; i -= 10000) + { + check (i, -LLONG_MAX + 30000, 1, 0) + check (i, -LLONG_MAX + 20000, 1, 1) + check (i, -LLONG_MAX + 10000, 1, 2) + e = 1; + } + #pragma omp for schedule(runtime) nowait + for (j = 20; j <= LLONG_MAX - 70; j += LLONG_MAX + 50ULL) + { + check (j, 20, 2, 0) + e = 1; + } + #pragma omp for schedule(runtime) nowait + for (j = ULLONG_MAX - 3; j >= LLONG_MAX + 70ULL; j -= LLONG_MAX + 50ULL) + { + check (j, ULLONG_MAX - 3, 3, 0) + e = 1; + } + #pragma omp for schedule(runtime) nowait + for (j = LLONG_MAX - 20000ULL; j <= LLONG_MAX + 10000ULL; j += 10000ULL) + { + check (j, LLONG_MAX - 20000ULL, 4, 0) + check (j, LLONG_MAX - 10000ULL, 4, 1) + check (j, LLONG_MAX, 4, 2) + check (j, LLONG_MAX + 10000ULL, 4, 3) + e = 1; + } + #pragma omp for schedule(runtime) nowait + for (i = -3LL * INT_MAX - 20000LL; i <= INT_MAX + 10000LL; i += INT_MAX + 200LL) + { + check (i, -3LL * INT_MAX - 20000LL, 5, 0) + check (i, -2LL * INT_MAX - 20000LL + 200LL, 5, 1) + check (i, -INT_MAX - 20000LL + 400LL, 5, 2) + check (i, -20000LL + 600LL, 5, 3) + check (i, INT_MAX - 20000LL + 800LL, 5, 4) + e = 1; + } + } + if (e) + abort (); + test (0, 3); + test (1, 3); + test (2, 1); + test (3, 1); + test (4, 4); + test (5, 5); + return 0; +} + +int +main () +{ + if (2 * sizeof (int) != sizeof (long long)) + return 0; + test1 (); + test2 (); + test3 (); + test4 (); + omp_set_schedule (omp_sched_static, 0); + test5 (); + omp_set_schedule (omp_sched_static, 3); + test5 (); + omp_set_schedule (omp_sched_dynamic, 5); + test5 (); + omp_set_schedule (omp_sched_guided, 2); + test5 (); + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/master-1.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/master-1.C new file mode 100644 index 000000000..734b4e2cd --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/master-1.C @@ -0,0 +1,24 @@ +// PR c++/24734 +// { dg-do run } + +extern "C" void abort (); +int i; + +template<int> void +foo () +{ + #pragma omp parallel + { + #pragma omp master + i++; + } +} + +int +main () +{ + foo<0> (); + if (i != 1) + abort (); + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/nested-1.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/nested-1.C new file mode 100644 index 000000000..8d0e397bd --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/nested-1.C @@ -0,0 +1,28 @@ +// { dg-do run } + +extern "C" void abort(void); +#define N 1000 + +int foo() +{ + int i = 0, j; + + #pragma omp parallel for num_threads(2) shared (i) + for (j = 0; j < N; ++j) + { + #pragma omp parallel num_threads(1) shared (i) + { + #pragma omp atomic + i++; + } + } + + return i; +} + +int main() +{ + if (foo() != N) + abort (); + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/parallel-1.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/parallel-1.C new file mode 100644 index 000000000..3c9314713 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/parallel-1.C @@ -0,0 +1,40 @@ +#include <omp.h> + +extern "C" void abort (void); + +int +foo (void) +{ + return 10; +} + +main () +{ + int A = 0; + + #pragma omp parallel if (foo () > 10) shared (A) + { + A = omp_get_num_threads (); + } + + if (A != 1) + abort (); + + #pragma omp parallel if (foo () == 10) num_threads (3) shared (A) + { + A = omp_get_num_threads (); + } + + if (A != 3) + abort (); + + #pragma omp parallel if (foo () == 10) num_threads (foo ()) shared (A) + { + A = omp_get_num_threads (); + } + + if (A != 10) + abort (); + + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/pr24455-1.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/pr24455-1.C new file mode 100644 index 000000000..e7f38f8ab --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/pr24455-1.C @@ -0,0 +1,6 @@ +// { dg-do compile } +// { dg-require-effective-target tls } +extern int i; +#pragma omp threadprivate (i) + +int i; diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/pr24455.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/pr24455.C new file mode 100644 index 000000000..8256b6693 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/pr24455.C @@ -0,0 +1,24 @@ +// { dg-do run } +// { dg-additional-sources pr24455-1.C } +// { dg-require-effective-target tls_runtime } +// { dg-options "-fno-extern-tls-init" } + +extern "C" void abort (void); + +extern int i; +#pragma omp threadprivate(i) + +int main() +{ + i = 0; + +#pragma omp parallel default(none) num_threads(10) copyin(i) + { + i++; +#pragma omp barrier + if (i != 1) + abort (); + } + + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/pr26691.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/pr26691.C new file mode 100644 index 000000000..776b31e24 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/pr26691.C @@ -0,0 +1,20 @@ +// PR c++/26691 + +struct A +{ + int n; + A (int i = 3) : n (i) {} +}; + +int +main () +{ + A a; + int err = 0; +#pragma omp parallel private (a) reduction (+:err) + if (a.n != 3) + err++; + + return err; + } + diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/pr26943.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/pr26943.C new file mode 100644 index 000000000..07b7b5dbf --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/pr26943.C @@ -0,0 +1,62 @@ +// PR c++/26943 +// { dg-do run } + +#include <assert.h> +#include <unistd.h> + +struct S +{ + public: + int x; + S () : x(-1) { } + S (const S &); + S& operator= (const S &); + void test (); +}; + +static volatile int hold; + +S::S (const S &s) +{ + #pragma omp master + sleep (1); + + assert (s.x == -1); + x = 0; +} + +S& +S::operator= (const S& s) +{ + assert (s.x == 1); + x = 2; + return *this; +} + +void +S::test () +{ + assert (x == 0); + x = 1; +} + +static S x; + +void +foo () +{ + #pragma omp sections firstprivate(x) lastprivate(x) + { + x.test(); + } +} + +int +main () +{ + #pragma omp parallel num_threads(2) + foo(); + + assert (x.x == 2); + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/pr27337.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/pr27337.C new file mode 100644 index 000000000..6db2465ec --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/pr27337.C @@ -0,0 +1,87 @@ +// PR middle-end/27337 +// { dg-do run } + +#include <omp.h> + +extern "C" void abort (void); + +struct S +{ + S (); + ~S (); + S (const S &); + int i; +}; + +int n[3]; + +S::S () : i(18) +{ + if (omp_get_thread_num () != 0) +#pragma omp atomic + n[0]++; +} + +S::~S () +{ + if (omp_get_thread_num () != 0) +#pragma omp atomic + n[1]++; +} + +S::S (const S &x) +{ + if (x.i != 18) + abort (); + i = 118; + if (omp_get_thread_num () != 0) +#pragma omp atomic + n[2]++; +} + +S +foo () +{ + int i; + S ret; + +#pragma omp parallel for firstprivate (ret) lastprivate (ret) \ + schedule (static, 1) num_threads (4) + for (i = 0; i < 4; i++) + ret.i += omp_get_thread_num (); + + return ret; +} + +S +bar () +{ + int i; + S ret; + +#pragma omp parallel for num_threads (4) + for (i = 0; i < 4; i++) +#pragma omp atomic + ret.i += omp_get_thread_num () + 1; + + return ret; +} + +S x; + +int +main (void) +{ + omp_set_dynamic (false); + x = foo (); + if (n[0] != 0 || n[1] != 3 || n[2] != 3) + abort (); + if (x.i != 118 + 3) + abort (); + x = bar (); + if (n[0] != 0 || n[1] != 3 || n[2] != 3) + abort (); + if (x.i != 18 + 0 + 1 + 2 + 3 + 4) + abort (); + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/pr30703.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/pr30703.C new file mode 100644 index 000000000..d48efd952 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/pr30703.C @@ -0,0 +1,73 @@ +// PR c++/30703 +// { dg-do run } + +#include <omp.h> + +extern "C" void abort (); + +int ctor, cctor, dtor; + +struct A +{ + A(); + A(const A &); + ~A(); + int i; +}; + +A::A() +{ +#pragma omp atomic + ctor++; +} + +A::A(const A &r) +{ + i = r.i; +#pragma omp atomic + cctor++; +} + +A::~A() +{ +#pragma omp atomic + dtor++; +} + +void +foo (A a, A b) +{ + int i, j = 0; +#pragma omp parallel for firstprivate (a) lastprivate (a) private (b) schedule (static, 1) num_threads (5) + for (i = 0; i < 5; i++) + { + b.i = 5; + if (a.i != 6) + #pragma omp atomic + j += 1; + a.i = b.i + i + 6; + } + + if (j || a.i != 15) + abort (); +} + +void +bar () +{ + A a, b; + a.i = 6; + b.i = 7; + foo (a, b); +} + +int +main () +{ + omp_set_dynamic (false); + if (ctor || cctor || dtor) + abort (); + bar (); + if (ctor + cctor != dtor) + abort (); +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/pr34513.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/pr34513.C new file mode 100644 index 000000000..e5ad3bcb4 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/pr34513.C @@ -0,0 +1,32 @@ +// PR c++/34513 +// { dg-do run } + +#include <omp.h> + +extern "C" void abort (); + +static int errors = 0; +static int thrs = 4; + +int +main () +{ + omp_set_dynamic (0); + + #pragma omp parallel num_threads (thrs) + { + static int shrd = 0; + + #pragma omp atomic + shrd += 1; + + #pragma omp barrier + + if (shrd != thrs) + #pragma omp atomic + errors += 1; + } + + if (errors) + abort (); +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/pr35185.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/pr35185.C new file mode 100644 index 000000000..f22c77207 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/pr35185.C @@ -0,0 +1,33 @@ +// PR middle-end/35185 +// { dg-do run } + +extern "C" void abort (); + +struct S +{ + S () : s (6) {} + ~S () {} + int s; +}; + +__attribute__((noinline)) +bool +bar (S s) +{ + return s.s != 6; +} + +int +main () +{ + S s; + int err = 0; +#pragma omp parallel shared (s) + { + if (bar (s)) + #pragma omp atomic + err++; + } + if (err) + abort (); +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/pr38650.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/pr38650.C new file mode 100644 index 000000000..ebe221adc --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/pr38650.C @@ -0,0 +1,49 @@ +// PR c++/38650 +// { dg-do run } + +#include <cstdlib> + +int e; + +int +main () +{ + volatile int i, j = 10; + e = 0; +#pragma omp parallel for reduction(+:e) + for (i = 0; i < j; i += 1) + e++; + if (e != 10) + std::abort (); + e = 0; +#pragma omp parallel for reduction(+:e) + for (i = 0; i < j; ++i) + e++; + if (e != 10) + std::abort (); + e = 0; +#pragma omp parallel for reduction(+:e) + for (i = 0; i < j; i++) + e++; + if (e != 10) + std::abort (); + e = 0; +#pragma omp parallel for reduction(+:e) + for (i = 0; i < 10; i += 1) + e++; + if (e != 10) + std::abort (); + e = 0; +#pragma omp parallel for reduction(+:e) + for (i = 0; i < 10; ++i) + e++; + if (e != 10) + std::abort (); + e = 0; +#pragma omp parallel for reduction(+:e) + for (i = 0; i < 10; i++) + e++; + if (e != 10) + std::abort (); + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/pr39573.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/pr39573.C new file mode 100644 index 000000000..0167222bc --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/pr39573.C @@ -0,0 +1,39 @@ +// PR middle-end/39573 +// { dg-do run } + +int z; + +void __attribute__((noinline)) +bar (int *x) +{ + #pragma omp atomic + z += x[2]; + x[2] += x[3]; +} + +int +main () +{ + int i; +#pragma omp parallel for + for (i = 0; i < 65536; i++) + { + int x[] = + { + 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, + 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, + 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, + 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, + 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, + 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, + 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, + 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, + 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, + 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, + 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, + 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, + 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, + }; + bar (x); + } +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/pr43893.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/pr43893.C new file mode 100644 index 000000000..be0b6f4ab --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/pr43893.C @@ -0,0 +1,125 @@ +// PR c/43893 +// { dg-do run } + +extern "C" void abort (); + +template <typename T, T M, T N> +void +f1 () +{ + int c; + T i; + c = 0; +#pragma omp parallel for reduction(+:c) + for (i = M; i < N; i++) + c++; + if (c != 1) + abort (); +} + +template <typename T, T M, T N> +void +f2 () +{ + int c; + T i; + c = 0; +#pragma omp parallel for reduction(+:c) + for (i = M; i <= N; i++) + c++; + if (c != 1) + abort (); +} + +template <typename T, T M, T N> +void +f3 () +{ + int c; + T i; + c = 0; +#pragma omp parallel for reduction(+:c) + for (i = M; i > N; i--) + c++; + if (c != 1) + abort (); +} + +template <typename T, T M, T N> +void +f4 () +{ + int c; + T i; + c = 0; +#pragma omp parallel for reduction(+:c) + for (i = M; i >= N; i--) + c++; + if (c != 1) + abort (); +} + +int +main () +{ + int c; + unsigned int i; + int j; + c = 0; +#pragma omp parallel for reduction(+:c) + for (i = 0; i < 1; i++) + c++; + if (c != 1) + abort (); + f1 <unsigned int, 0, 1> (); + c = 0; +#pragma omp parallel for reduction(+:c) + for (i = 0; i <= 0; i++) + c++; + if (c != 1) + abort (); + f2 <unsigned int, 0, 0> (); + c = 0; +#pragma omp parallel for reduction(+:c) + for (j = - __INT_MAX__ - 1; j < - __INT_MAX__; j++) + c++; + if (c != 1) + abort (); + f1 <int, (- __INT_MAX__ - 1), (- __INT_MAX__)> (); + c = 0; +#pragma omp parallel for reduction(+:c) + for (j = - __INT_MAX__ - 1; j <= - __INT_MAX__ - 1; j++) + c++; + if (c != 1) + abort (); + f2 <int, (- __INT_MAX__ - 1), (- __INT_MAX__ - 1)> (); + c = 0; +#pragma omp parallel for reduction(+:c) + for (i = 2U * __INT_MAX__ + 1; i > 2U * __INT_MAX__; i--) + c++; + if (c != 1) + abort (); + f3 <unsigned int, (2U * __INT_MAX__ + 1), (2U * __INT_MAX__)> (); + c = 0; +#pragma omp parallel for reduction(+:c) + for (i = 2U * __INT_MAX__ + 1; i >= 2U * __INT_MAX__ + 1; i--) + c++; + if (c != 1) + abort (); + f4 <unsigned int, (2U * __INT_MAX__ + 1), (2U * __INT_MAX__ + 1)> (); + c = 0; +#pragma omp parallel for reduction(+:c) + for (j = __INT_MAX__; j > __INT_MAX__ - 1; j--) + c++; + if (c != 1) + abort (); + f3 <int, __INT_MAX__, (__INT_MAX__ - 1)> (); + c = 0; +#pragma omp parallel for reduction(+:c) + for (j = __INT_MAX__; j >= __INT_MAX__; j--) + c++; + if (c != 1) + abort (); + f4 <int, __INT_MAX__, __INT_MAX__> (); + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/pr48869.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/pr48869.C new file mode 100644 index 000000000..ec952d9b7 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/pr48869.C @@ -0,0 +1,68 @@ +// PR c++/48869 +// { dg-do run } +// { dg-options "-std=gnu++0x" } + +template <const int N> +struct A +{ + A () {} + A (const A&) = delete; + void foo () {} + ~A () {} +}; + +template <const int N> +struct B +{ + B () {} + B (const B&) {} + void foo () {} + ~B () {} +}; + +void __attribute__((used)) +foo (B<6> b6) +{ + #pragma omp task + b6.foo (); +} + +int +main () +{ + A<0> a0; + #pragma omp task shared(a0) + a0.foo (); + #pragma omp task default(shared) + a0.foo (); + #pragma omp parallel shared(a0) + #pragma omp task + a0.foo (); + #pragma omp task + { + A<1> a1; + a1.foo (); + } + B<0> b0; + #pragma omp task shared(b0) + b0.foo (); + B<1> b1; + #pragma omp task default(shared) + b1.foo (); + B<2> b2; + #pragma omp parallel shared(b2) + #pragma omp task + b2.foo (); + B<3> b3; + #pragma omp task + b3.foo (); + B<4> b4; + #pragma omp parallel private (b4) + #pragma omp task + b4.foo (); + B<5> b5; + #pragma omp parallel firstprivate (b5) + #pragma omp task + b5.foo (); + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/pr49043.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/pr49043.C new file mode 100644 index 000000000..604cfc30d --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/pr49043.C @@ -0,0 +1,19 @@ +// PR c++/49043 +// { dg-options "-std=c++0x" } +// { dg-do run } + +extern "C" void abort (); + +int +main () +{ + int r = 0; + #pragma omp parallel for reduction (+:r) + for (int a = 0; a < 10; ++a) + { + auto func = [=] () { return a; }; + r += func (); + } + if (r != 45) + abort (); +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/pr56217.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/pr56217.C new file mode 100644 index 000000000..19da91853 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/pr56217.C @@ -0,0 +1,36 @@ +// PR middle-end/56217 +// { dg-do run } +// { dg-options "-std=c++0x" } + +extern "C" void abort (); + +template <typename T> +struct ptr { + T *p; + ptr () : p () {} + ptr (ptr &) = delete; + ptr (ptr &&o) : p(o) {} + operator T * () { return p; } +}; + +int a[6] = { 100, 101, 102, 103, 104, 105 }; + +static ptr<int> +f () +{ + ptr<int> pt; + #pragma omp task shared (pt) + pt.p = a + 2; + #pragma omp taskwait + return pt; +} + +int +main () +{ + ptr<int> pt; + #pragma omp parallel + #pragma omp single + if (f () != a + 2 || *f () != 102) + abort (); +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/reduction-1.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/reduction-1.C new file mode 100644 index 000000000..665163af0 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/reduction-1.C @@ -0,0 +1,36 @@ +#include <omp.h> +#include <stdlib.h> + +int +main (void) +{ + int i = 0, j = 0, k = ~0; + double d = 1.0; +#pragma omp parallel num_threads(4) reduction(+:i) reduction(*:d) reduction(&:k) + { + if (i != 0 || d != 1.0 || k != ~0) +#pragma omp atomic + j |= 1; + + if (omp_get_num_threads () != 4) +#pragma omp atomic + j |= 2; + + i = omp_get_thread_num (); + d = i + 1; + k = ~(1 << (2 * i)); + } + + if (j & 1) + abort (); + if ((j & 2) == 0) + { + if (i != (0 + 1 + 2 + 3)) + abort (); + if (d != (1.0 * 2.0 * 3.0 * 4.0)) + abort (); + if (k != (~0 ^ 0x55)) + abort (); + } + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/reduction-2.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/reduction-2.C new file mode 100644 index 000000000..52b3faff7 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/reduction-2.C @@ -0,0 +1,50 @@ +#include <omp.h> +#include <stdlib.h> + +int +main (void) +{ + int i = 0, j = 0, k = ~0, l; + double d = 1.0; +#pragma omp parallel num_threads(4) + { +#pragma omp single + { + i = 16; + k ^= (1 << 16); + d += 32.0; + } + +#pragma omp for reduction(+:i) reduction(*:d) reduction(&:k) + for (l = 0; l < 4; l++) + { + if (omp_get_num_threads () == 4 && (i != 0 || d != 1.0 || k != ~0)) +#pragma omp atomic + j |= 1; + + if (l == omp_get_thread_num ()) + { + i = omp_get_thread_num (); + d = i + 1; + k = ~(1 << (2 * i)); + } + } + + if (omp_get_num_threads () == 4) + { + if (i != (16 + 0 + 1 + 2 + 3)) +#pragma omp atomic + j |= 2; + if (d != (33.0 * 1.0 * 2.0 * 3.0 * 4.0)) +#pragma omp atomic + j |= 4; + if (k != (~0 ^ 0x55 ^ (1 << 16))) +#pragma omp atomic + j |= 8; + } + } + + if (j) + abort (); + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/reduction-3.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/reduction-3.C new file mode 100644 index 000000000..4f8f2fc12 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/reduction-3.C @@ -0,0 +1,51 @@ +#include <omp.h> +#include <stdlib.h> + +int +main (void) +{ + int i = 0, j = 0, k = ~0, l; + double d = 1.0; +#pragma omp parallel num_threads(4) + { +#pragma omp single + { + i = 16; + k ^= (1 << 16); + d += 32.0; + } + +#pragma omp for reduction(+:i) reduction(*:d) reduction(&:k) nowait + for (l = 0; l < 4; l++) + { + if (omp_get_num_threads () == 4 && (i != 0 || d != 1.0 || k != ~0)) +#pragma omp atomic + j |= 1; + + if (l == omp_get_thread_num ()) + { + i = omp_get_thread_num (); + d = i + 1; + k = ~(1 << (2 * i)); + } + } + + if (omp_get_num_threads () == 4) + { +#pragma omp barrier + if (i != (16 + 0 + 1 + 2 + 3)) +#pragma omp atomic + j |= 2; + if (d != (33.0 * 1.0 * 2.0 * 3.0 * 4.0)) +#pragma omp atomic + j |= 4; + if (k != (~0 ^ 0x55 ^ (1 << 16))) +#pragma omp atomic + j |= 8; + } + } + + if (j) + abort (); + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/reduction-4.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/reduction-4.C new file mode 100644 index 000000000..e7ef8a13c --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/reduction-4.C @@ -0,0 +1,54 @@ +// { dg-do run } + +extern "C" void abort (void); + +template <typename I, typename F> +void +foo () +{ + I j = -10000; + F f = 1024.0; + int i; + #pragma omp parallel for reduction (min:f) reduction (max:j) + for (i = 0; i < 4; i++) + switch (i) + { + case 0: + if (j < -16) j = -16; break; + case 1: + if (f > -2.0) f = -2.0; break; + case 2: + if (j < 8) j = 8; if (f > 9.0) f = 9.0; break; + case 3: + break; + } + if (j != 8 || f != -2.0) + abort (); +} + +int +main () +{ + int j = -10000; + float f = 1024.0; + int i; + #pragma omp parallel for reduction (min:f) reduction (max:j) + for (i = 0; i < 4; i++) + switch (i) + { + case 0: + if (j < -16) j = -16; break; + case 1: + if (f > -2.0) f = -2.0; break; + case 2: + if (j < 8) j = 8; if (f > 9.0) f = 9.0; break; + case 3: + break; + } + if (j != 8 || f != -2.0) + abort (); + foo <int, float> (); + foo <long, double> (); + foo <long long, long double> (); + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/sections-1.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/sections-1.C new file mode 100644 index 000000000..32c93dbde --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/sections-1.C @@ -0,0 +1,64 @@ +/****************************************************************************** +* FILE: omp_workshare2.c +* DESCRIPTION: +* OpenMP Example - Sections Work-sharing - C/C++ Version +* In this example, the OpenMP SECTION directive is used to assign +* different array operations to threads that execute a SECTION. Each +* thread receives its own copy of the result array to work with. +* AUTHOR: Blaise Barney 5/99 +* LAST REVISED: 04/06/05 +******************************************************************************/ +#include <omp.h> +#include <stdio.h> +#include <stdlib.h> +#define N 50 + +int main (int argc, char *argv[]) { + +int i, nthreads, tid; +float a[N], b[N], c[N]; + +/* Some initializations */ +for (i=0; i<N; i++) + a[i] = b[i] = i * 1.0; + +#pragma omp parallel shared(a,b,nthreads) private(c,i,tid) + { + tid = omp_get_thread_num(); + if (tid == 0) + { + nthreads = omp_get_num_threads(); + printf("Number of threads = %d\n", nthreads); + } + printf("Thread %d starting...\n",tid); + + #pragma omp sections nowait + { + #pragma omp section + { + printf("Thread %d doing section 1\n",tid); + for (i=0; i<N; i++) + { + c[i] = a[i] + b[i]; + printf("Thread %d: c[%d]= %f\n",tid,i,c[i]); + } + } + + #pragma omp section + { + printf("Thread %d doing section 2\n",tid); + for (i=0; i<N; i++) + { + c[i] = a[i] * b[i]; + printf("Thread %d: c[%d]= %f\n",tid,i,c[i]); + } + } + + } /* end of sections */ + + printf("Thread %d done.\n",tid); + + } /* end of parallel section */ + + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/shared-1.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/shared-1.C new file mode 100644 index 000000000..334a553ce --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/shared-1.C @@ -0,0 +1,60 @@ +#include <omp.h> + +extern "C" void abort (void); + +struct Y +{ + int l[5][10]; +}; + +struct X +{ + struct Y y; + float b[10]; +}; + +void +parallel (int a, int b) +{ + int i, j; + struct X A[10][5]; + a = b = 3; + + for (i = 0; i < 10; i++) + for (j = 0; j < 5; j++) + A[i][j].y.l[3][3] = -10; + + #pragma omp parallel shared (a, b, A) num_threads (5) + { + int i, j; + + #pragma omp atomic + a += omp_get_num_threads (); + + #pragma omp atomic + b += omp_get_num_threads (); + + #pragma omp for private (j) + for (i = 0; i < 10; i++) + for (j = 0; j < 5; j++) + A[i][j].y.l[3][3] += 20; + + } + + for (i = 0; i < 10; i++) + for (j = 0; j < 5; j++) + if (A[i][j].y.l[3][3] != 10) + abort (); + + if (a != 28) + abort (); + + if (b != 28) + abort (); +} + +main() +{ + parallel (1, 2); + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/shared-2.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/shared-2.C new file mode 100644 index 000000000..01855fbd4 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/shared-2.C @@ -0,0 +1,47 @@ +extern "C" void abort (void); + +void +parallel (int a, int b) +{ + int bad, LASTPRIV, LASTPRIV_SEC; + int i; + + a = b = 3; + + bad = 0; + + #pragma omp parallel firstprivate (a,b) shared (bad) num_threads (5) + { + if (a != 3 || b != 3) + bad = 1; + + #pragma omp for lastprivate (LASTPRIV) + for (i = 0; i < 10; i++) + LASTPRIV = i; + + #pragma omp sections lastprivate (LASTPRIV_SEC) + { + #pragma omp section + { LASTPRIV_SEC = 3; } + + #pragma omp section + { LASTPRIV_SEC = 42; } + } + + } + + if (LASTPRIV != 9) + abort (); + + if (LASTPRIV_SEC != 42) + abort (); + + if (bad) + abort (); +} + +int main() +{ + parallel (1, 2); + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/simd-1.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/simd-1.C new file mode 100644 index 000000000..16ef159b8 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/simd-1.C @@ -0,0 +1,79 @@ +// { dg-do run } +// { dg-options "-O2" } +// { dg-additional-options "-msse2" { target sse2_runtime } } +// { dg-additional-options "-mavx" { target avx_runtime } } + +extern "C" void abort (); +int a[1024] __attribute__((aligned (32))) = { 1 }; +int b[1024] __attribute__((aligned (32))) = { 1 }; +int k, m; +struct U { U (); ~U (); int u; }; +struct V +{ + V () : v (8) {} + ~V () + { + if (v > 38 + 4 + 3 * 1024 + 1) + abort (); + } + V &operator= (const V &x) { v = x.v + 1; return *this; } + int v; +}; + +__attribute__((noinline, noclone)) +U::U () : u (6) +{ +} + +__attribute__((noinline, noclone)) +U::~U () +{ + if (u > 38 + 4 + 3 * 1023) + abort (); +} + +__attribute__((noinline, noclone)) int +foo (int *p) +{ + int i, s = 0; + U u; + V v; + #pragma omp simd aligned(a, p : 32) linear(k: m + 1) \ + reduction(+:s) lastprivate(u, v) + for (i = 0; i < 1024; i++) + { + a[i] *= p[i]; + u.u = p[i] + k; + k += m + 1; + v.v = p[i] + k; + s += p[i] + k; + } + if (u.u != 36 + 4 + 3 * 1023 || v.v != 36 + 4 + 3 * 1024 + 1) + abort (); + return s; +} + +int +main () +{ +#if __SIZEOF_INT__ >= 4 + int i; + k = 4; + m = 2; + for (i = 0; i < 1024; i++) + { + a[i] = i - 512; + b[i] = (i - 51) % 39; + } + int s = foo (b); + for (i = 0; i < 1024; i++) + { + if (b[i] != (i - 51) % 39 + || a[i] != (i - 512) * b[i]) + abort (); + } + if (k != 4 + 3 * 1024 || s != 1596127) + abort (); +#endif + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/simd-2.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/simd-2.C new file mode 100644 index 000000000..6b12415bd --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/simd-2.C @@ -0,0 +1,36 @@ +// { dg-do run } +// { dg-options "-O2" } +// { dg-additional-options "-msse2" { target sse2_runtime } } +// { dg-additional-options "-mavx" { target avx_runtime } } + +extern "C" void abort (); +__UINTPTR_TYPE__ arr[1027]; + +__attribute__((noinline, noclone)) void +foo () +{ + int i, v; + #pragma omp simd private (v) safelen(16) + for (i = 0; i < 1027; i++) + arr[i] = (__UINTPTR_TYPE__) &v; +} + +int +main () +{ + int i, j, cnt = 0; + __UINTPTR_TYPE__ arr2[16]; + foo (); + for (i = 0; i < 1027; i++) + { + for (j = 0; j < cnt; j++) + if (arr[i] == arr2[j]) + break; + if (j != cnt) + continue; + if (cnt == 16) + abort (); + arr2[cnt++] = arr[i]; + } + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/simd-3.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/simd-3.C new file mode 100644 index 000000000..1c6d8e01a --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/simd-3.C @@ -0,0 +1,131 @@ +// { dg-do run } +// { dg-options "-O2" } +// { dg-additional-options "-msse2" { target sse2_runtime } } +// { dg-additional-options "-mavx" { target avx_runtime } } + +extern "C" void abort (); +int a[1024] __attribute__((aligned (32))) = { 1 }; +int b[1024] __attribute__((aligned (32))) = { 1 }; +unsigned char c[1024] __attribute__((aligned (32))) = { 1 }; +int k, m; +__UINTPTR_TYPE__ u, u2, u3; + +__attribute__((noinline, noclone)) int +foo (int *p) +{ + int i, s = 0, s2 = 0, t, t2; + #pragma omp simd aligned(a, b, p : 32) linear(k: m + 1) reduction(+:s) \ + lastprivate (t2) + for (i = 0; i < 512; i++) + { + a[i] *= p[i]; + t2 = k + p[i]; + k += m + 1; + s += p[i] + k; + c[i]++; + } + #pragma omp simd aligned(a, b, p : 32) linear(k: m + 1) reduction(+:s2) \ + lastprivate (t, u, u2, u3) + for (i = 512; i < 1024; i++) + { + a[i] *= p[i]; + k += m + 1; + t = k + p[i]; + u = (__UINTPTR_TYPE__) &k; + u2 = (__UINTPTR_TYPE__) &s2; + u3 = (__UINTPTR_TYPE__) &t; + s2 += t; + c[i]++; + } + return s + s2 + t + t2; +} + +__attribute__((noinline, noclone)) long int +bar (int *p, long int n, long int o) +{ + long int i, s = 0, s2 = 0, t, t2; + #pragma omp simd aligned(a, b, p : 32) linear(k: m + 1) reduction(+:s) \ + lastprivate (t2) + for (i = 0; i < n; i++) + { + a[i] *= p[i]; + t2 = k + p[i]; + k += m + 1; + s += p[i] + k; + c[i]++; + } + #pragma omp simd aligned(a, b, p : 32) linear(k: m + 1) reduction(+:s2) \ + lastprivate (t, u, u2, u3) + for (i = n; i < o; i++) + { + a[i] *= p[i]; + k += m + 1; + t = k + p[i]; + u = (__UINTPTR_TYPE__) &k; + u2 = (__UINTPTR_TYPE__) &s2; + u3 = (__UINTPTR_TYPE__) &t; + s2 += t; + c[i]++; + } + return s + s2 + t + t2; +} + +int +main () +{ +#if __SIZEOF_INT__ >= 4 + int i; + k = 4; + m = 2; + for (i = 0; i < 1024; i++) + { + a[i] = i - 512; + b[i] = (i - 51) % 39; + c[i] = (unsigned char) i; + } + int s = foo (b); + for (i = 0; i < 1024; i++) + { + if (b[i] != (i - 51) % 39 + || a[i] != (i - 512) * b[i] + || c[i] != (unsigned char) (i + 1)) + abort (); + a[i] = i - 512; + } + if (k != 4 + 3 * 1024 + || s != 1596127 + (4 + 3 * 511 + b[511]) + (4 + 3 * 1024 + b[1023])) + abort (); + k = 4; + s = bar (b, 512, 1024); + for (i = 0; i < 1024; i++) + { + if (b[i] != (i - 51) % 39 + || a[i] != (i - 512) * b[i] + || c[i] != (unsigned char) (i + 2)) + abort (); + a[i] = i - 512; + } + if (k != 4 + 3 * 1024 + || s != 1596127 + (4 + 3 * 511 + b[511]) + (4 + 3 * 1024 + b[1023])) + abort (); + k = 4; + s = bar (b, 511, 1021); + for (i = 0; i < 1021; i++) + { + if (b[i] != (i - 51) % 39 + || a[i] != (i - 512) * b[i] + || c[i] != (unsigned char) (i + 3)) + abort (); + a[i] = i - 512; + } + for (i = 1021; i < 1024; i++) + if (b[i] != (i - 51) % 39 + || a[i] != i - 512 + || c[i] != (unsigned char) (i + 2)) + abort (); + if (k != 4 + 3 * 1021 + || s != 1586803 + (4 + 3 * 510 + b[510]) + (4 + 3 * 1021 + b[1020])) + abort (); +#endif + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/simd-4.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/simd-4.C new file mode 100644 index 000000000..bdfacc652 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/simd-4.C @@ -0,0 +1,45 @@ +// { dg-do run } +// { dg-options "-O2" } +// { dg-additional-options "-msse2" { target sse2_runtime } } +// { dg-additional-options "-mavx" { target avx_runtime } } + +extern "C" void abort (); +int a[1024] __attribute__((aligned (32))) = { 1 }; +struct S +{ + int s; + S () : s (0) {} + ~S () {} +}; +#pragma omp declare reduction (+:S:omp_out.s += omp_in.s) +#pragma omp declare reduction (foo:S:omp_out.s += omp_in.s) +#pragma omp declare reduction (foo:int:omp_out += omp_in) + +__attribute__((noinline, noclone)) int +foo () +{ + int i, u = 0; + S s, t; + #pragma omp simd aligned(a : 32) reduction(+:s) reduction(foo:t, u) + for (i = 0; i < 1024; i++) + { + int x = a[i]; + s.s += x; + t.s += x; + u += x; + } + if (t.s != s.s || u != s.s) + abort (); + return s.s; +} + +int +main () +{ + int i; + for (i = 0; i < 1024; i++) + a[i] = (i & 31) + (i / 128); + int s = foo (); + if (s != 19456) + abort (); +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/simd-5.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/simd-5.C new file mode 100644 index 000000000..6c4627e21 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/simd-5.C @@ -0,0 +1,47 @@ +// { dg-do run } +// { dg-options "-O2" } +// { dg-additional-options "-msse2" { target sse2_runtime } } +// { dg-additional-options "-mavx" { target avx_runtime } } + +extern "C" void abort (); +int a[1024] __attribute__((aligned (32))) = { 1 }; +struct S +{ + int s; + S () : s (0) {} + ~S () {} +}; +#pragma omp declare reduction (+:S:omp_out.s += omp_in.s) +#pragma omp declare reduction (foo:S:omp_out.s += omp_in.s) +#pragma omp declare reduction (foo:int:omp_out += omp_in) + +__attribute__((noinline, noclone)) int +foo () +{ + int i, u = 0, q = 0; + S s, t; + #pragma omp simd aligned(a : 32) reduction(+:s, q) reduction(foo:t, u) \ + safelen(1) + for (i = 0; i < 1024; i++) + { + int x = a[i]; + s.s += x; + t.s += x; + u += x; + q++; + } + if (t.s != s.s || u != s.s || q != 1024) + abort (); + return s.s; +} + +int +main () +{ + int i; + for (i = 0; i < 1024; i++) + a[i] = (i & 31) + (i / 128); + int s = foo (); + if (s != 19456) + abort (); +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/simd-6.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/simd-6.C new file mode 100644 index 000000000..cfc13d0a0 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/simd-6.C @@ -0,0 +1,70 @@ +// { dg-do run } +// { dg-options "-O2" } +// { dg-additional-options "-msse2" { target sse2_runtime } } +// { dg-additional-options "-mavx" { target avx_runtime } } + +extern "C" void abort (); +int a[1024] __attribute__((aligned (32))) = { 1 }; +struct S +{ + int s; + S () : s (0) {} + S (int x) : s (x) {} + ~S () {} +}; +#pragma omp declare reduction (+:S:omp_out.s += omp_in.s) \ + initializer (omp_priv (0)) +#pragma omp declare reduction (foo:S:omp_out.s += omp_in.s) \ + initializer (omp_priv (0)) +#pragma omp declare reduction (foo:int:omp_out += omp_in) \ + initializer (omp_priv = 0) + +__attribute__((noinline, noclone)) S +foo (S s) +{ + int i, v = 0, &u = v; + S t; + #pragma omp simd aligned(a : 32) reduction(+:s) reduction(foo:t, u) + for (i = 0; i < 1024; i++) + { + int x = a[i]; + s.s += x; + t.s += x; + u += x; + } + if (t.s != s.s || u != s.s) + abort (); + return t; +} + +__attribute__((noinline, noclone)) int +bar (S &s, S &t) +{ + int i, v = 0, &u = v; + #pragma omp simd aligned(a : 32) reduction(+:s) reduction(foo:t, u) + for (i = 0; i < 1024; i++) + { + int x = a[i]; + s.s += x; + t.s += x; + u += x; + } + if (t.s != s.s || u != s.s) + abort (); + return s.s; +} + +int +main () +{ + int i; + for (i = 0; i < 1024; i++) + a[i] = (i & 31) + (i / 128); + S q; + int s = foo (q).s; + if (s != 19456) + abort (); + S r, v; + if (bar (r, v) != s) + abort (); +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/simd-7.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/simd-7.C new file mode 100644 index 000000000..5a6f4cef7 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/simd-7.C @@ -0,0 +1,72 @@ +// { dg-do run } +// { dg-options "-O2" } +// { dg-additional-options "-msse2" { target sse2_runtime } } +// { dg-additional-options "-mavx" { target avx_runtime } } + +extern "C" void abort (); +int a[1024] __attribute__((aligned (32))) = { 1 }; +struct S +{ + int s; + S () : s (0) {} + S (int x) : s (x) {} + ~S () {} +}; +#pragma omp declare reduction (+:S:omp_out.s += omp_in.s) \ + initializer (omp_priv (0)) +#pragma omp declare reduction (foo:S:omp_out.s += omp_in.s) \ + initializer (omp_priv (0)) +#pragma omp declare reduction (foo:int:omp_out += omp_in) \ + initializer (omp_priv = 0) + +__attribute__((noinline, noclone)) S +foo (S s) +{ + int i, v = 0, &u = v; + S t; + #pragma omp simd aligned(a : 32) reduction(+:s) reduction(foo:t, u) \ + safelen(1) + for (i = 0; i < 1024; i++) + { + int x = a[i]; + s.s += x; + t.s += x; + u += x; + } + if (t.s != s.s || u != s.s) + abort (); + return t; +} + +__attribute__((noinline, noclone)) int +bar (S &s, S &t) +{ + int i, v = 0, &u = v; + #pragma omp simd aligned(a : 32) reduction(+:s) reduction(foo:t, u) \ + safelen(1) + for (i = 0; i < 1024; i++) + { + int x = a[i]; + s.s += x; + t.s += x; + u += x; + } + if (t.s != s.s || u != s.s) + abort (); + return s.s; +} + +int +main () +{ + int i; + for (i = 0; i < 1024; i++) + a[i] = (i & 31) + (i / 128); + S q; + int s = foo (q).s; + if (s != 19456) + abort (); + S r, v; + if (bar (r, v) != s) + abort (); +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/simd-8.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/simd-8.C new file mode 100644 index 000000000..7c7583285 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/simd-8.C @@ -0,0 +1,47 @@ +// PR libgomp/58482 +// { dg-do run } +// { dg-options "-O2" } +// { dg-additional-options "-msse2" { target sse2_runtime } } +// { dg-additional-options "-mavx" { target avx_runtime } } + +extern "C" void abort (); +int a[1024] __attribute__((aligned (32))) = { 1 }; +struct S +{ + int s; + S () : s (0) {} + ~S () {} +}; +#pragma omp declare reduction (+:S:omp_out.s += omp_in.s) +#pragma omp declare reduction (foo:S:omp_out.s += omp_in.s) +#pragma omp declare reduction (foo:int:omp_out += omp_in) + +__attribute__((noinline, noclone)) int +foo () +{ + int i, u = 0; + S s, t; + #pragma omp parallel for simd aligned(a : 32) reduction(+:s) \ + reduction(foo:t, u) + for (i = 0; i < 1024; i++) + { + int x = a[i]; + s.s += x; + t.s += x; + u += x; + } + if (t.s != s.s || u != s.s) + abort (); + return s.s; +} + +int +main () +{ + int i; + for (i = 0; i < 1024; i++) + a[i] = (i & 31) + (i / 128); + int s = foo (); + if (s != 19456) + abort (); +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/single-1.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/single-1.C new file mode 100644 index 000000000..e318a48ca --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/single-1.C @@ -0,0 +1,19 @@ +extern "C" void abort (void); + +main() +{ + int i = 0; + + #pragma omp parallel shared (i) + { + #pragma omp single + { + i++; + } + } + + if (i != 1) + abort (); + + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/single-2.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/single-2.C new file mode 100644 index 000000000..c2dd22856 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/single-2.C @@ -0,0 +1,36 @@ +extern "C" void abort (void); + +struct X +{ + int a; + char b; + int c; +}; + +main() +{ + int i = 0; + struct X x; + int bad = 0; + + #pragma omp parallel private (i, x) shared (bad) + { + i = 5; + + #pragma omp single copyprivate (i, x) + { + i++; + x.a = 23; + x.b = 42; + x.c = 26; + } + + if (i != 6 || x.a != 23 || x.b != 42 || x.c != 26) + bad = 1; + } + + if (bad) + abort (); + + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/single-3.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/single-3.C new file mode 100644 index 000000000..abc7f44b3 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/single-3.C @@ -0,0 +1,21 @@ +extern "C" void abort (void); + +void +single (int a, int b) +{ + #pragma omp single copyprivate(a) copyprivate(b) + { + a = b = 5; + } + + if (a != b) + abort (); +} + +int main() +{ + #pragma omp parallel + single (1, 2); + + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/target-1.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/target-1.C new file mode 100644 index 000000000..3cf01d997 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/target-1.C @@ -0,0 +1 @@ +#include "../libgomp.c/target-1.c" diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/target-2-aux.cc b/gcc-4.9/libgomp/testsuite/libgomp.c++/target-2-aux.cc new file mode 100644 index 000000000..b405404e6 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/target-2-aux.cc @@ -0,0 +1,5 @@ +double f[1024]; +double (&fr) [1024] = f; +double gbuf[1024]; +double *g = gbuf; +double *&gr = g; diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/target-2.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/target-2.C new file mode 100644 index 000000000..83207cd51 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/target-2.C @@ -0,0 +1,58 @@ +// { dg-options "-O2 -fopenmp" } +// { dg-additional-sources "target-2-aux.cc" } + +extern "C" void abort (void); + +void +fn1 (double *x, double *y, int z) +{ + int i; + for (i = 0; i < z; i++) + { + x[i] = i & 31; + y[i] = (i & 63) - 30; + } +} + +double b[1024]; +double (&br) [1024] = b; +double cbuf[1024]; +double *c = cbuf; +double *&cr = c; +extern double (&fr) [1024]; +extern double *&gr; + +double +fn2 (int x, double (&dr) [1024], double *&er) +{ + double s = 0; + double h[1024]; + double (&hr) [1024] = h; + double ibuf[1024]; + double *i = ibuf; + double *&ir = i; + int j; + fn1 (hr + 2 * x, ir + 2 * x, x); + #pragma omp target map(to: br[:x], cr[0:x], dr[x:x], er[x:x]) \ + map(to: fr[0:x], gr[0:x], hr[2 * x:x], ir[2 * x:x]) + #pragma omp parallel for reduction(+:s) + for (j = 0; j < x; j++) + s += br[j] * cr[j] + dr[x + j] + er[x + j] + + fr[j] + gr[j] + hr[2 * x + j] + ir[2 * x + j]; + return s; +} + +int +main () +{ + double d[1024]; + double ebuf[1024]; + double *e = ebuf; + fn1 (br, cr, 128); + fn1 (d + 128, e + 128, 128); + fn1 (fr, gr, 128); + double h = fn2 (128, d, e); + if (h != 20416.0) + abort (); + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/target-3.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/target-3.C new file mode 100644 index 000000000..2e4586fec --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/target-3.C @@ -0,0 +1 @@ +#include "../libgomp.c/target-2.c" diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/task-1.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/task-1.C new file mode 100644 index 000000000..94ab6f21f --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/task-1.C @@ -0,0 +1,83 @@ +extern "C" void abort (); + +int a = 18; + +void +f1 (int i, int j, int k) +{ + int l = 6, m = 7, n = 8; +#pragma omp task private(j, m) shared(k, n) + { + j = 6; + m = 5; + if (++a != 19 || ++i != 9 || j != 6 || ++l != 7 || m != 5 || ++n != 9) + #pragma omp atomic + k++; + } +#pragma omp taskwait + if (a != 19 || i != 8 || j != 26 || k != 0 || l != 6 || m != 7 || n != 9) + abort (); +} + +int v1 = 1, v2 = 2, v5 = 5; +int e; + +void +f2 (void) +{ + int v3 = 3; +#pragma omp sections private (v1) firstprivate (v2) + { + #pragma omp section + { + int v4 = 4; + v1 = 7; + #pragma omp task + { + if (++v1 != 8 || ++v2 != 3 || ++v3 != 4 || ++v4 != 5 || ++v5 != 6) + e = 1; + } + #pragma omp taskwait + if (v1 != 7 || v2 != 2 || v3 != 3 || v4 != 4 || v5 != 6) + abort (); + if (e) + abort (); + } + } +} + +void +f3 (int i, int j, int k) +{ + int l = 6, m = 7, n = 8; +#pragma omp task private(j, m) shared(k, n) untied + { + j = 6; + m = 5; + if (++a != 19 || ++i != 9 || j != 6 || ++l != 7 || m != 5 || ++n != 9) + #pragma omp atomic + k++; + } +#pragma omp taskwait + if (a != 19 || i != 8 || j != 26 || k != 0 || l != 6 || m != 7 || n != 9) + abort (); +} + +int +main () +{ + f1 (8, 26, 0); + f2 (); + a = 18; + f3 (8, 26, 0); + a = 18; +#pragma omp parallel num_threads(4) + { + #pragma omp master + { + f1 (8, 26, 0); + a = 18; + f3 (8, 26, 0); + } + } +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/task-2.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/task-2.C new file mode 100644 index 000000000..a198cc721 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/task-2.C @@ -0,0 +1,70 @@ +// { dg-do run } + +#include <omp.h> +extern "C" void abort (); + +int l = 5; + +int +foo (int i) +{ + int j = 7; + const int k = 8; + #pragma omp task firstprivate (i) shared (j, l) + { + #pragma omp critical + { + j += i; + l += k; + } + } + i++; + #pragma omp task firstprivate (i) shared (j, l) + { + #pragma omp critical + { + j += i; + l += k; + } + } + i++; + #pragma omp task firstprivate (i) shared (j, l) + { + #pragma omp critical + { + j += i; + l += k; + } + } + i++; + #pragma omp task firstprivate (i) shared (j, l) + { + #pragma omp critical + { + j += i; + l += k; + } + } + i++; + #pragma omp taskwait + return (i != 8 * omp_get_thread_num () + 4 + || j != 4 * i - 3 + || k != 8); +} + +int +main (void) +{ + int r = 0; + #pragma omp parallel num_threads (4) reduction(+:r) + if (omp_get_num_threads () != 4) + { + #pragma omp master + l = 133; + } + else if (foo (8 * omp_get_thread_num ())) + r++; + if (r || l != 133) + abort (); + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/task-3.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/task-3.C new file mode 100644 index 000000000..e1ecb4965 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/task-3.C @@ -0,0 +1,90 @@ +// { dg-do run } + +extern "C" void abort (); + +struct A +{ + A (); + ~A (); + A (const A &); + unsigned long l; +}; + +int e; + +A::A () +{ + l = 17; +} + +A::~A () +{ + if (l > 30) + #pragma omp atomic + e++; +} + +A::A (const A &r) +{ + l = r.l; +} + +void +check (int i, A &a, int j, A &b) +{ + if (i != 6 || a.l != 21 || j != 0 || b.l != 23) + #pragma omp atomic + e++; +} + +A b; +int j; + +void +foo (int i) +{ + A a; + a.l = 21; + #pragma omp task firstprivate (i, a, j, b) + check (i, a, j, b); +} + +void +bar (int i, A a) +{ + a.l = 21; + #pragma omp task firstprivate (i, a, j, b) + check (i, a, j, b); +} + +A +baz () +{ + A a, c; + a.l = 21; + c.l = 23; + #pragma omp task firstprivate (a, c) + check (6, a, 0, c); + return a; +} + +int +main () +{ + b.l = 23; + foo (6); + bar (6, A ()); + baz (); + #pragma omp parallel num_threads (4) + { + #pragma omp single + for (int i = 0; i < 64; i++) + { + foo (6); + bar (6, A ()); + baz (); + } + } + if (e) + abort (); +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/task-4.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/task-4.C new file mode 100644 index 000000000..f2e786a2f --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/task-4.C @@ -0,0 +1,37 @@ +#include <omp.h> +extern "C" void *memset (void *, int, __SIZE_TYPE__); +extern "C" void abort (void); + +int e; + +void +baz (int i, int *p, int j, int *q) +{ + if (p[0] != 1 || p[i] != 3 || q[0] != 2 || q[j] != 4) + #pragma omp atomic + e++; +} + +void +foo (int i, int j) +{ + int p[i + 1]; + int q[j + 1]; + memset (p, 0, sizeof (p)); + memset (q, 0, sizeof (q)); + p[0] = 1; + p[i] = 3; + q[0] = 2; + q[j] = 4; + #pragma omp task firstprivate (p, q) + baz (i, p, j, q); +} + +int +main () +{ + #pragma omp parallel num_threads (4) + foo (5 + omp_get_thread_num (), 7 + omp_get_thread_num ()); + if (e) + abort (); +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/task-5.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/task-5.C new file mode 100644 index 000000000..c882bfe15 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/task-5.C @@ -0,0 +1,90 @@ +// { dg-do run } + +extern "C" void abort (); + +struct A +{ + A (); + ~A (); + A (const A &); + unsigned long l; +}; + +int e; + +A::A () +{ + l = 17; +} + +A::~A () +{ + if (l > 130) + #pragma omp atomic + e++; +} + +A::A (const A &r) +{ + l = r.l + 64; +} + +void +check (int i, A &a, int j, A &b) +{ + if (i != 6 || a.l != 21 + 64 || j != 0 || b.l != 23 + 64) + #pragma omp atomic + e++; +} + +A b; +int j; + +void +foo (int i) +{ + A a; + a.l = 21; + #pragma omp task firstprivate (j, b) + check (i, a, j, b); +} + +void +bar (int i, A a) +{ + a.l = 21; + #pragma omp task firstprivate (j, b) + check (i, a, j, b); +} + +A +baz () +{ + A a, c; + a.l = 21; + c.l = 23; + #pragma omp task firstprivate (a, c) + check (6, a, 0, c); + return a; +} + +int +main () +{ + b.l = 23; + foo (6); + bar (6, A ()); + baz (); + #pragma omp parallel num_threads (4) + { + #pragma omp single + for (int i = 0; i < 64; i++) + { + foo (6); + bar (6, A ()); + baz (); + } + } + if (e) + abort (); +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/task-6.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/task-6.C new file mode 100644 index 000000000..389e1e218 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/task-6.C @@ -0,0 +1,86 @@ +extern "C" void abort (); + +int a = 18; + +template <typename T> +void +f1 (T i, T j, T k) +{ + T l = 6, m = 7, n = 8; +#pragma omp task private(j, m) shared(k, n) + { + j = 6; + m = 5; + if (++a != 19 || ++i != 9 || j != 6 || ++l != 7 || m != 5 || ++n != 9) + #pragma omp atomic + k++; + } +#pragma omp taskwait + if (a != 19 || i != 8 || j != 26 || k != 0 || l != 6 || m != 7 || n != 9) + abort (); +} + +int v1 = 1, v2 = 2, v5 = 5; +int e; + +template <typename T> +void +f2 (void) +{ + T v3 = 3; +#pragma omp sections private (v1) firstprivate (v2) + { + #pragma omp section + { + T v4 = 4; + v1 = 7; + #pragma omp task + { + if (++v1 != 8 || ++v2 != 3 || ++v3 != 4 || ++v4 != 5 || ++v5 != 6) + e = 1; + } + #pragma omp taskwait + if (v1 != 7 || v2 != 2 || v3 != 3 || v4 != 4 || v5 != 6) + abort (); + if (e) + abort (); + } + } +} + +template <typename T> +void +f3 (T i, T j, T k) +{ + T l = 6, m = 7, n = 8; +#pragma omp task private(j, m) shared(k, n) untied + { + j = 6; + m = 5; + if (++a != 19 || ++i != 9 || j != 6 || ++l != 7 || m != 5 || ++n != 9) + #pragma omp atomic + k++; + } +#pragma omp taskwait + if (a != 19 || i != 8 || j != 26 || k != 0 || l != 6 || m != 7 || n != 9) + abort (); +} + +int +main () +{ + f1 <int> (8, 26, 0); + f2 <int> (); + a = 18; + f3 <int> (8, 26, 0); + a = 18; +#pragma omp parallel num_threads(4) + { + #pragma omp master + { + f1 <int> (8, 26, 0); + a = 18; + f3 <int> (8, 26, 0); + } + } +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/task-7.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/task-7.C new file mode 100644 index 000000000..e9828cd2c --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/task-7.C @@ -0,0 +1,18 @@ +// PR c++/36523 +// { dg-do run } + +template<typename T> +struct A +{ + A() { } + A(const A&) { } + void foo() { } +}; + +int main() +{ + A<int> a; + #pragma omp task firstprivate (a) + a.foo(); + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/task-8.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/task-8.C new file mode 100644 index 000000000..b523c4d22 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/task-8.C @@ -0,0 +1,44 @@ +// { dg-do run } + +#include <omp.h> +#include <cstdlib> + +int errval; + +int +main () +{ + int e; +#pragma omp parallel shared(errval) + { + if (omp_in_final ()) + #pragma omp atomic write + errval = 1; + #pragma omp task if (0) shared(errval) + { + if (omp_in_final ()) + #pragma omp atomic write + errval = 1; + #pragma omp task if (0) shared(errval) + if (omp_in_final ()) + #pragma omp atomic write + errval = 1; + } + #pragma omp task final (1) shared(errval) + { + if (!omp_in_final ()) + #pragma omp atomic write + errval = 1; + #pragma omp taskyield + #pragma omp taskwait + #pragma omp task shared(errval) + if (!omp_in_final ()) + #pragma omp atomic write + errval = 1; + } + } + #pragma omp atomic read + e = errval; + if (e) + abort (); +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/taskgroup-1.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/taskgroup-1.C new file mode 100644 index 000000000..512989661 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/taskgroup-1.C @@ -0,0 +1 @@ +#include "../libgomp.c/taskgroup-1.c" diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/tls-init1.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/tls-init1.C new file mode 100644 index 000000000..d62e96b95 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/tls-init1.C @@ -0,0 +1,28 @@ +// { dg-require-alias } + +extern "C" void abort(); + +struct A +{ + A(); + int i; +}; + +extern A a; +#pragma omp threadprivate (a) +A a; + +A &f() +{ + return a; +} + +int j; +A::A(): i(j) { } + +int main() +{ + j = 42; + if (f().i != 42) + abort (); +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/udr-1.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/udr-1.C new file mode 100644 index 000000000..c3ddd859e --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/udr-1.C @@ -0,0 +1,82 @@ +// { dg-do run } + +extern "C" void abort (); + +struct S +{ + int s; + void foo (S &x) { s += x.s; } + void foo (S &x, bool y) { s += x.s; if (y) abort (); } + S (const S &x) { s = x.s + 1; } + S (const S &x, bool y) { s = x.s + 2; if (y) abort (); } + S () { s = 6; } + ~S (); +}; + +S::~S () +{ + if (s < 6) abort (); + s = -1; + /* Ensure the above store is not DSEd. */ + asm volatile ("" : : "r" (&s) : "memory"); +} + +void +bar (S &x) +{ + if (x.s != 6) abort (); + x.s = 15; +} + +#pragma omp declare reduction (foo: S: omp_out.foo (omp_in)) \ + initializer (omp_priv (omp_orig, false)) +#pragma omp declare reduction (foo: char, int, short: omp_out += omp_in - 4) \ + initializer (omp_priv (4)) +#pragma omp declare reduction (+: S: omp_out.foo (omp_in, false)) \ + initializer (omp_priv (omp_orig)) + +namespace N +{ + #pragma omp declare reduction (foo: S: omp_out.foo (omp_in)) \ + initializer (::bar (omp_priv)) + namespace M {} +} + +int +main () +{ + S a, b, c, s, t, u; + if (a.s != 6 || b.s != 6 || c.s != 6 + || s.s != 6 || t.s != 6 || u.s != 6) abort (); + s.s = 9; t.s = 10; u.s = 11; + int d = 0, e = 0, f = 0, g = 0, h = 30, v = 2, q = 0; + #pragma omp declare reduction (foo: S: omp_out.foo (omp_in, true)) \ + initializer (omp_priv = omp_orig) + { + #pragma omp declare reduction (foo: S: omp_out.foo (omp_in, false)) \ + initializer (omp_priv = omp_orig) + #pragma omp parallel num_threads (4) reduction (N::operator +: q) \ + reduction (operator +: a, d) reduction (::operator +: b, e) \ + reduction (+: c, f) reduction (::N::M::operator +: g) \ + reduction (::N::min: h) reduction (foo: s) reduction (N::foo: t) \ + reduction (::foo: u) reduction (::foo: v) + { + if (a.s != 7 || b.s != 7 || c.s != 7 + || s.s != 10 || t.s != 15 || u.s != 13 + || v != 4 || d || e || f || g || h != __INT_MAX__) abort (); + asm volatile ("" : "+m" (a.s), "+m" (b.s)); + asm volatile ("" : "+m" (c.s), "+r" (d)); + asm volatile ("" : "+r" (e), "+r" (f)); + asm volatile ("" : "+r" (g), "+r" (h)); + asm volatile ("" : "+m" (s.s), "+m" (t.s)); + asm volatile ("" : "+m" (u.s), "+r" (v)); + a.s++; b.s++; c.s++; d++; e++; f++; g++; h = t.s; + s.s++; t.s++; u.s++; v++; q++; + } + } + if (a.s != 6 + q * 8 || b.s != 6 + q * 8 || c.s != 6 + q * 8 + || d != q || e != q || f != q || g != q || h != 15 + || s.s != 9 + q * 11 || t.s != 10 + q * 16 || u.s != 11 + q * 14 + || v != 2 + q) + abort (); +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/udr-2.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/udr-2.C new file mode 100644 index 000000000..5408be146 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/udr-2.C @@ -0,0 +1,88 @@ +// { dg-do run } + +extern "C" void abort (); + +namespace NS +{ + struct U + { + void foo (U &, bool); + U (); + }; + struct S + { + int s; + #pragma omp declare reduction (foo : U, S : omp_out.foo (omp_in, false)) + #pragma omp declare reduction (foo : int : omp_out += omp_in) \ + initializer (omp_priv = int ()) + void baz (int v) + { + S s; + int q = 0; + if (s.s != 6 || v != 0) abort (); + s.s = 20; + #pragma omp parallel num_threads (4) reduction (foo : s, v) \ + reduction (::NS::U::operator + : q) + { + if (s.s != 6 || q != 0 || v != 0) abort (); + asm volatile ("" : "+m" (s.s), "+r" (q), "+r" (v)); + s.s++; q++; v++; + } + if (s.s != 20 + q * 7 || q != v) abort (); + } + void foo (S &x) { s += x.s; } + void foo (S &x, bool y) { s += x.s; if (y) abort (); } + S (const S &x) { s = x.s + 1; } + S (const S &x, bool y) { s = x.s + 2; if (y) abort (); } + S () { s = 6; } + S (int x) { s = x; } + ~S (); + }; + #pragma omp declare reduction (bar : S : omp_out.foo (omp_in)) \ + initializer (omp_priv (8)) +} + +NS::S::~S () +{ + if (s < 6) abort (); + s = -1; + /* Ensure the above store is not DSEd. */ + asm volatile ("" : : "r" (&s) : "memory"); +} + +struct T : public NS::S +{ + void baz () + { + S s; + int q = 0; + if (s.s != 6) abort (); + #pragma omp parallel num_threads (4) reduction (foo:s) \ + reduction (+: q) + { + if (s.s != 6 || q != 0) abort (); + asm volatile ("" : "+m" (s.s), "+r" (q)); + s.s += 2; q++; + } + if (s.s != 6 + q * 8) abort (); + } +}; + +int +main () +{ + NS::S s; + s.baz (0); + T t; + t.baz (); + int q = 0; + if (s.s != 6) abort (); + // Test ADL + #pragma omp parallel num_threads (4) reduction (bar:s) reduction (+:q) + { + if (s.s != 8 || q != 0) abort (); + asm volatile ("" : "+m" (s.s), "+r" (q)); + s.s += 4; q++; + } + if (s.s != 6 + q * 12) abort (); +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/udr-3.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/udr-3.C new file mode 100644 index 000000000..74a01389c --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/udr-3.C @@ -0,0 +1,149 @@ +// { dg-do run } + +extern "C" void abort (); + +void +dblinit (double *p) +{ + *p = 2.0; +} + +namespace NS +{ + template <int N> + struct U + { + void foo (U &, bool); + U (); + }; + template <int N> + struct S + { + int s; + #pragma omp declare reduction (foo : U<0>, S : omp_out.foo (omp_in, false)) + #pragma omp declare reduction (foo : int : omp_out += omp_in) \ + initializer (omp_priv = N + 2) + #pragma omp declare reduction (foo : double : omp_out += omp_in) \ + initializer (dblinit (&omp_priv)) + void baz (int v) + { + S s; + int q = 0; + if (s.s != 6 || v != 0) abort (); + s.s = 20; + double d = 4.0; + #pragma omp parallel num_threads (4) reduction (foo : s, v, d) \ + reduction (::NS::U<N>::operator + : q) + { + if (s.s != 6 || q != 0 || v != N + 2 || d != 2.0) abort (); + asm volatile ("" : "+m" (s.s), "+r" (q), "+r" (v)); + s.s++; q++; v++; + } + if (s.s != 20 + q * 7 || (N + 3) * q != v || d != 4.0 + 2.0 * q) + abort (); + } + void foo (S &x) { s += x.s; } + void foo (S &x, bool y) { s += x.s; if (y) abort (); } + S (const S &x) { s = x.s + 1; } + S (const S &x, bool y) { s = x.s + 2; if (y) abort (); } + S () { s = 6; } + S (int x) { s = x; } + ~S (); + }; + #pragma omp declare reduction (bar : S<1> : omp_out.foo (omp_in)) \ + initializer (omp_priv (8)) +} + +template <int N> +NS::S<N>::~S () +{ + if (s < 6) abort (); + s = -1; + /* Ensure the above store is not DSEd. */ + asm volatile ("" : : "r" (&s) : "memory"); +} + +template <int N> +struct T : public NS::S<N> +{ + void baz () + { + NS::S<N> s; + int q = 0; + if (s.s != 6) abort (); + #pragma omp parallel num_threads (4) reduction (foo:s) \ + reduction (+: q) + { + if (s.s != 6 || q != 0) abort (); + asm volatile ("" : "+m" (s.s), "+r" (q)); + s.s += 2; q++; + } + if (s.s != 6 + q * 8) abort (); + } +}; + +struct W +{ + int v; + W () : v (6) {} + ~W () {} +}; + +template <typename T, typename D> +struct V +{ + #pragma omp declare reduction (baz: T: omp_out.s += omp_in.s) \ + initializer (omp_priv (11)) + #pragma omp declare reduction (baz: D: omp_out += omp_in) \ + initializer (dblinit (&omp_priv)) + static void dblinit (D *x) { *x = 3.0; } + void baz () + { + T t; + V v; + int q = 0; + D d = 4.0; + if (t.s != 6 || v.v != 4) abort (); + #pragma omp declare reduction (+ : V, W : omp_out.v -= omp_in.v) \ + initializer (omp_priv (12)) + { + #pragma omp declare reduction (+ : W, V : omp_out.v += omp_in.v) \ + initializer (omp_priv (9)) + #pragma omp parallel num_threads (4) reduction (+: v, q) \ + reduction (baz: t, d) + { + if (t.s != 11 || v.v != 9 || q != 0 || d != 3.0) abort (); + asm volatile ("" : "+m" (t.s), "+m" (v.v), "+r" (q)); + t.s += 2; v.v += 3; q++; + } + if (t.s != 6 + 13 * q || v.v != 4 + 12 * q || d != 4.0 + 3.0 * q) + abort (); + } + } + int v; + V () : v (4) {} + V (int x) : v (x) {} + ~V () {} +}; + +int +main () +{ + NS::S<0> u; + u.baz (0); + T<2> t; + t.baz (); + NS::S<1> s; + int q = 0; + if (s.s != 6) abort (); + // Test ADL + #pragma omp parallel num_threads (4) reduction (bar:s) reduction (+:q) + { + if (s.s != 8 || q != 0) abort (); + asm volatile ("" : "+m" (s.s), "+r" (q)); + s.s += 4; q++; + } + if (s.s != 6 + q * 12) abort (); + V <NS::S <0>, double> v; + v.baz (); +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/udr-4.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/udr-4.C new file mode 100644 index 000000000..3e717467a --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/udr-4.C @@ -0,0 +1,32 @@ +// { dg-do run } + +extern "C" void abort (); + +struct S +{ + int s; + S () : s (0) {} + ~S () {} +}; + +#pragma omp declare reduction (+:S:omp_out.s += omp_in.s) +#pragma omp declare reduction (foo:S:omp_out.s += omp_in.s) +#pragma omp declare reduction (foo:int:omp_out += omp_in) + +int +main () +{ + int i, u = 0, q = 0; + S s, t; + if (s.s != 0 || t.s != 0) abort (); + #pragma omp parallel reduction(+:s, q) reduction(foo:t, u) + { + if (s.s != 0 || t.s != 0 || u != 0 || q != 0) abort (); + s.s = 6; + t.s = 8; + u = 9; + q++; + } + if (s.s != 6 * q || t.s != 8 * q || u != 9 * q) abort (); + return 0; +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/udr-5.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/udr-5.C new file mode 100644 index 000000000..91ae2f697 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/udr-5.C @@ -0,0 +1,49 @@ +// { dg-do run } + +extern "C" void abort (); + +struct S +{ + void foo () + { + S s; + int j = 0; + #pragma omp declare reduction (bar : int : omp_out += omp_in) + #pragma omp parallel reduction (bar : s) reduction(S::operator+ : j) + s.a = 4, j = 1; + if (s.a != 4 * j) abort (); + } + #pragma omp declare reduction (bar : S : baz (omp_out, omp_in)) + static void baz (S &x, S &y) { x.a += y.a; } + S () : a (0) {} + int a; +}; + +template <int N> +struct T +{ + void foo () + { + S s; + T t; + int j = 0; + #pragma omp declare reduction (bar : int : omp_out += omp_in) + #pragma omp parallel reduction (bar : t) reduction (S::bar : s) \ + reduction(T<N>::operator+ : j) + s.a = 4, t.a = 5, j = 1; + if (s.a != 4 * j || t.a != 5 * j) abort (); + } + #pragma omp declare reduction (bar : T<N> : baz (omp_out, omp_in)) + static void baz (T &x, T &y) { x.a += y.a; } + T () : a (N) {} + int a; +}; + +int +main () +{ + S s; + s.foo (); + T<0> t; + t.foo (); +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/udr-6.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/udr-6.C new file mode 100644 index 000000000..4be821ed0 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/udr-6.C @@ -0,0 +1,68 @@ +// { dg-do run } + +extern "C" void abort (); + +struct A { int a; A () : a (6) {} }; +struct B { int b; B () : b (5) {} }; +struct C { int c; C () : c (4) {} }; +struct D { int d; D () : d (3) {} }; +struct E : A, B {}; +struct F : C, D {}; +struct G : E, F {}; +void foo (B &); +void foo (F &); +#pragma omp declare reduction (+:B:omp_out.b += omp_in.b) \ + initializer(foo (omp_priv)) + +void +foo (B &x) +{ + if (x.b != 5) + abort (); + x.b = 9; +} + +template <typename T> +void bar (T &x, T &y, int z) +{ + if (z) + abort (); + x.a += y.a; +} + +namespace N1 +{ + struct A { int a; A () : a (0) {} }; + #pragma omp declare reduction (+:A:bar (omp_out, omp_in, 0)) +}; +namespace N2 +{ + struct B : N1::A { }; + #pragma omp declare reduction (+:N1::A:bar (omp_out, omp_in, 1)) +}; + +int +main () +{ + G g; + int i = 0; + #pragma omp parallel reduction(+:g, i) + { + if (g.a != 6 || g.b != 9 || g.c != 4 || g.d != 3) + abort (); + g.a = 1, g.b = 2, g.c = 3, g.d = 4, i = 1; + } + if (g.a != 6 || g.b != 5 + 2 * i || g.c != 4 || g.d != 3) + abort (); + N2::B b; + i = 0; + #pragma omp parallel reduction (+:b, i) + { + if (b.a != 0) + abort (); + b.a = 4; + i = 1; + } + if (b.a != 4 * i) + abort (); +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/udr-7.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/udr-7.C new file mode 100644 index 000000000..6f661895a --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/udr-7.C @@ -0,0 +1,72 @@ +// { dg-do run } + +extern "C" void abort (); + +struct S +{ + int s; + void foo (S &x) { s += x.s; } + S (const S &x) { s = x.s + 1; } + S () { s = 6; } + ~S () {} +}; + +void +bar (S &x, S &y) +{ + if (x.s != 6 || y.s != 6) + abort (); + x.s = 8; +} + +#pragma omp declare reduction (foo: S: omp_out.foo (omp_in)) \ + initializer (omp_priv (omp_orig)) +#pragma omp declare reduction (bar : S: omp_out.foo (omp_in)) \ + initializer (bar (omp_priv, omp_orig)) + +S +baz (S x) +{ + S r; + int i = 0; + if (x.s != 7 || r.s != 6) + abort (); + #pragma omp parallel reduction (foo: x) reduction (bar: r) \ + reduction (+: i) + { + if (x.s != 8 || r.s != 8) + abort (); + x.s = 12; + r.s = 14; + i = 1; + } + if (x.s != 7 + 12 * i || r.s != 6 + 14 * i) + abort (); + return r; +} + +void +baz (S &x, S &y) +{ + int i = 0, &j = i; + #pragma omp parallel reduction (foo: x) reduction (bar: y) \ + reduction (+: i) + { + if (x.s != 7 || y.s != 8) + abort (); + x.s = 12; + y.s = 14; + i = 1; + } + if (x.s != 6 + 12 * j || y.s != 6 + 14 * j) + abort (); +} + +int +main () +{ + S s; + baz (s); + S t, u; + baz (t, u); +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/udr-8.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/udr-8.C new file mode 100644 index 000000000..81c4beb8b --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/udr-8.C @@ -0,0 +1,39 @@ +// { dg-do run } + +extern "C" void abort (); + +struct S; +void foo (S *, S *); +void bar (S &, S &); +#pragma omp declare reduction (+:S:foo (&omp_out, &omp_in)) +#pragma omp declare reduction (*:S:bar (omp_out, omp_in)) +struct S { int s; S () : s (0) {} }; + +void +foo (S *x, S *y) +{ + x->s += y->s; +} + +void +bar (S &x, S &y) +{ + x.s += y.s; +} + +int +main () +{ + S s, t; + int i = 0; + #pragma omp parallel reduction (+:s, i) reduction (*:t) + { + if (s.s != 0 || t.s != 0) + abort (); + s.s = 2; + t.s = 3; + i = 1; + } + if (s.s != 2 * i || t.s != 3 * i) + abort (); +} diff --git a/gcc-4.9/libgomp/testsuite/libgomp.c++/udr-9.C b/gcc-4.9/libgomp/testsuite/libgomp.c++/udr-9.C new file mode 100644 index 000000000..58fea18a4 --- /dev/null +++ b/gcc-4.9/libgomp/testsuite/libgomp.c++/udr-9.C @@ -0,0 +1,3 @@ +// { dg-do run } + +#include "../libgomp.c/udr-1.c" |