aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorTobias Burnus <tobias@codesourcery.com>2020-07-21 18:29:53 +0200
committerTobias Burnus <tobias@codesourcery.com>2020-07-22 09:57:15 +0200
commitc7c24828cfa4983ebc6744be3f913d0da6ff7163 (patch)
treea8de602e795da9f5bac1ff2dcc94a1a4fd016876 /gcc/cp
parentfb1de6a8543f4d7a63149bf99b54037315b8c3bb (diff)
downloadgcc-c7c24828cfa4983ebc6744be3f913d0da6ff7163.zip
gcc-c7c24828cfa4983ebc6744be3f913d0da6ff7163.tar.gz
gcc-c7c24828cfa4983ebc6744be3f913d0da6ff7163.tar.bz2
OpenMP: Fixes for omp critical + hint
gcc/c-family/ChangeLog: * c-omp.c (c_finish_omp_critical): Check for no name but nonzero hint provided. gcc/c/ChangeLog: * c-parser.c (c_parser_omp_clause_hint): Require nonnegative hint clause. (c_parser_omp_critical): Permit hint(0) clause without named critical. (c_parser_omp_construct): Don't assert if error_mark_node is returned. gcc/cp/ChangeLog: * parser.c (cp_parser_omp_clause_hint): Require nonnegative hint. (cp_parser_omp_critical): Permit hint(0) clause without named critical. * pt.c (tsubst_expr): Re-check the latter for templates. gcc/fortran/ChangeLog: * openmp.c (gfc_match_omp_critical): Fix handling hints; permit hint clause without named critical. (resolve_omp_clauses): Require nonnegative constant integer for the hint clause. (gfc_resolve_omp_directive): Check for no name but nonzero value for hint clause. * parse.c (parse_omp_structured_block): Fix same-name check for critical. * trans-openmp.c (gfc_trans_omp_critical): Handle hint clause properly. libgomp/ChangeLog: * omp_lib.f90.in: Add omp_sync_hint_* and omp_sync_hint_kind. * omp_lib.h.in: Likewise. gcc/testsuite/ChangeLog: * g++.dg/gomp/critical-3.C: Add nameless critical with hint testcase. * c-c++-common/gomp/critical-hint-1.c: New test. * c-c++-common/gomp/critical-hint-2.c: New test. * gfortran.dg/gomp/critical-hint-1.f90: New test. * gfortran.dg/gomp/critical-hint-2.f90: New test.
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/parser.c20
-rw-r--r--gcc/cp/pt.c9
2 files changed, 22 insertions, 7 deletions
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 5a2d73d..0c77c20 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -35383,12 +35383,21 @@ cp_parser_omp_clause_hint (cp_parser *parser, tree list, location_t location)
t = cp_parser_assignment_expression (parser);
+ if (t != error_mark_node)
+ {
+ t = fold_non_dependent_expr (t);
+ if (!value_dependent_expression_p (t)
+ && (!INTEGRAL_TYPE_P (TREE_TYPE (t))
+ || !tree_fits_shwi_p (t)
+ || tree_int_cst_sgn (t) == -1))
+ error_at (location, "expected constant integer expression with "
+ "valid sync-hint value");
+ }
if (t == error_mark_node
|| !parens.require_close (parser))
cp_parser_skip_to_closing_parenthesis (parser, /*recovering=*/true,
/*or_comma=*/false,
/*consume_paren=*/true);
-
check_no_duplicate_clause (list, OMP_CLAUSE_HINT, "hint", location);
c = build_omp_clause (location, OMP_CLAUSE_HINT);
@@ -38210,13 +38219,10 @@ cp_parser_omp_critical (cp_parser *parser, cp_token *pragma_tok, bool *if_p)
if (cp_lexer_next_token_is (parser->lexer, CPP_COMMA)
&& cp_lexer_nth_token_is (parser->lexer, 2, CPP_NAME))
cp_lexer_consume_token (parser->lexer);
-
- clauses = cp_parser_omp_all_clauses (parser,
- OMP_CRITICAL_CLAUSE_MASK,
- "#pragma omp critical", pragma_tok);
}
- else
- cp_parser_require_pragma_eol (parser, pragma_tok);
+
+ clauses = cp_parser_omp_all_clauses (parser, OMP_CRITICAL_CLAUSE_MASK,
+ "#pragma omp critical", pragma_tok);
stmt = cp_parser_omp_structured_block (parser, if_p);
return c_finish_omp_critical (input_location, stmt, name, clauses);
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index f9e80e5..d9db44f 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -18531,6 +18531,15 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl,
stmt = pop_stmt_list (stmt);
}
+ if (TREE_CODE (t) == OMP_CRITICAL
+ && tmp != NULL_TREE
+ && integer_nonzerop (OMP_CLAUSE_HINT_EXPR (tmp)))
+ {
+ error_at (OMP_CLAUSE_LOCATION (tmp),
+ "%<#pragma omp critical%> with %<hint%> clause requires "
+ "a name, except when %<omp_sync_hint_none%> is used");
+ RETURN (error_mark_node);
+ }
t = copy_node (t);
OMP_BODY (t) = stmt;
OMP_CLAUSES (t) = tmp;