gcc/libgomp/testsuite/libgomp.c-c++-common/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

25 lines
468 B
C

#include <omp.h>
#include <stdlib.h>
int
main ()
{
int v = 42;
#pragma omp parallel num_threads(4) default(firstprivate)
{
if (v != 42)
abort ();
v = omp_get_thread_num ();
#pragma omp barrier
if (v != omp_get_thread_num ())
abort ();
}
#pragma omp parallel num_threads(4) default(private)
{
v = omp_get_thread_num () + 13;
#pragma omp barrier
if (v != omp_get_thread_num () + 13)
abort ();
}
return 0;
}