Skip to content

Commit 5413a2b

Browse files
authored
[clang][OpenMP] Fix error handling of the adjust_args clause (#94696)
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.
1 parent 313b1a8 commit 5413a2b

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

clang/include/clang/Basic/DiagnosticParseKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,6 +1508,8 @@ def err_omp_unexpected_append_op : Error<
15081508
"unexpected operation specified in 'append_args' clause, expected 'interop'">;
15091509
def err_omp_unexpected_execution_modifier : Error<
15101510
"unexpected 'execution' modifier in non-executable context">;
1511+
def err_omp_unknown_adjust_args_op : Error<
1512+
"incorrect adjust_args type, expected 'need_device_ptr' or 'nothing'">;
15111513
def err_omp_declare_variant_wrong_clause : Error<
15121514
"expected %select{'match'|'match', 'adjust_args', or 'append_args'}0 clause "
15131515
"on 'omp declare variant' directive">;

clang/lib/Parse/ParseOpenMP.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4785,8 +4785,8 @@ bool Parser::ParseOpenMPVarList(OpenMPDirectiveKind DKind,
47854785
getLangOpts());
47864786
Data.ExtraModifierLoc = Tok.getLocation();
47874787
if (Data.ExtraModifier == OMPC_ADJUST_ARGS_unknown) {
4788-
SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end,
4789-
StopBeforeMatch);
4788+
Diag(Tok, diag::err_omp_unknown_adjust_args_op);
4789+
SkipUntil(tok::r_paren, tok::annot_pragma_openmp_end, StopBeforeMatch);
47904790
} else {
47914791
ConsumeToken();
47924792
if (Tok.is(tok::colon))
@@ -4799,7 +4799,7 @@ bool Parser::ParseOpenMPVarList(OpenMPDirectiveKind DKind,
47994799
bool IsComma =
48004800
(Kind != OMPC_reduction && Kind != OMPC_task_reduction &&
48014801
Kind != OMPC_in_reduction && Kind != OMPC_depend &&
4802-
Kind != OMPC_doacross && Kind != OMPC_map) ||
4802+
Kind != OMPC_doacross && Kind != OMPC_map && Kind != OMPC_adjust_args) ||
48034803
(Kind == OMPC_reduction && !InvalidReductionId) ||
48044804
(Kind == OMPC_map && Data.ExtraModifier != OMPC_MAP_unknown) ||
48054805
(Kind == OMPC_depend && Data.ExtraModifier != OMPC_DEPEND_unknown) ||

clang/test/OpenMP/declare_variant_clauses_messages.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,16 @@ void vararg_bar2(const char *fmt) { return; }
186186
// 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 *)'}}
187187
#pragma omp declare variant(foo_v4) match(construct={dispatch})
188188

189+
// expected-error@+3 {{incorrect adjust_args type, expected 'need_device_ptr' or 'nothing'}}
190+
#pragma omp declare variant(foo_v1) \
191+
match(construct={dispatch}, device={arch(arm)}) \
192+
adjust_args(badaaop:AAA,BBB)
193+
194+
// expected-error@+3 {{incorrect adjust_args type, expected 'need_device_ptr' or 'nothing'}}
195+
#pragma omp declare variant(foo_v1) \
196+
match(construct={dispatch}, device={arch(arm)}) \
197+
adjust_args(badaaop AAA,BBB)
198+
189199
#endif // _OPENMP >= 202011
190200
#if _OPENMP < 202011 // OpenMP 5.0 or lower
191201
// expected-error@+2 {{expected 'match' clause on 'omp declare variant' directive}}

0 commit comments

Comments
 (0)