gcc/libgomp/testsuite/libgomp.c++/pr27337.C
Jakub Jelinek 8ca5b2a2d4 re PR c++/26943 ([gomp] firstprivate + lastprivate uses inefficient barrier)
PR c++/26943
	* omp-low.c (maybe_lookup_decl_in_outer_ctx): New function.
	(build_outer_var_ref): Use maybe_lookup_decl_in_outer_ctx
	to find if var will be a global variable even in the nested context.
	(omp_copy_decl): Only check for global variable at the end, it might
	be overridden in outer contexts.
	(scan_sharing_clauses): For global variables don't create a field.
	(lower_rec_input_clauses): Do nothing for global shared variables.
	Emit a barrier at the end of ILIST if there were any decls in both
	firstprivate and lastprivate clauses.
	(lower_send_clauses): Do nothing for global variables except for
	COPYIN.

	* testsuite/libgomp.c/pr26943-1.c: New test.
	* testsuite/libgomp.c/pr26943-2.c: New test.
	* testsuite/libgomp.c/pr26943-3.c: New test.
	* testsuite/libgomp.c/pr26943-4.c: New test.
	* testsuite/libgomp.c++/pr27337.C: Remove barrier.
	* testsuite/libgomp.c++/pr26943.C: New test.

From-SVN: r113483
2006-05-02 22:03:38 +02:00

88 lines
1.1 KiB
C

// 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;
}