summaryrefslogtreecommitdiff
path: root/libgomp
diff options
context:
space:
mode:
authorRichard Henderson <rth@gcc.gnu.org>2006-03-09 10:14:39 -0800
committerRichard Henderson <rth@gcc.gnu.org>2006-03-09 10:14:39 -0800
commit1799e5d5ca20304e32f7d1134ba5e8a2ab231880 (patch)
tree461ecbd500b6dd4b3b219e43f1580a187a1407cf /libgomp
parentf8fe05458d2116e5dcd2aa3eac9dff868be27cfb (diff)
downloadgcc-1799e5d5ca20304e32f7d1134ba5e8a2ab231880.tar.gz
Merge C++ from gomp-20050608-branch.
From-SVN: r111867
Diffstat (limited to 'libgomp')
-rw-r--r--libgomp/ChangeLog4
-rw-r--r--libgomp/testsuite/libgomp.c++/c++.exp20
-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-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++/loop-1.C96
-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.C24
-rw-r--r--libgomp/testsuite/libgomp.c++/loop-7.C22
-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++/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
34 files changed, 1462 insertions, 0 deletions
diff --git a/libgomp/ChangeLog b/libgomp/ChangeLog
index fd1a2315354..278cba07e3c 100644
--- a/libgomp/ChangeLog
+++ b/libgomp/ChangeLog
@@ -1,3 +1,7 @@
+2006-03-09 Diego Novillo <dnovillo@redhat.com>
+
+ * testsuite/libgomp.c++: New directory.
+
2006-02-25 Shantonu Sen <ssen@opendarwin.org>
* config/posix/sem.h: Define BROKEN_POSIX_SEMAPHORES functions.
diff --git a/libgomp/testsuite/libgomp.c++/c++.exp b/libgomp/testsuite/libgomp.c++/c++.exp
new file mode 100644
index 00000000000..ecb4aa9a9c7
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c++/c++.exp
@@ -0,0 +1,20 @@
+set lang_library_path "../libstdc++-v3/src/.libs"
+set lang_test_file "${lang_library_path}/libstdc++.a"
+set lang_link_flags "-lstdc++"
+
+load_lib libgomp-dg.exp
+
+# Initialize dg.
+dg-init
+
+if [file exists "${blddir}/${lang_test_file}"] {
+
+ # Gather a list of all tests.
+ set tests [lsort [glob -nocomplain $srcdir/$subdir/*.C]]
+
+ # Main loop.
+ gfortran-dg-runtest $tests ""
+}
+
+# All done.
+dg-finish
diff --git a/libgomp/testsuite/libgomp.c++/copyin-1.C b/libgomp/testsuite/libgomp.c++/copyin-1.C
new file mode 100644
index 00000000000..bc12be2d2f9
--- /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 00000000000..024f5998054
--- /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 00000000000..2ad3b3a6efc
--- /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-2.C b/libgomp/testsuite/libgomp.c++/ctor-2.C
new file mode 100644
index 00000000000..6611c592fda
--- /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 00000000000..e65e4ea521b
--- /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 00000000000..e4f8f82db34
--- /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 00000000000..d99a1d4628f
--- /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 00000000000..eab74e08922
--- /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 00000000000..3d669a70791
--- /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 00000000000..5c0d81b73d1
--- /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 00000000000..215a901f8d3
--- /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++/loop-1.C b/libgomp/testsuite/libgomp.c++/loop-1.C
new file mode 100644
index 00000000000..0e83c95832f
--- /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-2.C b/libgomp/testsuite/libgomp.c++/loop-2.C
new file mode 100644
index 00000000000..ea3dc588afd
--- /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 00000000000..fa50f099f3f
--- /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 00000000000..731f2345021
--- /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 00000000000..c427efa85c6
--- /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 00000000000..fa26c6892cf
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c++/loop-6.C
@@ -0,0 +1,24 @@
+// { dg-do run }
+
+extern "C" void abort (void);
+
+volatile int count;
+static int test(void)
+{
+ return ++count > 0;
+}
+
+int main()
+{
+ int i;
+ #pragma omp for
+ 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 00000000000..4eccb7fca01
--- /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++/master-1.C b/libgomp/testsuite/libgomp.c++/master-1.C
new file mode 100644
index 00000000000..734b4e2cd98
--- /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 00000000000..8d0e397bd2e
--- /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 00000000000..3c931471328
--- /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 00000000000..e7f38f8ab7b
--- /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 00000000000..ad43b47b2c5
--- /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++/reduction-1.C b/libgomp/testsuite/libgomp.c++/reduction-1.C
new file mode 100644
index 00000000000..665163af09f
--- /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 00000000000..52b3faff787
--- /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 00000000000..4f8f2fc1236
--- /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 00000000000..32c93dbdef6
--- /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 00000000000..334a553ce23
--- /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 00000000000..01855fbd496
--- /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 00000000000..e318a48ca5c
--- /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 00000000000..c2dd228568d
--- /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 00000000000..abc7f44b311
--- /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;
+}