diff options
author | Jakub Jelinek <jakub@redhat.com> | 2021-09-18 09:47:25 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2021-09-18 09:47:25 +0200 |
commit | e5597f2ad55219092929dc12ea15e1edba06df18 (patch) | |
tree | db45e32b3dc999d431fae4e2bdbd0bed09573756 /gcc/gimplify.c | |
parent | d07c750cc6c866e77e0c7eafcd71466139882618 (diff) | |
download | gcc-e5597f2ad55219092929dc12ea15e1edba06df18.zip gcc-e5597f2ad55219092929dc12ea15e1edba06df18.tar.gz gcc-e5597f2ad55219092929dc12ea15e1edba06df18.tar.bz2 |
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.
Diffstat (limited to 'gcc/gimplify.c')
-rw-r--r-- | gcc/gimplify.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/gcc/gimplify.c b/gcc/gimplify.c index f680292..9163dcd 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -7369,6 +7369,18 @@ omp_default_clause (struct gimplify_omp_ctx *ctx, tree decl, default_kind = kind; else if (VAR_P (decl) && TREE_STATIC (decl) && DECL_IN_CONSTANT_POOL (decl)) default_kind = OMP_CLAUSE_DEFAULT_SHARED; + /* For C/C++ default({,first}private), variables with static storage duration + declared in a namespace or global scope and referenced in construct + must be explicitly specified, i.e. acts as default(none). */ + else if ((default_kind == OMP_CLAUSE_DEFAULT_PRIVATE + || default_kind == OMP_CLAUSE_DEFAULT_FIRSTPRIVATE) + && VAR_P (decl) + && is_global_var (decl) + && (DECL_FILE_SCOPE_P (decl) + || (DECL_CONTEXT (decl) + && TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)) + && !lang_GNU_Fortran ()) + default_kind = OMP_CLAUSE_DEFAULT_NONE; switch (default_kind) { |