From: Jakub Jelinek Date: Tue, 16 Jun 2020 14:30:05 +0000 (+0200) Subject: openmp: Diagnose invalid OpenMP schedule(simd, static) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=fab46c5df7500f2ce640f98320d47a19d3de8a2f;p=gcc.git openmp: Diagnose invalid OpenMP schedule(simd, static) 2020-06-16 Jakub Jelinek gcc/c/ * c-parser.c (c_parser_omp_clause_schedule): Reject modifier separated from kind by comma rather than colon. gcc/cp/ * parser.c (cp_parser_omp_clause_schedule): Reject modifier separated from kind by comma rather than colon. gcc/testsuite/ * c-c++-common/gomp/schedule-modifiers-2.c: New test. --- diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index df0b59f9f95..fea6a09f771 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -14782,6 +14782,7 @@ c_parser_omp_clause_schedule (c_parser *parser, tree list) c = build_omp_clause (loc, OMP_CLAUSE_SCHEDULE); + location_t comma = UNKNOWN_LOCATION; while (c_parser_next_token_is (parser, CPP_NAME)) { tree kind = c_parser_peek_token (parser)->value; @@ -14794,16 +14795,22 @@ c_parser_omp_clause_schedule (c_parser *parser, tree list) modifiers |= OMP_CLAUSE_SCHEDULE_NONMONOTONIC; else break; + comma = UNKNOWN_LOCATION; c_parser_consume_token (parser); if (nmodifiers++ == 0 && c_parser_next_token_is (parser, CPP_COMMA)) - c_parser_consume_token (parser); + { + comma = c_parser_peek_token (parser)->location; + c_parser_consume_token (parser); + } else { c_parser_require (parser, CPP_COLON, "expected %<:%>"); break; } } + if (comma != UNKNOWN_LOCATION) + error_at (comma, "expected %<:%>"); if ((modifiers & (OMP_CLAUSE_SCHEDULE_MONOTONIC | OMP_CLAUSE_SCHEDULE_NONMONOTONIC)) diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 799f310bcee..69839baa712 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -35864,6 +35864,7 @@ cp_parser_omp_clause_schedule (cp_parser *parser, tree list, location_t location c = build_omp_clause (location, OMP_CLAUSE_SCHEDULE); + location_t comma = UNKNOWN_LOCATION; while (cp_lexer_next_token_is (parser->lexer, CPP_NAME)) { tree id = cp_lexer_peek_token (parser->lexer)->u.value; @@ -35876,16 +35877,22 @@ cp_parser_omp_clause_schedule (cp_parser *parser, tree list, location_t location modifiers |= OMP_CLAUSE_SCHEDULE_NONMONOTONIC; else break; + comma = UNKNOWN_LOCATION; cp_lexer_consume_token (parser->lexer); if (nmodifiers++ == 0 && cp_lexer_next_token_is (parser->lexer, CPP_COMMA)) - cp_lexer_consume_token (parser->lexer); + { + comma = cp_lexer_peek_token (parser->lexer)->location; + cp_lexer_consume_token (parser->lexer); + } else { cp_parser_require (parser, CPP_COLON, RT_COLON); break; } } + if (comma != UNKNOWN_LOCATION) + error_at (comma, "expected %<:%>"); if (cp_lexer_next_token_is (parser->lexer, CPP_NAME)) { diff --git a/gcc/testsuite/c-c++-common/gomp/schedule-modifiers-2.c b/gcc/testsuite/c-c++-common/gomp/schedule-modifiers-2.c new file mode 100644 index 00000000000..79d7d432450 --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/schedule-modifiers-2.c @@ -0,0 +1,14 @@ +void +foo (void) +{ + int i = 0; + #pragma omp for simd schedule(simd, static) /* { dg-error "expected ':'" } */ + for (i = 0; i < 16; i++) + ; + #pragma omp for simd schedule(monotonic, dynamic) /* { dg-error "expected ':'" } */ + for (i = 0; i < 16; i++) + ; + #pragma omp for simd schedule(nonmonotonic, guided, 1) /* { dg-error "expected ':'" } */ + for (i = 0; i < 16; i++) + ; +}