Skip to content

Commit 70ca3f4

Browse files
authored
[OpenMP] Fix crash on invalid with cancel directive (#139577)
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 b17f3c6 commit 70ca3f4

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
@@ -2497,7 +2497,7 @@ StmtResult Parser::ParseOpenMPExecutableDirective(
24972497
} else if (DKind == OMPD_cancellation_point || DKind == OMPD_cancel) {
24982498
CancelRegion = parseOpenMPDirectiveKind(*this);
24992499
if (Tok.isNot(tok::annot_pragma_openmp_end))
2500-
ConsumeToken();
2500+
ConsumeAnyToken();
25012501
}
25022502

25032503
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)