Skip to content

Commit

Permalink
[clang][OpenMP] Fix error handling of the adjust_args clause (llvm#94696
Browse files Browse the repository at this point in the history
)

Static verifier noticed the current code has logically dead code parsing
the clause where IsComma is assigned. Fix this and improve the error
message received when a bad adjust-op is specified.

This will now be handled like 'map' where a nice diagnostic is given
with the correct values, then parsing continues on the next clause
reducing unhelpful diagnostics.
  • Loading branch information
mikerice1969 authored Jun 24, 2024
1 parent 313b1a8 commit 5413a2b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 2 additions & 0 deletions clang/include/clang/Basic/DiagnosticParseKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -1508,6 +1508,8 @@ def err_omp_unexpected_append_op : Error<
"unexpected operation specified in 'append_args' clause, expected 'interop'">;
def err_omp_unexpected_execution_modifier : Error<
"unexpected 'execution' modifier in non-executable context">;
def err_omp_unknown_adjust_args_op : Error<
"incorrect adjust_args type, expected 'need_device_ptr' or 'nothing'">;
def err_omp_declare_variant_wrong_clause : Error<
"expected %select{'match'|'match', 'adjust_args', or 'append_args'}0 clause "
"on 'omp declare variant' directive">;
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/Parse/ParseOpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4785,8 +4785,8 @@ bool Parser::ParseOpenMPVarList(OpenMPDirectiveKind DKind,
getLangOpts());
Data.ExtraModifierLoc = Tok.getLocation();
if (Data.ExtraModifier == OMPC_ADJUST_ARGS_unknown) {
SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end,
StopBeforeMatch);
Diag(Tok, diag::err_omp_unknown_adjust_args_op);
SkipUntil(tok::r_paren, tok::annot_pragma_openmp_end, StopBeforeMatch);
} else {
ConsumeToken();
if (Tok.is(tok::colon))
Expand All @@ -4799,7 +4799,7 @@ bool Parser::ParseOpenMPVarList(OpenMPDirectiveKind DKind,
bool IsComma =
(Kind != OMPC_reduction && Kind != OMPC_task_reduction &&
Kind != OMPC_in_reduction && Kind != OMPC_depend &&
Kind != OMPC_doacross && Kind != OMPC_map) ||
Kind != OMPC_doacross && Kind != OMPC_map && Kind != OMPC_adjust_args) ||
(Kind == OMPC_reduction && !InvalidReductionId) ||
(Kind == OMPC_map && Data.ExtraModifier != OMPC_MAP_unknown) ||
(Kind == OMPC_depend && Data.ExtraModifier != OMPC_DEPEND_unknown) ||
Expand Down
10 changes: 10 additions & 0 deletions clang/test/OpenMP/declare_variant_clauses_messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,16 @@ void vararg_bar2(const char *fmt) { return; }
// expected-error@+1 {{variant in '#pragma omp declare variant' with type 'void (float *, float *, int *, omp_interop_t)' (aka 'void (float *, float *, int *, void *)') is incompatible with type 'void (float *, float *, int *)'}}
#pragma omp declare variant(foo_v4) match(construct={dispatch})

// expected-error@+3 {{incorrect adjust_args type, expected 'need_device_ptr' or 'nothing'}}
#pragma omp declare variant(foo_v1) \
match(construct={dispatch}, device={arch(arm)}) \
adjust_args(badaaop:AAA,BBB)

// expected-error@+3 {{incorrect adjust_args type, expected 'need_device_ptr' or 'nothing'}}
#pragma omp declare variant(foo_v1) \
match(construct={dispatch}, device={arch(arm)}) \
adjust_args(badaaop AAA,BBB)

#endif // _OPENMP >= 202011
#if _OPENMP < 202011 // OpenMP 5.0 or lower
// expected-error@+2 {{expected 'match' clause on 'omp declare variant' directive}}
Expand Down

0 comments on commit 5413a2b

Please sign in to comment.