Hi! As mentioned recently, in OpenMP 5.0 the general rule is that the grammar has assignment-expressions inside of clauses, unless otherwise specified (e.g. in array sections, array shape operator).
In some cases we were already doing that, in other cases we parsed expression non-terminal instead, in other cases what is accepted in if condition. This changes it to match the standard. Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk. Thomas, if OpenACC needs in some case do something different, we'll need is_omp arguments where the same parsing routine is used for both. And, I haven't touched any of the OpenACC-only parsing routines. 2018-11-09 Jakub Jelinek <ja...@redhat.com> c/ * c-parser.c (c_parser_omp_clause_final): Use c_parser_expr_no_commas, convert_lvalue_to_rvalue, c_objc_common_truthvalue_conversion, c_fully_fold and parentheses parsing instead of c_parser_paren_condition. (c_parser_omp_clause_if): Use c_parser_expr_no_commas, convert_lvalue_to_rvalue, c_objc_common_truthvalue_conversion and c_fully_fold instead of c_parser_condition. (c_parser_omp_clause_num_threads, c_parser_omp_clause_num_tasks, c_parser_omp_clause_grainsize, c_parser_omp_clause_priority, c_parser_omp_clause_hint, c_parser_omp_clause_num_teams, c_parser_omp_clause_thread_limit, c_parser_omp_clause_linear): Use c_parser_expr_no_commas instead of c_parser_expression. cp/ * parser.c (cp_parser_omp_clause_final, cp_parser_omp_clause_if): Use cp_parser_assignment_expression instead of cp_parser_condition. (cp_parser_omp_clause_num_threads, cp_parser_omp_clause_num_tasks, cp_parser_omp_clause_grainsize, cp_parser_omp_clause_priority, cp_parser_omp_clause_num_teams, cp_parser_omp_clause_thread_limit, cp_parser_omp_clause_linear, cp_parser_omp_clause_device): Use cp_parser_assignment_expression instead of cp_parser_expression. (cp_parser_omp_clause_hint): Likewise. Formatting fix. testsuite/ * c-c++-common/gomp/clauses-5.c: New test. --- gcc/c/c-parser.c.jj 2018-11-09 17:17:05.454216557 +0100 +++ gcc/c/c-parser.c 2018-11-09 19:32:49.210991843 +0100 @@ -12184,8 +12184,19 @@ c_parser_omp_clause_final (c_parser *par location_t loc = c_parser_peek_token (parser)->location; if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) { - tree t = c_parser_paren_condition (parser); - tree c; + matching_parens parens; + tree t, c; + if (!parens.require_open (parser)) + t = error_mark_node; + else + { + location_t eloc = c_parser_peek_token (parser)->location; + c_expr expr = c_parser_expr_no_commas (parser, NULL); + t = convert_lvalue_to_rvalue (eloc, expr, true, true).value; + t = c_objc_common_truthvalue_conversion (eloc, t); + t = c_fully_fold (t, false, NULL); + parens.skip_until_found_close (parser); + } check_no_duplicate_clause (list, OMP_CLAUSE_FINAL, "final"); @@ -12305,7 +12316,11 @@ c_parser_omp_clause_if (c_parser *parser } } - tree t = c_parser_condition (parser), c; + location_t loc = c_parser_peek_token (parser)->location; + c_expr expr = c_parser_expr_no_commas (parser, NULL); + expr = convert_lvalue_to_rvalue (loc, expr, true, true); + tree t = c_objc_common_truthvalue_conversion (loc, expr.value), c; + t = c_fully_fold (t, false, NULL); parens.skip_until_found_close (parser); for (c = list; c ; c = OMP_CLAUSE_CHAIN (c)) @@ -12440,7 +12455,7 @@ c_parser_omp_clause_num_threads (c_parse if (parens.require_open (parser)) { location_t expr_loc = c_parser_peek_token (parser)->location; - c_expr expr = c_parser_expression (parser); + c_expr expr = c_parser_expr_no_commas (parser, NULL); expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true); tree c, t = expr.value; t = c_fully_fold (t, false, NULL); @@ -12486,7 +12501,7 @@ c_parser_omp_clause_num_tasks (c_parser if (parens.require_open (parser)) { location_t expr_loc = c_parser_peek_token (parser)->location; - c_expr expr = c_parser_expression (parser); + c_expr expr = c_parser_expr_no_commas (parser, NULL); expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true); tree c, t = expr.value; t = c_fully_fold (t, false, NULL); @@ -12532,7 +12547,7 @@ c_parser_omp_clause_grainsize (c_parser if (parens.require_open (parser)) { location_t expr_loc = c_parser_peek_token (parser)->location; - c_expr expr = c_parser_expression (parser); + c_expr expr = c_parser_expr_no_commas (parser, NULL); expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true); tree c, t = expr.value; t = c_fully_fold (t, false, NULL); @@ -12578,7 +12593,7 @@ c_parser_omp_clause_priority (c_parser * if (parens.require_open (parser)) { location_t expr_loc = c_parser_peek_token (parser)->location; - c_expr expr = c_parser_expression (parser); + c_expr expr = c_parser_expr_no_commas (parser, NULL); expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true); tree c, t = expr.value; t = c_fully_fold (t, false, NULL); @@ -12625,7 +12640,7 @@ c_parser_omp_clause_hint (c_parser *pars if (parens.require_open (parser)) { location_t expr_loc = c_parser_peek_token (parser)->location; - c_expr expr = c_parser_expression (parser); + c_expr expr = c_parser_expr_no_commas (parser, NULL); expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true); tree c, t = expr.value; t = c_fully_fold (t, false, NULL); @@ -13646,7 +13661,7 @@ c_parser_omp_clause_num_teams (c_parser if (parens.require_open (parser)) { location_t expr_loc = c_parser_peek_token (parser)->location; - c_expr expr = c_parser_expression (parser); + c_expr expr = c_parser_expr_no_commas (parser, NULL); expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true); tree c, t = expr.value; t = c_fully_fold (t, false, NULL); @@ -13691,7 +13706,7 @@ c_parser_omp_clause_thread_limit (c_pars if (parens.require_open (parser)) { location_t expr_loc = c_parser_peek_token (parser)->location; - c_expr expr = c_parser_expression (parser); + c_expr expr = c_parser_expr_no_commas (parser, NULL); expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true); tree c, t = expr.value; t = c_fully_fold (t, false, NULL); @@ -13812,7 +13827,7 @@ c_parser_omp_clause_linear (c_parser *pa { c_parser_consume_token (parser); location_t expr_loc = c_parser_peek_token (parser)->location; - c_expr expr = c_parser_expression (parser); + c_expr expr = c_parser_expr_no_commas (parser, NULL); expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true); step = expr.value; step = c_fully_fold (step, false, NULL); --- gcc/cp/parser.c.jj 2018-11-09 17:18:47.887528746 +0100 +++ gcc/cp/parser.c 2018-11-09 19:12:18.053290351 +0100 @@ -32469,7 +32469,7 @@ cp_parser_omp_clause_final (cp_parser *p if (!parens.require_open (parser)) return list; - t = cp_parser_condition (parser); + t = cp_parser_assignment_expression (parser); if (t == error_mark_node || !parens.require_close (parser)) @@ -32592,7 +32592,7 @@ cp_parser_omp_clause_if (cp_parser *pars } } - t = cp_parser_condition (parser); + t = cp_parser_assignment_expression (parser); if (t == error_mark_node || !parens.require_close (parser)) @@ -32696,7 +32696,7 @@ cp_parser_omp_clause_num_threads (cp_par if (!parens.require_open (parser)) return list; - t = cp_parser_expression (parser); + t = cp_parser_assignment_expression (parser); if (t == error_mark_node || !parens.require_close (parser)) @@ -32727,7 +32727,7 @@ cp_parser_omp_clause_num_tasks (cp_parse if (!parens.require_open (parser)) return list; - t = cp_parser_expression (parser); + t = cp_parser_assignment_expression (parser); if (t == error_mark_node || !parens.require_close (parser)) @@ -32758,7 +32758,7 @@ cp_parser_omp_clause_grainsize (cp_parse if (!parens.require_open (parser)) return list; - t = cp_parser_expression (parser); + t = cp_parser_assignment_expression (parser); if (t == error_mark_node || !parens.require_close (parser)) @@ -32789,7 +32789,7 @@ cp_parser_omp_clause_priority (cp_parser if (!parens.require_open (parser)) return list; - t = cp_parser_expression (parser); + t = cp_parser_assignment_expression (parser); if (t == error_mark_node || !parens.require_close (parser)) @@ -32811,8 +32811,7 @@ cp_parser_omp_clause_priority (cp_parser hint ( expression ) */ static tree -cp_parser_omp_clause_hint (cp_parser *parser, tree list, - location_t location) +cp_parser_omp_clause_hint (cp_parser *parser, tree list, location_t location) { tree t, c; @@ -32820,7 +32819,7 @@ cp_parser_omp_clause_hint (cp_parser *pa if (!parens.require_open (parser)) return list; - t = cp_parser_expression (parser); + t = cp_parser_assignment_expression (parser); if (t == error_mark_node || !parens.require_close (parser)) @@ -33442,7 +33441,7 @@ cp_parser_omp_clause_num_teams (cp_parse if (!parens.require_open (parser)) return list; - t = cp_parser_expression (parser); + t = cp_parser_assignment_expression (parser); if (t == error_mark_node || !parens.require_close (parser)) @@ -33473,7 +33472,7 @@ cp_parser_omp_clause_thread_limit (cp_pa if (!parens.require_open (parser)) return list; - t = cp_parser_expression (parser); + t = cp_parser_assignment_expression (parser); if (t == error_mark_node || !parens.require_close (parser)) @@ -33641,7 +33640,7 @@ cp_parser_omp_clause_linear (cp_parser * step = NULL_TREE; } if (!step) - step = cp_parser_expression (parser); + step = cp_parser_assignment_expression (parser); if (!parens.require_close (parser)) cp_parser_skip_to_closing_parenthesis (parser, /*recovering=*/true, @@ -34151,7 +34150,7 @@ cp_parser_omp_clause_device (cp_parser * if (!parens.require_open (parser)) return list; - t = cp_parser_expression (parser); + t = cp_parser_assignment_expression (parser); if (t == error_mark_node || !parens.require_close (parser)) --- gcc/testsuite/c-c++-common/gomp/clauses-5.c.jj 2018-11-09 19:26:09.873576544 +0100 +++ gcc/testsuite/c-c++-common/gomp/clauses-5.c 2018-11-09 19:25:51.276883134 +0100 @@ -0,0 +1,52 @@ +void +foo (int *p) +{ + int i, j = 0; + #pragma omp parallel if (2, 1) /* { dg-error "expected" } */ + ; + #pragma omp parallel num_threads (3, 4) /* { dg-error "expected" } */ + ; + #pragma omp teams num_teams (4, 5) /* { dg-error "expected" } */ + ; + #pragma omp teams thread_limit (6, 7) /* { dg-error "expected" } */ + ; + #pragma omp for linear (j : 8, 9) /* { dg-error "expected" } */ + for (i = 0; i < 30; i++) + j += (8, 9); + #pragma omp for schedule (static, 3, 4) /* { dg-error "expected" } */ + for (i = 0; i < 30; i++) + ; + #pragma omp for collapse (1, 1) /* { dg-error "expected" } */ + for (i = 0; i < 30; i++) + ; + #pragma omp for ordered (1, 1) /* { dg-error "expected" } */ + for (i = 0; i < 30; i++) + ; + #pragma omp simd safelen (3, 4) /* { dg-error "expected" } */ + for (i = 0; i < 30; i++) + ; + #pragma omp simd simdlen (4, 8) /* { dg-error "expected" } */ + for (i = 0; i < 30; i++) + ; + #pragma omp simd aligned (p: 4, 8) /* { dg-error "expected" } */ + for (i = 0; i < 30; i++) + ; + #pragma omp teams + #pragma omp distribute dist_schedule (static, 6, 7) /* { dg-error "expected" } */ + for (i = 0; i < 30; i++) + ; + #pragma omp task final (8, 1) /* { dg-error "expected" } */ + ; + #pragma omp task priority (2, 3) /* { dg-error "expected" } */ + ; + #pragma omp taskloop grainsize (4, 5) /* { dg-error "expected" } */ + for (i = 0; i < 30; i++) + ; + #pragma omp taskloop num_tasks (5, 6) /* { dg-error "expected" } */ + for (i = 0; i < 30; i++) + ; + #pragma omp target device (5, 1) /* { dg-error "expected" } */ + ; + #pragma omp critical (baz) hint (2, 3) /* { dg-error "expected" } */ + ; +} Jakub