diff options
author | Sandra Loosemore <sloosemore@baylibre.com> | 2025-03-31 22:02:35 +0000 |
---|---|---|
committer | Sandra Loosemore <sloosemore@baylibre.com> | 2025-04-02 14:44:26 +0000 |
commit | aca8155c09001f269a20d6df438fa0e749dd5388 (patch) | |
tree | f3d8ef0c9d0b4865fce220b431a9182687c13675 /gcc/fortran | |
parent | 17ed44c96f6e5c0cc02d8cb29ff5943dd30ab3c1 (diff) | |
download | gcc-aca8155c09001f269a20d6df438fa0e749dd5388.zip gcc-aca8155c09001f269a20d6df438fa0e749dd5388.tar.gz gcc-aca8155c09001f269a20d6df438fa0e749dd5388.tar.bz2 |
OpenMP: Require target and/or targetsync init modifier [PR118965]
As noted in PR 118965, the initial interop implementation overlooked
the requirement in the OpenMP spec that at least one of the "target"
and "targetsync" modifiers is required in both the interop construct
init clause and the declare variant append_args clause.
Adding the check was fairly straightforward, but it broke about a
gazillion existing test cases. In particular, things like "init (x, y)"
which were previously accepted (and tested for being accepted) aren't
supposed to be allowed by the spec, much less things like "init (target)"
where target was previously interpreted as a variable name instead of a
modifier. Since one of the effects of the change is that at least one
modifier is always required, I found that deleting all the code that was
trying to detect and handle the no-modifier case allowed for better
diagnostics.
gcc/c/ChangeLog
PR middle-end/118965
* c-parser.cc (c_parser_omp_clause_init_modifiers): Adjust
error message.
(c_parser_omp_clause_init): Remove code for recognizing clauses
without modifiers. Diagnose missing target/targetsync modifier.
(c_finish_omp_declare_variant): Diagnose missing target/targetsync
modifier.
gcc/cp/ChangeLog
PR middle-end/118965
* parser.cc (c_parser_omp_clause_init_modifiers): Adjust
error message.
(cp_parser_omp_clause_init): Remove code for recognizing clauses
without modifiers. Diagnose missing target/targetsync modifier.
(cp_finish_omp_declare_variant): Diagnose missing target/targetsync
modifier.
gcc/fortran/ChangeLog
PR middle-end/118965
* openmp.cc (gfc_parser_omp_clause_init_modifiers): Fix some
inconsistent code indentation. Remove code for recognizing
clauses without modifiers. Diagnose prefer_type without a
following paren. Adjust error message for an unrecognized modifier.
Diagnose missing target/targetsync modifier.
(gfc_match_omp_init): Fix more inconsistent code indentation.
gcc/testsuite/ChangeLog
PR middle-end/118965
* c-c++-common/gomp/append-args-1.c: Add target/targetsync
modifiers so tests do what they were previously supposed to do.
Adjust expected output.
* c-c++-common/gomp/append-args-7.c: Likewise.
* c-c++-common/gomp/append-args-8.c: Likewise.
* c-c++-common/gomp/append-args-9.c: Likewise.
* c-c++-common/gomp/interop-1.c: Likewise.
* c-c++-common/gomp/interop-2.c: Likewise.
* c-c++-common/gomp/interop-3.c: Likewise.
* c-c++-common/gomp/interop-4.c: Likewise.
* c-c++-common/gomp/pr118965-1.c: New.
* c-c++-common/gomp/pr118965-2.c: New.
* g++.dg/gomp/append-args-1.C: Add target/targetsync modifiers
and adjust expected output.
* g++.dg/gomp/append-args-2.C: Likewise.
* g++.dg/gomp/append-args-6.C: Likewise.
* g++.dg/gomp/append-args-7.C: Likewise.
* g++.dg/gomp/append-args-8.C: Likewise.
* g++.dg/gomp/interop-5.C: Likewise.
* gfortran.dg/gomp/append_args-1.f90: Add target/targetsync
modifiers and adjust expected output.
* gfortran.dg/gomp/append_args-2.f90: Likewise.
* gfortran.dg/gomp/append_args-3.f90: Likewise.
* gfortran.dg/gomp/append_args-4.f90: Likewise.
* gfortran.dg/gomp/interop-1.f90: Likewise.
* gfortran.dg/gomp/interop-2.f90: Likewise.
* gfortran.dg/gomp/interop-3.f90: Likewise.
* gfortran.dg/gomp/interop-4.f90: Likewise.
* gfortran.dg/gomp/pr118965-1.f90: New.
* gfortran.dg/gomp/pr118965-2.f90: New.
Diffstat (limited to 'gcc/fortran')
-rw-r--r-- | gcc/fortran/openmp.cc | 77 |
1 files changed, 35 insertions, 42 deletions
diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc index 905980a..ded80b7 100644 --- a/gcc/fortran/openmp.cc +++ b/gcc/fortran/openmp.cc @@ -2138,10 +2138,8 @@ gfc_match_omp_prefer_type (char **type_str, int *type_str_len) the 'interop' directive and the 'append_args' directive of 'declare variant'. [prefer_type(...)][,][<target|targetsync>, ...]) - If is_init_clause, there might be no modifiers but variables like 'target'; - additionally, the modifier parsing ends with a ':'. - If not is_init_clause (i.e. append_args), there must be modifiers and the - parsing ends with ')'. */ + If is_init_clause, the modifier parsing ends with a ':'. + If not is_init_clause (i.e. append_args), the parsing ends with ')'. */ static match gfc_parser_omp_clause_init_modifiers (bool &target, bool &targetsync, @@ -2153,9 +2151,10 @@ gfc_parser_omp_clause_init_modifiers (bool &target, bool &targetsync, *type_str = NULL; type_str_len = 0; match m; - locus old_loc = gfc_current_locus; - do { - if (gfc_match ("prefer_type ( ") == MATCH_YES) + + do + { + if (gfc_match ("prefer_type ( ") == MATCH_YES) { if (*type_str) { @@ -2181,12 +2180,17 @@ gfc_parser_omp_clause_init_modifiers (bool &target, bool &targetsync, } return MATCH_ERROR; } - if (gfc_match ("targetsync ") == MATCH_YES) + + if (gfc_match ("prefer_type ") == MATCH_YES) + { + gfc_error ("Expected %<(%> after %<prefer_type%> at %C"); + return MATCH_ERROR; + } + + if (gfc_match ("targetsync ") == MATCH_YES) { if (targetsync) { - /* Avoid the word 'modifier' as it could be also be no clauses and - twice a variable named 'targetsync', which is also invalid. */ gfc_error ("Duplicate %<targetsync%> at %C"); return MATCH_ERROR; } @@ -2202,13 +2206,6 @@ gfc_parser_omp_clause_init_modifiers (bool &target, bool &targetsync, } if (gfc_match (": ") == MATCH_YES) break; - gfc_char_t c = gfc_peek_char (); - if (!*type_str && (c == ')' || (gfc_current_form != FORM_FREE - && (c == '_' || ISALPHA (c))))) - { - gfc_current_locus = old_loc; - break; - } gfc_error ("Expected %<,%> or %<:%> at %C"); return MATCH_ERROR; } @@ -2231,25 +2228,21 @@ gfc_parser_omp_clause_init_modifiers (bool &target, bool &targetsync, } if (gfc_match (": ") == MATCH_YES) break; - gfc_char_t c = gfc_peek_char (); - if (!*type_str && (c == ')' || (gfc_current_form != FORM_FREE - && (c == '_' || ISALPHA (c))))) - { - gfc_current_locus = old_loc; - break; - } gfc_error ("Expected %<,%> or %<:%> at %C"); return MATCH_ERROR; } - if (*type_str) - { - gfc_error ("Expected %<target%> or %<targetsync%> at %C"); - return MATCH_ERROR; - } - gfc_current_locus = old_loc; - break; + gfc_error ("Expected %<prefer_type%>, %<target%>, or %<targetsync%> " + "at %C"); + return MATCH_ERROR; } while (true); + + if (!target && !targetsync) + { + gfc_error ("Missing required %<target%> and/or %<targetsync%> " + "modifier at %C"); + return MATCH_ERROR; + } return MATCH_YES; } @@ -2266,17 +2259,17 @@ gfc_match_omp_init (gfc_omp_namelist **list) type_str_len, true) == MATCH_ERROR) return MATCH_ERROR; - gfc_omp_namelist **head = NULL; - if (gfc_match_omp_variable_list ("", list, false, NULL, &head) != MATCH_YES) - return MATCH_ERROR; - for (gfc_omp_namelist *n = *head; n; n = n->next) - { - n->u.init.target = target; - n->u.init.targetsync = targetsync; - n->u.init.len = type_str_len; - n->u2.init_interop = type_str; - } - return MATCH_YES; + gfc_omp_namelist **head = NULL; + if (gfc_match_omp_variable_list ("", list, false, NULL, &head) != MATCH_YES) + return MATCH_ERROR; + for (gfc_omp_namelist *n = *head; n; n = n->next) + { + n->u.init.target = target; + n->u.init.targetsync = targetsync; + n->u.init.len = type_str_len; + n->u2.init_interop = type_str; + } + return MATCH_YES; } |