From bb522e2eea23703375e65a044c93e8144ef4664e Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Fri, 9 Aug 2019 09:24:51 +0200 Subject: [PATCH] c-parser.c (check_no_duplicate_clause): Simplify using omp_find_clause. c/ * c-parser.c (check_no_duplicate_clause): Simplify using omp_find_clause. (c_parser_omp_clause_if): Fix up printing of target {enter,exit} data directive name modifiers. (c_parser_omp_clause_proc_bind): Check for duplicate proc_bind clause. cp/ * parser.c (check_no_duplicate_clause): Simplify using omp_find_clause. (cp_parser_omp_clause_if): Fix up printing of target {enter,exit} data directive name modifiers. testsuite/ * c-c++-common/gomp/if-4.c: New test. * c-c++-common/gomp/clause-dups-1.c: New test. From-SVN: r274227 --- gcc/c/ChangeLog | 6 + gcc/c/c-parser.c | 16 +- gcc/cp/ChangeLog | 5 + gcc/cp/parser.c | 14 +- gcc/testsuite/ChangeLog | 3 + .../c-c++-common/gomp/clause-dups-1.c | 222 ++++++++++++++++++ gcc/testsuite/c-c++-common/gomp/if-4.c | 60 +++++ 7 files changed, 305 insertions(+), 21 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/gomp/clause-dups-1.c create mode 100644 gcc/testsuite/c-c++-common/gomp/if-4.c diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 5363f1c8510..816c3e07f27 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,5 +1,11 @@ 2019-08-09 Jakub Jelinek + * c-parser.c (check_no_duplicate_clause): Simplify using + omp_find_clause. + (c_parser_omp_clause_if): Fix up printing of target {enter,exit} data + directive name modifiers. + (c_parser_omp_clause_proc_bind): Check for duplicate proc_bind clause. + PR c/91401 * c-parser.c (c_parser_omp_clause_dist_schedule): Fix up typos in the check_no_duplicate_clause call. Comment it out, instead emit a diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index 9585ba2ca67..055e6500333 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -11898,15 +11898,8 @@ static void check_no_duplicate_clause (tree clauses, enum omp_clause_code code, const char *name) { - tree c; - - for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c)) - if (OMP_CLAUSE_CODE (c) == code) - { - location_t loc = OMP_CLAUSE_LOCATION (c); - error_at (loc, "too many %qs clauses", name); - break; - } + if (tree c = omp_find_clause (clauses, code)) + error_at (OMP_CLAUSE_LOCATION (c), "too many %qs clauses", name); } /* OpenACC 2.0 @@ -12616,8 +12609,8 @@ c_parser_omp_clause_if (c_parser *parser, tree list, bool is_omp) case OMP_TARGET_DATA: p = "target data"; break; case OMP_TARGET: p = "target"; break; case OMP_TARGET_UPDATE: p = "target update"; break; - case OMP_TARGET_ENTER_DATA: p = "enter data"; break; - case OMP_TARGET_EXIT_DATA: p = "exit data"; break; + case OMP_TARGET_ENTER_DATA: p = "target enter data"; break; + case OMP_TARGET_EXIT_DATA: p = "target exit data"; break; default: gcc_unreachable (); } error_at (location, "too many % clauses with %qs modifier", @@ -14856,6 +14849,7 @@ c_parser_omp_clause_proc_bind (c_parser *parser, tree list) else goto invalid_kind; + check_no_duplicate_clause (list, OMP_CLAUSE_PROC_BIND, "proc_bind"); c_parser_consume_token (parser); parens.skip_until_found_close (parser); c = build_omp_clause (clause_loc, OMP_CLAUSE_PROC_BIND); diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 93b6e5ac27b..2e7909dd51c 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,10 @@ 2019-08-09 Jakub Jelinek + * parser.c (check_no_duplicate_clause): Simplify using + omp_find_clause. + (cp_parser_omp_clause_if): Fix up printing of target {enter,exit} data + directive name modifiers. + PR c/91401 * parser.c (cp_parser_omp_clause_dist_schedule): Comment out the check_no_duplicate_clause call, instead emit a warning for duplicate diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index a2efb551617..b5196f6184b 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -32684,14 +32684,8 @@ static void check_no_duplicate_clause (tree clauses, enum omp_clause_code code, const char *name, location_t location) { - tree c; - - for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c)) - if (OMP_CLAUSE_CODE (c) == code) - { - error_at (location, "too many %qs clauses", name); - break; - } + if (omp_find_clause (clauses, code)) + error_at (location, "too many %qs clauses", name); } /* OpenMP 2.5: @@ -33581,8 +33575,8 @@ cp_parser_omp_clause_if (cp_parser *parser, tree list, location_t location, case OMP_TARGET_DATA: p = "target data"; break; case OMP_TARGET: p = "target"; break; case OMP_TARGET_UPDATE: p = "target update"; break; - case OMP_TARGET_ENTER_DATA: p = "enter data"; break; - case OMP_TARGET_EXIT_DATA: p = "exit data"; break; + case OMP_TARGET_ENTER_DATA: p = "target enter data"; break; + case OMP_TARGET_EXIT_DATA: p = "target exit data"; break; default: gcc_unreachable (); } error_at (location, "too many % clauses with %qs modifier", diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f67c3101628..a31e2613dff 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2019-08-09 Jakub Jelinek + * c-c++-common/gomp/if-4.c: New test. + * c-c++-common/gomp/clause-dups-1.c: New test. + PR c/91401 * c-c++-common/gomp/pr91401-1.c: New test. * c-c++-common/gomp/pr91401-2.c: New test. diff --git a/gcc/testsuite/c-c++-common/gomp/clause-dups-1.c b/gcc/testsuite/c-c++-common/gomp/clause-dups-1.c new file mode 100644 index 00000000000..3dde0589f7c --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/clause-dups-1.c @@ -0,0 +1,222 @@ +void f0 (void); + +void +f1 (int *p) +{ + int i; + #pragma omp parallel proc_bind (master) proc_bind (master) /* { dg-error "too many 'proc_bind' clauses" } */ + f0 (); + #pragma omp parallel proc_bind (close) proc_bind (spread) /* { dg-error "too many 'proc_bind' clauses" } */ + f0 (); + #pragma omp for schedule(static) schedule(static) /* { dg-error "too many 'schedule' clauses" } */ + for (i = 0; i < 8; ++i) + f0 (); + #pragma omp for schedule(dynamic,5) schedule(runtime) /* { dg-error "too many 'schedule' clauses" } */ + for (i = 0; i < 8; ++i) + f0 (); + #pragma omp for collapse(1) collapse(1) /* { dg-error "too many 'collapse' clauses" } */ + for (i = 0; i < 8; ++i) + f0 (); + #pragma omp for collapse(1) collapse(2) /* { dg-error "too many 'collapse' clauses" } */ + for (i = 0; i < 8; ++i) + f0 (); + #pragma omp for ordered ordered /* { dg-error "too many 'ordered' clauses" } */ + for (i = 0; i < 8; ++i) + f0 (); + #pragma omp for ordered(1) ordered(1) /* { dg-error "too many 'ordered' clauses" } */ + for (i = 0; i < 8; ++i) + f0 (); + #pragma omp for nowait nowait /* { dg-error "too many 'nowait' clauses" } */ + for (i = 0; i < 8; ++i) + f0 (); + #pragma omp simd collapse(1) collapse(1) /* { dg-error "too many 'collapse' clauses" } */ + for (i = 0; i < 8; ++i) + f0 (); + #pragma omp simd collapse(1) collapse(2) /* { dg-error "too many 'collapse' clauses" } */ + for (i = 0; i < 8; ++i) + f0 (); + #pragma omp simd simdlen(1) simdlen(1) /* { dg-error "too many 'simdlen' clauses" } */ + for (i = 0; i < 8; ++i) + f0 (); + #pragma omp simd simdlen(1) simdlen(2) /* { dg-error "too many 'simdlen' clauses" } */ + for (i = 0; i < 8; ++i) + f0 (); + #pragma omp simd safelen(1) safelen(1) /* { dg-error "too many 'safelen' clauses" } */ + for (i = 0; i < 8; ++i) + f0 (); + #pragma omp simd safelen(1) safelen(2) /* { dg-error "too many 'safelen' clauses" } */ + for (i = 0; i < 8; ++i) + f0 (); + #pragma omp teams + { + #pragma omp distribute collapse(1) collapse(1) /* { dg-error "too many 'collapse' clauses" } */ + for (i = 0; i < 8; ++i) + f0 (); + #pragma omp distribute collapse(1) collapse(2) /* { dg-error "too many 'collapse' clauses" } */ + for (i = 0; i < 8; ++i) + f0 (); + } + #pragma omp teams thread_limit (3) thread_limit (3) /* { dg-error "too many 'thread_limit' clauses" } */ + f0 (); + #pragma omp teams thread_limit (3) thread_limit (5) /* { dg-error "too many 'thread_limit' clauses" } */ + f0 (); + #pragma omp teams num_teams (3) num_teams (3) /* { dg-error "too many 'num_teams' clauses" } */ + f0 (); + #pragma omp teams num_teams (3) num_teams (5) /* { dg-error "too many 'num_teams' clauses" } */ + f0 (); + #pragma omp single nowait nowait /* { dg-error "too many 'nowait' clauses" } */ + f0 (); + #pragma omp loop bind (thread) collapse(1) collapse(3) /* { dg-error "too many 'collapse' clauses" } */ + for (i = 0; i < 8; ++i) + f0 (); + #pragma omp task final (0) final (0) /* { dg-error "too many 'final' clauses" } */ + f0 (); + #pragma omp task final (0) final (1) /* { dg-error "too many 'final' clauses" } */ + f0 (); + #pragma omp task priority (1) priority (1) /* { dg-error "too many 'priority' clauses" } */ + f0 (); + #pragma omp task priority (0) priority (1) /* { dg-error "too many 'priority' clauses" } */ + f0 (); + #pragma omp taskloop final (0) final (0) /* { dg-error "too many 'final' clauses" } */ + for (i = 0; i < 8; ++i) + f0 (); + #pragma omp taskloop final (0) final (1) /* { dg-error "too many 'final' clauses" } */ + for (i = 0; i < 8; ++i) + f0 (); + #pragma omp taskloop priority (1) priority (1) /* { dg-error "too many 'priority' clauses" } */ + for (i = 0; i < 8; ++i) + f0 (); + #pragma omp taskloop priority (0) priority (1) /* { dg-error "too many 'priority' clauses" } */ + for (i = 0; i < 8; ++i) + f0 (); + #pragma omp taskloop grainsize (1) grainsize (2) /* { dg-error "too many 'grainsize' clauses" } */ + for (i = 0; i < 8; ++i) + f0 (); + #pragma omp taskloop grainsize (2) grainsize (2) /* { dg-error "too many 'grainsize' clauses" } */ + for (i = 0; i < 8; ++i) + f0 (); + #pragma omp taskloop num_tasks (1) num_tasks (2) /* { dg-error "too many 'num_tasks' clauses" } */ + for (i = 0; i < 8; ++i) + f0 (); + #pragma omp taskloop num_tasks (2) num_tasks (2) /* { dg-error "too many 'num_tasks' clauses" } */ + for (i = 0; i < 8; ++i) + f0 (); + #pragma omp taskloop num_tasks (1) grainsize (2) + for (i = 0; i < 8; ++i) + f0 (); + #pragma omp taskloop grainsize (2) num_tasks (2) + for (i = 0; i < 8; ++i) + f0 (); + #pragma omp taskloop collapse (1) collapse (1) /* { dg-error "too many 'collapse' clauses" } */ + for (i = 0; i < 8; ++i) + f0 (); + #pragma omp taskloop collapse (1) collapse (2) /* { dg-error "too many 'collapse' clauses" } */ + for (i = 0; i < 8; ++i) + f0 (); + #pragma omp target data device (1) device (1) map (alloc: i) /* { dg-error "too many 'device' clauses" } */ + f0 (); + #pragma omp target enter data device (1) device (1) map (to: i) /* { dg-error "too many 'device' clauses" } */ + #pragma omp target enter data nowait nowait map (to: i) /* { dg-error "too many 'nowait' clauses" } */ + #pragma omp target exit data device (1) device (1) map (from: i) /* { dg-error "too many 'device' clauses" } */ + #pragma omp target exit data nowait nowait map (from: i) /* { dg-error "too many 'nowait' clauses" } */ + #pragma omp target device (1) device (1) /* { dg-error "too many 'device' clauses" } */ + f0 (); + #pragma omp target nowait nowait /* { dg-error "too many 'nowait' clauses" } */ + f0 (); + #pragma omp target update device (1) device (1) to (i) /* { dg-error "too many 'device' clauses" } */ + #pragma omp target update nowait nowait to (i) /* { dg-error "too many 'nowait' clauses" } */ + #pragma omp atomic seq_cst seq_cst /* { dg-error "too many memory order clauses" } */ + p[0]++; + #pragma omp atomic release release /* { dg-error "too many memory order clauses" } */ + p[0]++; + #pragma omp atomic relaxed relaxed /* { dg-error "too many memory order clauses" } */ + p[0]++; + #pragma omp atomic seq_cst release /* { dg-error "too many memory order clauses" } */ + p[0]++; + #pragma omp atomic release relaxed /* { dg-error "too many memory order clauses" } */ + p[0]++; + #pragma omp atomic relaxed seq_cst /* { dg-error "too many memory order clauses" } */ + p[0]++; + #pragma omp atomic hint(0) hint(0) /* { dg-error "too many 'hint' clauses" } */ + p[0]++; + #pragma omp atomic update seq_cst seq_cst /* { dg-error "too many memory order clauses" } */ + p[0]++; + #pragma omp atomic update release release /* { dg-error "too many memory order clauses" } */ + p[0]++; + #pragma omp atomic update relaxed relaxed /* { dg-error "too many memory order clauses" } */ + p[0]++; + #pragma omp atomic update seq_cst release /* { dg-error "too many memory order clauses" } */ + p[0]++; + #pragma omp atomic update release relaxed /* { dg-error "too many memory order clauses" } */ + p[0]++; + #pragma omp atomic update relaxed seq_cst /* { dg-error "too many memory order clauses" } */ + p[0]++; + #pragma omp atomic update hint (0) hint(0) /* { dg-error "too many 'hint' clauses" } */ + p[0]++; + #pragma omp atomic write seq_cst seq_cst /* { dg-error "too many memory order clauses" } */ + p[0] = 0; + #pragma omp atomic write release release /* { dg-error "too many memory order clauses" } */ + p[0] = 0; + #pragma omp atomic write relaxed relaxed /* { dg-error "too many memory order clauses" } */ + p[0] = 0; + #pragma omp atomic write seq_cst release /* { dg-error "too many memory order clauses" } */ + p[0] = 0; + #pragma omp atomic write release relaxed /* { dg-error "too many memory order clauses" } */ + p[0] = 0; + #pragma omp atomic write relaxed seq_cst /* { dg-error "too many memory order clauses" } */ + p[0] = 0; + #pragma omp atomic write hint(0)hint(0) /* { dg-error "too many 'hint' clauses" } */ + p[0] = 0; + #pragma omp atomic read seq_cst seq_cst /* { dg-error "too many memory order clauses" } */ + i = p[0]; + #pragma omp atomic read acquire acquire /* { dg-error "too many memory order clauses" } */ + i = p[0]; + #pragma omp atomic read relaxed relaxed /* { dg-error "too many memory order clauses" } */ + i = p[0]; + #pragma omp atomic read seq_cst acquire /* { dg-error "too many memory order clauses" } */ + i = p[0]; + #pragma omp atomic read acquire relaxed /* { dg-error "too many memory order clauses" } */ + i = p[0]; + #pragma omp atomic read relaxed seq_cst /* { dg-error "too many memory order clauses" } */ + i = p[0]; + #pragma omp atomic read hint (0) hint(0) /* { dg-error "too many 'hint' clauses" } */ + i = p[0]; + #pragma omp atomic capture seq_cst seq_cst /* { dg-error "too many memory order clauses" } */ + i = p[0]++; + #pragma omp atomic capture acq_rel acq_rel /* { dg-error "too many memory order clauses" } */ + i = p[0]++; + #pragma omp atomic capture acquire acquire /* { dg-error "too many memory order clauses" } */ + i = p[0]++; + #pragma omp atomic capture release release /* { dg-error "too many memory order clauses" } */ + i = p[0]++; + #pragma omp atomic capture relaxed relaxed /* { dg-error "too many memory order clauses" } */ + i = p[0]++; + #pragma omp atomic capture seq_cst acq_rel /* { dg-error "too many memory order clauses" } */ + i = p[0]++; + #pragma omp atomic capture acq_rel acquire /* { dg-error "too many memory order clauses" } */ + i = p[0]++; + #pragma omp atomic capture acquire release /* { dg-error "too many memory order clauses" } */ + i = p[0]++; + #pragma omp atomic capture release relaxed /* { dg-error "too many memory order clauses" } */ + i = p[0]++; + #pragma omp atomic capture relaxed seq_cst /* { dg-error "too many memory order clauses" } */ + i = p[0]++; + #pragma omp atomic capture hint(0) hint (0) /* { dg-error "too many 'hint' clauses" } */ + i = p[0]++; + +} + +#pragma omp declare simd simdlen (4) simdlen (4) /* { dg-error "too many 'simdlen' clauses" } */ +void f2 (int a, int b); +#pragma omp declare simd simdlen (4) simdlen (8) /* { dg-error "too many 'simdlen' clauses" } */ +void f3 (int a, int b); +#pragma omp declare simd uniform (a) uniform (a) /* { dg-error "'a' appears more than once in data clauses" } */ +void f4 (int a, int b); +#pragma omp declare simd linear (a) linear (a) /* { dg-error "'a' appears more than once in data clauses" } */ +void f5 (int a, int b); +#pragma omp declare simd linear (a) linear (a:3) /* { dg-error "'a' appears more than once in data clauses" } */ +void f6 (int a, int b); +#pragma omp declare simd uniform (a) linear (a) /* { dg-error "'a' appears more than once in data clauses" } */ +void f7 (int a, int b); +#pragma omp declare simd linear (a) uniform (a) /* { dg-error "'a' appears more than once in data clauses" } */ +void f8 (int a, int b); diff --git a/gcc/testsuite/c-c++-common/gomp/if-4.c b/gcc/testsuite/c-c++-common/gomp/if-4.c new file mode 100644 index 00000000000..f374ce08643 --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/if-4.c @@ -0,0 +1,60 @@ +void f0 (void); + +void +f1 (int *p) +{ + int i; + #pragma omp task if (0) if (0) /* { dg-error "too many 'if' clauses without modifier" } */ + f0 (); + #pragma omp task if (0) if (1) /* { dg-error "too many 'if' clauses without modifier" } */ + f0 (); + #pragma omp task if (task:0) if (task:0) /* { dg-error "too many 'if' clauses with 'task' modifier" } */ + f0 (); + #pragma omp task if (task:0) if (1) /* { dg-error "if any 'if' clause has modifier, then all 'if' clauses have to use modifier" } */ + f0 (); + #pragma omp task if (0) if (task:1) /* { dg-error "if any 'if' clause has modifier, then all 'if' clauses have to use modifier" } */ + f0 (); + #pragma omp taskloop if (0) if (0) /* { dg-error "too many 'if' clauses without modifier" } */ + for (i = 0; i < 8; ++i) + f0 (); + #pragma omp taskloop if (0) if (1) /* { dg-error "too many 'if' clauses without modifier" } */ + for (i = 0; i < 8; ++i) + f0 (); + #pragma omp taskloop if (taskloop:0) if (taskloop:0) /* { dg-error "too many 'if' clauses with 'taskloop' modifier" } */ + for (i = 0; i < 8; ++i) + f0 (); + #pragma omp taskloop if (taskloop:0) if (1) /* { dg-error "if any 'if' clause has modifier, then all 'if' clauses have to use modifier" } */ + for (i = 0; i < 8; ++i) + f0 (); + #pragma omp taskloop if (0) if (taskloop:0) /* { dg-error "if any 'if' clause has modifier, then all 'if' clauses have to use modifier" } */ + for (i = 0; i < 8; ++i) + f0 (); + #pragma omp target data if (1) if (1) map (alloc: i) /* { dg-error "too many 'if' clauses without modifier" } */ + f0 (); + #pragma omp target data if (target data: 1) if (target data:0) map (alloc: i) /* { dg-error "too many 'if' clauses with 'target data' modifier" } */ + f0 (); + #pragma omp target data if (1) if (target data:0) map (alloc: i) /* { dg-error "if any 'if' clause has modifier, then all 'if' clauses have to use modifier" } */ + f0 (); + #pragma omp target data if (target data: 1) if (0) map (alloc: i) /* { dg-error "if any 'if' clause has modifier, then all 'if' clauses have to use modifier" } */ + f0 (); + #pragma omp target enter data if (1) if (1) map (to: i) /* { dg-error "too many 'if' clauses without modifier" } */ + #pragma omp target enter data if (target enter data: 1) if (target enter data:0) map (to: i) /* { dg-error "too many 'if' clauses with 'target enter data' modifier" } */ + #pragma omp target enter data if (1) if (target enter data:0) map (to: i) /* { dg-error "if any 'if' clause has modifier, then all 'if' clauses have to use modifier" } */ + #pragma omp target enter data if (target enter data: 1) if (0) map (to: i) /* { dg-error "if any 'if' clause has modifier, then all 'if' clauses have to use modifier" } */ + #pragma omp target exit data if (1) if (1) map (from: i) /* { dg-error "too many 'if' clauses without modifier" } */ + #pragma omp target exit data if (target exit data: 1) if (target exit data:0) map (from: i) /* { dg-error "too many 'if' clauses with 'target exit data' modifier" } */ + #pragma omp target exit data if (1) if (target exit data:0) map (from: i) /* { dg-error "if any 'if' clause has modifier, then all 'if' clauses have to use modifier" } */ + #pragma omp target exit data if (target exit data: 1) if (0) map (from: i) /* { dg-error "if any 'if' clause has modifier, then all 'if' clauses have to use modifier" } */ + #pragma omp target if (1) if (1) /* { dg-error "too many 'if' clauses without modifier" } */ + f0 (); + #pragma omp target if (target: 1) if (target:0) /* { dg-error "too many 'if' clauses with 'target' modifier" } */ + f0 (); + #pragma omp target if (1) if (target:0) /* { dg-error "if any 'if' clause has modifier, then all 'if' clauses have to use modifier" } */ + f0 (); + #pragma omp target if (target: 1) if (0) /* { dg-error "if any 'if' clause has modifier, then all 'if' clauses have to use modifier" } */ + f0 (); + #pragma omp target update if (1) if (1) to (i) /* { dg-error "too many 'if' clauses without modifier" } */ + #pragma omp target update if (target update: 1) if (target update:0) to (i) /* { dg-error "too many 'if' clauses with 'target update' modifier" } */ + #pragma omp target update if (1) if (target update:0) to (i) /* { dg-error "if any 'if' clause has modifier, then all 'if' clauses have to use modifier" } */ + #pragma omp target update if (target update: 1) if (0) to (i) /* { dg-error "if any 'if' clause has modifier, then all 'if' clauses have to use modifier" } */ +} -- 2.30.2