summaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.c++
diff options
context:
space:
mode:
Diffstat (limited to 'libgomp/testsuite/libgomp.c++')
-rw-r--r--libgomp/testsuite/libgomp.c++/atomic-1.C53
-rw-r--r--libgomp/testsuite/libgomp.c++/c++.exp60
-rw-r--r--libgomp/testsuite/libgomp.c++/collapse-1.C29
-rw-r--r--libgomp/testsuite/libgomp.c++/collapse-2.C371
-rw-r--r--libgomp/testsuite/libgomp.c++/copyin-1.C34
-rw-r--r--libgomp/testsuite/libgomp.c++/copyin-2.C34
-rw-r--r--libgomp/testsuite/libgomp.c++/ctor-1.C65
-rw-r--r--libgomp/testsuite/libgomp.c++/ctor-10.C78
-rw-r--r--libgomp/testsuite/libgomp.c++/ctor-11.C100
-rw-r--r--libgomp/testsuite/libgomp.c++/ctor-12.C65
-rw-r--r--libgomp/testsuite/libgomp.c++/ctor-2.C76
-rw-r--r--libgomp/testsuite/libgomp.c++/ctor-3.C89
-rw-r--r--libgomp/testsuite/libgomp.c++/ctor-4.C90
-rw-r--r--libgomp/testsuite/libgomp.c++/ctor-5.C52
-rw-r--r--libgomp/testsuite/libgomp.c++/ctor-6.C50
-rw-r--r--libgomp/testsuite/libgomp.c++/ctor-7.C67
-rw-r--r--libgomp/testsuite/libgomp.c++/ctor-8.C77
-rw-r--r--libgomp/testsuite/libgomp.c++/ctor-9.C60
-rw-r--r--libgomp/testsuite/libgomp.c++/for-1.C291
-rw-r--r--libgomp/testsuite/libgomp.c++/for-2.C182
-rw-r--r--libgomp/testsuite/libgomp.c++/for-3.C239
-rw-r--r--libgomp/testsuite/libgomp.c++/for-4.C225
-rw-r--r--libgomp/testsuite/libgomp.c++/for-5.C303
-rw-r--r--libgomp/testsuite/libgomp.c++/for-6.C109
-rw-r--r--libgomp/testsuite/libgomp.c++/for-7.C110
-rw-r--r--libgomp/testsuite/libgomp.c++/for-8.C291
-rw-r--r--libgomp/testsuite/libgomp.c++/loop-1.C96
-rw-r--r--libgomp/testsuite/libgomp.c++/loop-10.C105
-rw-r--r--libgomp/testsuite/libgomp.c++/loop-11.C276
-rw-r--r--libgomp/testsuite/libgomp.c++/loop-12.C387
-rw-r--r--libgomp/testsuite/libgomp.c++/loop-2.C32
-rw-r--r--libgomp/testsuite/libgomp.c++/loop-3.C26
-rw-r--r--libgomp/testsuite/libgomp.c++/loop-4.C20
-rw-r--r--libgomp/testsuite/libgomp.c++/loop-5.C19
-rw-r--r--libgomp/testsuite/libgomp.c++/loop-6.C25
-rw-r--r--libgomp/testsuite/libgomp.c++/loop-7.C22
-rw-r--r--libgomp/testsuite/libgomp.c++/loop-8.C276
-rw-r--r--libgomp/testsuite/libgomp.c++/loop-9.C387
-rw-r--r--libgomp/testsuite/libgomp.c++/master-1.C24
-rw-r--r--libgomp/testsuite/libgomp.c++/nested-1.C28
-rw-r--r--libgomp/testsuite/libgomp.c++/parallel-1.C40
-rw-r--r--libgomp/testsuite/libgomp.c++/pr24455-1.C6
-rw-r--r--libgomp/testsuite/libgomp.c++/pr24455.C23
-rw-r--r--libgomp/testsuite/libgomp.c++/pr26691.C20
-rw-r--r--libgomp/testsuite/libgomp.c++/pr26943.C62
-rw-r--r--libgomp/testsuite/libgomp.c++/pr27337.C87
-rw-r--r--libgomp/testsuite/libgomp.c++/pr30703.C73
-rw-r--r--libgomp/testsuite/libgomp.c++/pr34513.C32
-rw-r--r--libgomp/testsuite/libgomp.c++/pr35185.C33
-rw-r--r--libgomp/testsuite/libgomp.c++/pr38650.C49
-rw-r--r--libgomp/testsuite/libgomp.c++/pr39573.C39
-rw-r--r--libgomp/testsuite/libgomp.c++/pr43893.C125
-rw-r--r--libgomp/testsuite/libgomp.c++/pr48869.C68
-rw-r--r--libgomp/testsuite/libgomp.c++/pr49043.C19
-rw-r--r--libgomp/testsuite/libgomp.c++/reduction-1.C36
-rw-r--r--libgomp/testsuite/libgomp.c++/reduction-2.C50
-rw-r--r--libgomp/testsuite/libgomp.c++/reduction-3.C51
-rw-r--r--libgomp/testsuite/libgomp.c++/sections-1.C64
-rw-r--r--libgomp/testsuite/libgomp.c++/shared-1.C60
-rw-r--r--libgomp/testsuite/libgomp.c++/shared-2.C47
-rw-r--r--libgomp/testsuite/libgomp.c++/single-1.C19
-rw-r--r--libgomp/testsuite/libgomp.c++/single-2.C36
-rw-r--r--libgomp/testsuite/libgomp.c++/single-3.C21
-rw-r--r--libgomp/testsuite/libgomp.c++/task-1.C83
-rw-r--r--libgomp/testsuite/libgomp.c++/task-2.C70
-rw-r--r--libgomp/testsuite/libgomp.c++/task-3.C90
-rw-r--r--libgomp/testsuite/libgomp.c++/task-4.C37
-rw-r--r--libgomp/testsuite/libgomp.c++/task-5.C90
-rw-r--r--libgomp/testsuite/libgomp.c++/task-6.C86
-rw-r--r--libgomp/testsuite/libgomp.c++/task-7.C18
70 files changed, 6457 insertions, 0 deletions
diff --git a/libgomp/testsuite/libgomp.c++/atomic-1.C b/libgomp/testsuite/libgomp.c++/atomic-1.C
new file mode 100644
index 000000000..73f6e7c40
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/c++.exp b/libgomp/testsuite/libgomp.c++/c++.exp
new file mode 100644
index 000000000..decda3d1a
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c++/c++.exp
@@ -0,0 +1,60 @@
+load_lib libgomp-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
+
+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.
+ gfortran-dg-runtest $tests $libstdcxx_includes
+}
+
+# All done.
+dg-finish
diff --git a/libgomp/testsuite/libgomp.c++/collapse-1.C b/libgomp/testsuite/libgomp.c++/collapse-1.C
new file mode 100644
index 000000000..132d35cf4
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/collapse-2.C b/libgomp/testsuite/libgomp.c++/collapse-2.C
new file mode 100644
index 000000000..a42a1f07f
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/copyin-1.C b/libgomp/testsuite/libgomp.c++/copyin-1.C
new file mode 100644
index 000000000..bc12be2d2
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/copyin-2.C b/libgomp/testsuite/libgomp.c++/copyin-2.C
new file mode 100644
index 000000000..024f59980
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/ctor-1.C b/libgomp/testsuite/libgomp.c++/ctor-1.C
new file mode 100644
index 000000000..2ad3b3a6e
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/ctor-10.C b/libgomp/testsuite/libgomp.c++/ctor-10.C
new file mode 100644
index 000000000..f46e45ec4
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/ctor-11.C b/libgomp/testsuite/libgomp.c++/ctor-11.C
new file mode 100644
index 000000000..8f501e8c8
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/ctor-12.C b/libgomp/testsuite/libgomp.c++/ctor-12.C
new file mode 100644
index 000000000..8bd53de3f
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/ctor-2.C b/libgomp/testsuite/libgomp.c++/ctor-2.C
new file mode 100644
index 000000000..6611c592f
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/ctor-3.C b/libgomp/testsuite/libgomp.c++/ctor-3.C
new file mode 100644
index 000000000..e65e4ea52
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/ctor-4.C b/libgomp/testsuite/libgomp.c++/ctor-4.C
new file mode 100644
index 000000000..e4f8f82db
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/ctor-5.C b/libgomp/testsuite/libgomp.c++/ctor-5.C
new file mode 100644
index 000000000..d99a1d462
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/ctor-6.C b/libgomp/testsuite/libgomp.c++/ctor-6.C
new file mode 100644
index 000000000..eab74e089
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/ctor-7.C b/libgomp/testsuite/libgomp.c++/ctor-7.C
new file mode 100644
index 000000000..3d669a707
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/ctor-8.C b/libgomp/testsuite/libgomp.c++/ctor-8.C
new file mode 100644
index 000000000..5c0d81b73
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/ctor-9.C b/libgomp/testsuite/libgomp.c++/ctor-9.C
new file mode 100644
index 000000000..215a901f8
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/for-1.C b/libgomp/testsuite/libgomp.c++/for-1.C
new file mode 100644
index 000000000..1c713464e
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/for-2.C b/libgomp/testsuite/libgomp.c++/for-2.C
new file mode 100644
index 000000000..98ffa1ae6
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/for-3.C b/libgomp/testsuite/libgomp.c++/for-3.C
new file mode 100644
index 000000000..235f83875
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/for-4.C b/libgomp/testsuite/libgomp.c++/for-4.C
new file mode 100644
index 000000000..c528ef9d1
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/for-5.C b/libgomp/testsuite/libgomp.c++/for-5.C
new file mode 100644
index 000000000..9b75bf379
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/for-6.C b/libgomp/testsuite/libgomp.c++/for-6.C
new file mode 100644
index 000000000..0da21ce2f
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/for-7.C b/libgomp/testsuite/libgomp.c++/for-7.C
new file mode 100644
index 000000000..9d626c028
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/for-8.C b/libgomp/testsuite/libgomp.c++/for-8.C
new file mode 100644
index 000000000..918de7cc8
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/loop-1.C b/libgomp/testsuite/libgomp.c++/loop-1.C
new file mode 100644
index 000000000..0e83c9583
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/loop-10.C b/libgomp/testsuite/libgomp.c++/loop-10.C
new file mode 100644
index 000000000..9c0de25d5
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/loop-11.C b/libgomp/testsuite/libgomp.c++/loop-11.C
new file mode 100644
index 000000000..7775b86b8
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/loop-12.C b/libgomp/testsuite/libgomp.c++/loop-12.C
new file mode 100644
index 000000000..f8aca92b8
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/loop-2.C b/libgomp/testsuite/libgomp.c++/loop-2.C
new file mode 100644
index 000000000..ea3dc588a
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/loop-3.C b/libgomp/testsuite/libgomp.c++/loop-3.C
new file mode 100644
index 000000000..fa50f099f
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/loop-4.C b/libgomp/testsuite/libgomp.c++/loop-4.C
new file mode 100644
index 000000000..731f23450
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/loop-5.C b/libgomp/testsuite/libgomp.c++/loop-5.C
new file mode 100644
index 000000000..c427efa85
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/loop-6.C b/libgomp/testsuite/libgomp.c++/loop-6.C
new file mode 100644
index 000000000..f4a6925a4
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/loop-7.C b/libgomp/testsuite/libgomp.c++/loop-7.C
new file mode 100644
index 000000000..4eccb7fca
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/loop-8.C b/libgomp/testsuite/libgomp.c++/loop-8.C
new file mode 100644
index 000000000..bc20c68a1
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/loop-9.C b/libgomp/testsuite/libgomp.c++/loop-9.C
new file mode 100644
index 000000000..35daf2276
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/master-1.C b/libgomp/testsuite/libgomp.c++/master-1.C
new file mode 100644
index 000000000..734b4e2cd
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/nested-1.C b/libgomp/testsuite/libgomp.c++/nested-1.C
new file mode 100644
index 000000000..8d0e397bd
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/parallel-1.C b/libgomp/testsuite/libgomp.c++/parallel-1.C
new file mode 100644
index 000000000..3c9314713
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/pr24455-1.C b/libgomp/testsuite/libgomp.c++/pr24455-1.C
new file mode 100644
index 000000000..e7f38f8ab
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/pr24455.C b/libgomp/testsuite/libgomp.c++/pr24455.C
new file mode 100644
index 000000000..ad43b47b2
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c++/pr24455.C
@@ -0,0 +1,23 @@
+// { dg-do run }
+// { dg-additional-sources pr24455-1.C }
+// { dg-require-effective-target tls_runtime }
+
+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/libgomp/testsuite/libgomp.c++/pr26691.C b/libgomp/testsuite/libgomp.c++/pr26691.C
new file mode 100644
index 000000000..776b31e24
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/pr26943.C b/libgomp/testsuite/libgomp.c++/pr26943.C
new file mode 100644
index 000000000..07b7b5dbf
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/pr27337.C b/libgomp/testsuite/libgomp.c++/pr27337.C
new file mode 100644
index 000000000..6db2465ec
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/pr30703.C b/libgomp/testsuite/libgomp.c++/pr30703.C
new file mode 100644
index 000000000..d48efd952
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/pr34513.C b/libgomp/testsuite/libgomp.c++/pr34513.C
new file mode 100644
index 000000000..e5ad3bcb4
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/pr35185.C b/libgomp/testsuite/libgomp.c++/pr35185.C
new file mode 100644
index 000000000..f22c77207
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/pr38650.C b/libgomp/testsuite/libgomp.c++/pr38650.C
new file mode 100644
index 000000000..ebe221adc
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/pr39573.C b/libgomp/testsuite/libgomp.c++/pr39573.C
new file mode 100644
index 000000000..0167222bc
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/pr43893.C b/libgomp/testsuite/libgomp.c++/pr43893.C
new file mode 100644
index 000000000..be0b6f4ab
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/pr48869.C b/libgomp/testsuite/libgomp.c++/pr48869.C
new file mode 100644
index 000000000..ec952d9b7
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/pr49043.C b/libgomp/testsuite/libgomp.c++/pr49043.C
new file mode 100644
index 000000000..604cfc30d
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/reduction-1.C b/libgomp/testsuite/libgomp.c++/reduction-1.C
new file mode 100644
index 000000000..665163af0
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/reduction-2.C b/libgomp/testsuite/libgomp.c++/reduction-2.C
new file mode 100644
index 000000000..52b3faff7
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/reduction-3.C b/libgomp/testsuite/libgomp.c++/reduction-3.C
new file mode 100644
index 000000000..4f8f2fc12
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/sections-1.C b/libgomp/testsuite/libgomp.c++/sections-1.C
new file mode 100644
index 000000000..32c93dbde
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/shared-1.C b/libgomp/testsuite/libgomp.c++/shared-1.C
new file mode 100644
index 000000000..334a553ce
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/shared-2.C b/libgomp/testsuite/libgomp.c++/shared-2.C
new file mode 100644
index 000000000..01855fbd4
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/single-1.C b/libgomp/testsuite/libgomp.c++/single-1.C
new file mode 100644
index 000000000..e318a48ca
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/single-2.C b/libgomp/testsuite/libgomp.c++/single-2.C
new file mode 100644
index 000000000..c2dd22856
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/single-3.C b/libgomp/testsuite/libgomp.c++/single-3.C
new file mode 100644
index 000000000..abc7f44b3
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/task-1.C b/libgomp/testsuite/libgomp.c++/task-1.C
new file mode 100644
index 000000000..94ab6f21f
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/task-2.C b/libgomp/testsuite/libgomp.c++/task-2.C
new file mode 100644
index 000000000..a198cc721
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/task-3.C b/libgomp/testsuite/libgomp.c++/task-3.C
new file mode 100644
index 000000000..e1ecb4965
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/task-4.C b/libgomp/testsuite/libgomp.c++/task-4.C
new file mode 100644
index 000000000..f2e786a2f
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/task-5.C b/libgomp/testsuite/libgomp.c++/task-5.C
new file mode 100644
index 000000000..c882bfe15
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/task-6.C b/libgomp/testsuite/libgomp.c++/task-6.C
new file mode 100644
index 000000000..389e1e218
--- /dev/null
+++ b/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/libgomp/testsuite/libgomp.c++/task-7.C b/libgomp/testsuite/libgomp.c++/task-7.C
new file mode 100644
index 000000000..e9828cd2c
--- /dev/null
+++ b/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;
+}