gcc/libgomp/testsuite/libgomp.c++/default-1.C
Jakub Jelinek e5597f2ad5 openmp: Allow private or firstprivate arguments to default clause even for C/C++
OpenMP 5.1 allows default(private) or default(firstprivate) even in C/C++,
but it behaves the same way as in Fortran only for variables not declared at
namespace or file scope.  For the namespace/file scope variables it instead
behaves as default(none).

2021-09-18  Jakub Jelinek  <jakub@redhat.com>

gcc/
	* gimplify.c (omp_default_clause): For C/C++ default({,first}private),
	if file/namespace scope variable doesn't have predetermined sharing,
	treat it as if there was default(none).
gcc/c/
	* c-parser.c (c_parser_omp_clause_default): Handle private and
	firstprivate arguments, adjust diagnostics on unknown argument.
gcc/cp/
	* parser.c (cp_parser_omp_clause_default): Handle private and
	firstprivate arguments, adjust diagnostics on unknown argument.
	* cp-gimplify.c (cxx_omp_finish_clause): Handle OMP_CLAUSE_PRIVATE.
gcc/testsuite/
	* c-c++-common/gomp/default-2.c: New test.
	* c-c++-common/gomp/default-3.c: New test.
	* g++.dg/gomp/default-1.C: New test.
libgomp/
	* testsuite/libgomp.c++/default-1.C: New test.
	* testsuite/libgomp.c-c++-common/default-1.c: New test.
	* libgomp.texi (OpenMP 5.1): Mark "private and firstprivate argument
	to default clause in C and C++" as implemented.
2021-09-18 09:47:25 +02:00

30 lines
585 B
C

#include <omp.h>
#include <stdlib.h>
struct S { S () : s (42) {} S (const S &x) : s (x.s) {}; ~S () {} int s; };
int
main ()
{
S s;
s.s = 113;
#pragma omp parallel num_threads(4) default(firstprivate)
{
if (s.s != 113)
abort ();
s.s = omp_get_thread_num ();
#pragma omp barrier
if (s.s != omp_get_thread_num ())
abort ();
}
#pragma omp parallel num_threads(4) default(private)
{
if (s.s != 42)
abort ();
s.s = omp_get_thread_num () + 13;
#pragma omp barrier
if (s.s != omp_get_thread_num () + 13)
abort ();
}
}