Skip to content

Commit 9d245d0

Browse files
committed
[OpenMP] Fix crash on invalid with cancel directive
If the next token after 'cancel' is a special token, we would trigger an assertion. We should be consuming any token, same as elsewhere in the function. Note, we could check for an unknown directive and do different error recovery, but that caused too many behavioral changes for other tests in the form of "unexpected tokens ignored" diagnostics that didn't seem like an improvement for the test cases. Fixes #139360
1 parent cede236 commit 9d245d0

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,7 @@ OpenMP Support
922922
an invalid expression. (#GH139073)
923923
- Fixed a crashing bug with ``omp simd collapse`` if the argument to
924924
``collapse`` was an invalid expression. (#GH138493)
925+
- Fixed a crashing bug with a malformed ``cancel`` directive. (#GH139360)
925926
- Fixed a crashing bug with ``omp distribute dist_schedule`` if the argument to
926927
``dist_schedule`` was not strictly positive. (#GH139266)
927928

clang/lib/Parse/ParseOpenMP.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2487,7 +2487,7 @@ StmtResult Parser::ParseOpenMPExecutableDirective(
24872487
} else if (DKind == OMPD_cancellation_point || DKind == OMPD_cancel) {
24882488
CancelRegion = parseOpenMPDirectiveKind(*this);
24892489
if (Tok.isNot(tok::annot_pragma_openmp_end))
2490-
ConsumeToken();
2490+
ConsumeAnyToken();
24912491
}
24922492

24932493
if (isOpenMPLoopDirective(DKind))

clang/test/OpenMP/cancel_messages.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,8 @@ label1 : {
9393
return 0;
9494
}
9595

96+
namespace GH139360 {
97+
void f(){
98+
#pragma omp cancel( // expected-error {{one of 'for', 'parallel', 'sections' or 'taskgroup' is expected}}
99+
}
100+
} // namesapce GH139360

0 commit comments

Comments
 (0)