aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/c/c-parser.c25
-rw-r--r--gcc/cp/cp-gimplify.c4
-rw-r--r--gcc/cp/parser.c19
-rw-r--r--gcc/gimplify.c12
-rw-r--r--gcc/testsuite/c-c++-common/gomp/default-2.c67
-rw-r--r--gcc/testsuite/c-c++-common/gomp/default-3.c14
-rw-r--r--gcc/testsuite/g++.dg/gomp/default-1.C112
7 files changed, 247 insertions, 6 deletions
diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index eba9bbf..c5e222b 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -13420,6 +13420,9 @@ c_parser_omp_clause_copyprivate (c_parser *parser, tree list)
/* OpenMP 2.5:
default ( none | shared )
+ OpenMP 5.1:
+ default ( private | firstprivate )
+
OpenACC:
default ( none | present ) */
@@ -13446,9 +13449,24 @@ c_parser_omp_clause_default (c_parser *parser, tree list, bool is_oacc)
break;
case 'p':
- if (strcmp ("present", p) != 0 || !is_oacc)
+ if (is_oacc)
+ {
+ if (strcmp ("present", p) != 0)
+ goto invalid_kind;
+ kind = OMP_CLAUSE_DEFAULT_PRESENT;
+ }
+ else
+ {
+ if (strcmp ("private", p) != 0)
+ goto invalid_kind;
+ kind = OMP_CLAUSE_DEFAULT_PRIVATE;
+ }
+ break;
+
+ case 'f':
+ if (strcmp ("firstprivate", p) != 0 || is_oacc)
goto invalid_kind;
- kind = OMP_CLAUSE_DEFAULT_PRESENT;
+ kind = OMP_CLAUSE_DEFAULT_FIRSTPRIVATE;
break;
case 's':
@@ -13469,7 +13487,8 @@ c_parser_omp_clause_default (c_parser *parser, tree list, bool is_oacc)
if (is_oacc)
c_parser_error (parser, "expected %<none%> or %<present%>");
else
- c_parser_error (parser, "expected %<none%> or %<shared%>");
+ c_parser_error (parser, "expected %<none%>, %<shared%>, "
+ "%<private%> or %<firstprivate%>");
}
parens.skip_until_found_close (parser);
diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c
index bf928a8..c86a5fe 100644
--- a/gcc/cp/cp-gimplify.c
+++ b/gcc/cp/cp-gimplify.c
@@ -2060,6 +2060,7 @@ cxx_omp_finish_clause (tree c, gimple_seq *, bool /* openacc */)
bool make_shared = false;
if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_FIRSTPRIVATE
+ && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_PRIVATE
&& (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_LASTPRIVATE
|| !OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c)))
return;
@@ -2080,9 +2081,10 @@ cxx_omp_finish_clause (tree c, gimple_seq *, bool /* openacc */)
Save the results, because later we won't be in the right context
for making these queries. */
bool first = OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE;
+ bool last = OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE;
if (!make_shared
&& CLASS_TYPE_P (inner_type)
- && cxx_omp_create_clause_info (c, inner_type, !first, first, !first,
+ && cxx_omp_create_clause_info (c, inner_type, !first, first, last,
true))
make_shared = true;
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 31bae6d..b9ed38d 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -36988,6 +36988,9 @@ cp_parser_omp_clause_collapse (cp_parser *parser, tree list, location_t location
/* OpenMP 2.5:
default ( none | shared )
+ OpenMP 5.1:
+ default ( private | firstprivate )
+
OpenACC:
default ( none | present ) */
@@ -37001,7 +37004,12 @@ cp_parser_omp_clause_default (cp_parser *parser, tree list,
matching_parens parens;
if (!parens.require_open (parser))
return list;
- if (cp_lexer_next_token_is (parser->lexer, CPP_NAME))
+ if (!is_oacc && cp_lexer_next_token_is_keyword (parser->lexer, RID_PRIVATE))
+ {
+ kind = OMP_CLAUSE_DEFAULT_PRIVATE;
+ cp_lexer_consume_token (parser->lexer);
+ }
+ else if (cp_lexer_next_token_is (parser->lexer, CPP_NAME))
{
tree id = cp_lexer_peek_token (parser->lexer)->u.value;
const char *p = IDENTIFIER_POINTER (id);
@@ -37020,6 +37028,12 @@ cp_parser_omp_clause_default (cp_parser *parser, tree list,
kind = OMP_CLAUSE_DEFAULT_PRESENT;
break;
+ case 'f':
+ if (strcmp ("firstprivate", p) != 0 || is_oacc)
+ goto invalid_kind;
+ kind = OMP_CLAUSE_DEFAULT_FIRSTPRIVATE;
+ break;
+
case 's':
if (strcmp ("shared", p) != 0 || is_oacc)
goto invalid_kind;
@@ -37038,7 +37052,8 @@ cp_parser_omp_clause_default (cp_parser *parser, tree list,
if (is_oacc)
cp_parser_error (parser, "expected %<none%> or %<present%>");
else
- cp_parser_error (parser, "expected %<none%> or %<shared%>");
+ cp_parser_error (parser, "expected %<none%>, %<shared%>, "
+ "%<private%> or %<firstprivate%>");
}
if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED
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)
{
diff --git a/gcc/testsuite/c-c++-common/gomp/default-2.c b/gcc/testsuite/c-c++-common/gomp/default-2.c
new file mode 100644
index 0000000..6378e6e
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/gomp/default-2.c
@@ -0,0 +1,67 @@
+int x;
+extern int z;
+
+void
+foo (void)
+{
+ int y = 0, i;
+ static int w;
+ #pragma omp task default(firstprivate) /* { dg-message "note: enclosing 'task'" } */
+ {
+ y++; /* { dg-bogus "'y' not specified in enclosing 'task'" } */
+ w++; /* { dg-bogus "'w' not specified in enclosing 'task'" } */
+ x++; /* { dg-error "'x' not specified in enclosing 'task'" } */
+ z++; /* { dg-error "'z' not specified in enclosing 'task'" } */
+ }
+ #pragma omp taskloop default(firstprivate) /* { dg-message "note: enclosing 'taskloop'" } */
+ for (i = 0; i < 64; i++)
+ {
+ y++; /* { dg-bogus "'y' not specified in enclosing 'taskloop'" } */
+ w++; /* { dg-bogus "'w' not specified in enclosing 'taskloop'" } */
+ x++; /* { dg-error "'x' not specified in enclosing 'taskloop'" } */
+ z++; /* { dg-error "'z' not specified in enclosing 'taskloop'" } */
+ }
+ #pragma omp teams default(firstprivate) /* { dg-message "note: enclosing 'teams'" } */
+ {
+ y++; /* { dg-bogus "'y' not specified in enclosing 'teams'" } */
+ w++; /* { dg-bogus "'w' not specified in enclosing 'teams'" } */
+ x++; /* { dg-error "'x' not specified in enclosing 'teams'" } */
+ z++; /* { dg-error "'z' not specified in enclosing 'teams'" } */
+ }
+ #pragma omp parallel default(firstprivate) /* { dg-message "note: enclosing 'parallel'" } */
+ {
+ y++; /* { dg-bogus "'y' not specified in enclosing 'parallel'" } */
+ w++; /* { dg-bogus "'w' not specified in enclosing 'parallel'" } */
+ x++; /* { dg-error "'x' not specified in enclosing 'parallel'" } */
+ z++; /* { dg-error "'z' not specified in enclosing 'parallel'" } */
+ }
+ #pragma omp task default(private) /* { dg-message "note: enclosing 'task'" } */
+ {
+ y = 1; /* { dg-bogus "'y' not specified in enclosing 'task'" } */
+ w = 1; /* { dg-bogus "'w' not specified in enclosing 'task'" } */
+ x++; /* { dg-error "'x' not specified in enclosing 'task'" } */
+ z++; /* { dg-error "'z' not specified in enclosing 'task'" } */
+ }
+ #pragma omp taskloop default(private) /* { dg-message "note: enclosing 'taskloop'" } */
+ for (i = 0; i < 64; i++)
+ {
+ y = 1; /* { dg-bogus "'y' not specified in enclosing 'taskloop'" } */
+ w = 1; /* { dg-bogus "'w' not specified in enclosing 'taskloop'" } */
+ x++; /* { dg-error "'x' not specified in enclosing 'taskloop'" } */
+ z++; /* { dg-error "'z' not specified in enclosing 'taskloop'" } */
+ }
+ #pragma omp teams default(private) /* { dg-message "note: enclosing 'teams'" } */
+ {
+ y = 1; /* { dg-bogus "'y' not specified in enclosing 'teams'" } */
+ w = 1; /* { dg-bogus "'w' not specified in enclosing 'teams'" } */
+ x++; /* { dg-error "'x' not specified in enclosing 'teams'" } */
+ z++; /* { dg-error "'z' not specified in enclosing 'teams'" } */
+ }
+ #pragma omp parallel default(private) /* { dg-message "note: enclosing 'parallel'" } */
+ {
+ y = 1; /* { dg-bogus "'y' not specified in enclosing 'parallel'" } */
+ w++; /* { dg-bogus "'w' not specified in enclosing 'parallel'" } */
+ x++; /* { dg-error "'x' not specified in enclosing 'parallel'" } */
+ z++; /* { dg-error "'z' not specified in enclosing 'parallel'" } */
+ }
+}
diff --git a/gcc/testsuite/c-c++-common/gomp/default-3.c b/gcc/testsuite/c-c++-common/gomp/default-3.c
new file mode 100644
index 0000000..a742a71
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/gomp/default-3.c
@@ -0,0 +1,14 @@
+void
+foo (void)
+{
+ int i;
+ #pragma omp task default(copyprivate) /* { dg-error "expected 'none', 'shared', 'private' or 'firstprivate' before 'copyprivate'" } */
+ ;
+ #pragma omp taskloop default(copyprivate) /* { dg-error "expected 'none', 'shared', 'private' or 'firstprivate' before 'copyprivate'" } */
+ for (i = 0; i < 64; i++)
+ ;
+ #pragma omp teams default(copyprivate) /* { dg-error "expected 'none', 'shared', 'private' or 'firstprivate' before 'copyprivate'" } */
+ ;
+ #pragma omp parallel default(copyprivate) /* { dg-error "expected 'none', 'shared', 'private' or 'firstprivate' before 'copyprivate'" } */
+ ;
+}
diff --git a/gcc/testsuite/g++.dg/gomp/default-1.C b/gcc/testsuite/g++.dg/gomp/default-1.C
new file mode 100644
index 0000000..e39df12
--- /dev/null
+++ b/gcc/testsuite/g++.dg/gomp/default-1.C
@@ -0,0 +1,112 @@
+namespace N
+{
+ int x;
+ extern int z;
+}
+
+struct S
+{
+ static int s;
+};
+
+#if __cpp_variable_templates >= 201304
+template <int N>
+int t = N;
+#endif
+
+void
+foo (void)
+{
+ int y = 0, i;
+ static int w;
+ #pragma omp task default(firstprivate) /* { dg-message "note: enclosing 'task'" } */
+ {
+ y++; /* { dg-bogus "'y' not specified in enclosing 'task'" } */
+ w++; /* { dg-bogus "'w' not specified in enclosing 'task'" } */
+ S::s++; /* { dg-bogus "'S::s' not specified in enclosing 'task'" } */
+ N::x++; /* { dg-error "'x' not specified in enclosing 'task'" } */
+ N::z++; /* { dg-error "'z' not specified in enclosing 'task'" } */
+#if __cpp_variable_templates >= 201304
+ t<5>++; /* { dg-error "'t' not specified in enclosing 'task'" "" { target c++14 } } */
+#endif
+ }
+ #pragma omp taskloop default(firstprivate) /* { dg-message "note: enclosing 'taskloop'" } */
+ for (i = 0; i < 64; i++)
+ {
+ y++; /* { dg-bogus "'y' not specified in enclosing 'taskloop'" } */
+ w++; /* { dg-bogus "'w' not specified in enclosing 'taskloop'" } */
+ S::s++; /* { dg-bogus "'S::s' not specified in enclosing 'taskloop'" } */
+ N::x++; /* { dg-error "'x' not specified in enclosing 'taskloop'" } */
+ N::z++; /* { dg-error "'z' not specified in enclosing 'taskloop'" } */
+#if __cpp_variable_templates >= 201304
+ t<5>++; /* { dg-error "'t' not specified in enclosing 'taskloop'" "" { target c++14 } } */
+#endif
+ }
+ #pragma omp teams default(firstprivate) /* { dg-message "note: enclosing 'teams'" } */
+ {
+ y++; /* { dg-bogus "'y' not specified in enclosing 'teams'" } */
+ w++; /* { dg-bogus "'w' not specified in enclosing 'teams'" } */
+ S::s++; /* { dg-bogus "'S::s' not specified in enclosing 'teams'" } */
+ N::x++; /* { dg-error "'x' not specified in enclosing 'teams'" } */
+ N::z++; /* { dg-error "'z' not specified in enclosing 'teams'" } */
+#if __cpp_variable_templates >= 201304
+ t<5>++; /* { dg-error "'t' not specified in enclosing 'teams'" "" { target c++14 } } */
+#endif
+ }
+ #pragma omp parallel default(firstprivate) /* { dg-message "note: enclosing 'parallel'" } */
+ {
+ y++; /* { dg-bogus "'y' not specified in enclosing 'parallel'" } */
+ w++; /* { dg-bogus "'w' not specified in enclosing 'parallel'" } */
+ S::s++; /* { dg-bogus "'S::s' not specified in enclosing 'parallel'" } */
+ N::x++; /* { dg-error "'x' not specified in enclosing 'parallel'" } */
+ N::z++; /* { dg-error "'z' not specified in enclosing 'parallel'" } */
+#if __cpp_variable_templates >= 201304
+ t<5>++; /* { dg-error "'t' not specified in enclosing 'parallel'" "" { target c++14 } } */
+#endif
+ }
+ #pragma omp task default(private) /* { dg-message "note: enclosing 'task'" } */
+ {
+ y = 1; /* { dg-bogus "'y' not specified in enclosing 'task'" } */
+ w = 1; /* { dg-bogus "'w' not specified in enclosing 'task'" } */
+ S::s = 1; /* { dg-bogus "'S::s' not specified in enclosing 'task'" } */
+ N::x++; /* { dg-error "'x' not specified in enclosing 'task'" } */
+ N::z++; /* { dg-error "'z' not specified in enclosing 'task'" } */
+#if __cpp_variable_templates >= 201304
+ t<5>++; /* { dg-error "'t' not specified in enclosing 'task'" "" { target c++14 } } */
+#endif
+ }
+ #pragma omp taskloop default(private) /* { dg-message "note: enclosing 'taskloop'" } */
+ for (i = 0; i < 64; i++)
+ {
+ y = 1; /* { dg-bogus "'y' not specified in enclosing 'taskloop'" } */
+ w = 1; /* { dg-bogus "'w' not specified in enclosing 'taskloop'" } */
+ S::s = 1; /* { dg-bogus "'S::s' not specified in enclosing 'taskloop'" } */
+ N::x++; /* { dg-error "'x' not specified in enclosing 'taskloop'" } */
+ N::z++; /* { dg-error "'z' not specified in enclosing 'taskloop'" } */
+#if __cpp_variable_templates >= 201304
+ t<5>++; /* { dg-error "'t' not specified in enclosing 'taskloop'" "" { target c++14 } } */
+#endif
+ }
+ #pragma omp teams default(private) /* { dg-message "note: enclosing 'teams'" } */
+ {
+ y = 1; /* { dg-bogus "'y' not specified in enclosing 'teams'" } */
+ w = 1; /* { dg-bogus "'w' not specified in enclosing 'teams'" } */
+ S::s = 1; /* { dg-bogus "'S::s' not specified in enclosing 'teams'" } */
+ N::x++; /* { dg-error "'x' not specified in enclosing 'teams'" } */
+ N::z++; /* { dg-error "'z' not specified in enclosing 'teams'" } */
+#if __cpp_variable_templates >= 201304
+ t<5>++; /* { dg-error "'t' not specified in enclosing 'teams'" "" { target c++14 } } */
+#endif
+ }
+ #pragma omp parallel default(private) /* { dg-message "note: enclosing 'parallel'" } */
+ {
+ y = 1; /* { dg-bogus "'y' not specified in enclosing 'parallel'" } */
+ w = 1; /* { dg-bogus "'w' not specified in enclosing 'parallel'" } */
+ S::s = 1; /* { dg-bogus "'S::s' not specified in enclosing 'parallel'" } */
+ N::x++; /* { dg-error "'x' not specified in enclosing 'parallel'" } */
+ N::z++; /* { dg-error "'z' not specified in enclosing 'parallel'" } */
+#if __cpp_variable_templates >= 201304
+ t<5>++; /* { dg-error "'t' not specified in enclosing 'parallel'" "" { target c++14 } } */
+#endif
+ }
+}