[clang] 70ca3f4 - [OpenMP] Fix crash on invalid with cancel directive (#139577)
via cfe-commits
cfe-commits at lists.llvm.org
Mon May 12 10:44:07 PDT 2025
Author: Aaron Ballman
Date: 2025-05-12T13:44:03-04:00
New Revision: 70ca3f41fa1a16ede0b33e0780c04360b50e4dee
URL: https://github.com/llvm/llvm-project/commit/70ca3f41fa1a16ede0b33e0780c04360b50e4dee
DIFF: https://github.com/llvm/llvm-project/commit/70ca3f41fa1a16ede0b33e0780c04360b50e4dee.diff
LOG: [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
Added:
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/Parse/ParseOpenMP.cpp
clang/test/OpenMP/cancel_messages.cpp
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 257c4696de403..14d526a71f458 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -922,6 +922,7 @@ OpenMP Support
an invalid expression. (#GH139073)
- Fixed a crashing bug with ``omp simd collapse`` if the argument to
``collapse`` was an invalid expression. (#GH138493)
+- Fixed a crashing bug with a malformed ``cancel`` directive. (#GH139360)
- Fixed a crashing bug with ``omp distribute dist_schedule`` if the argument to
``dist_schedule`` was not strictly positive. (#GH139266)
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 91087a913d97e..85838feae77d3 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -2497,7 +2497,7 @@ StmtResult Parser::ParseOpenMPExecutableDirective(
} else if (DKind == OMPD_cancellation_point || DKind == OMPD_cancel) {
CancelRegion = parseOpenMPDirectiveKind(*this);
if (Tok.isNot(tok::annot_pragma_openmp_end))
- ConsumeToken();
+ ConsumeAnyToken();
}
if (isOpenMPLoopDirective(DKind))
diff --git a/clang/test/OpenMP/cancel_messages.cpp b/clang/test/OpenMP/cancel_messages.cpp
index 0c96beecc04b0..1391578cb0977 100644
--- a/clang/test/OpenMP/cancel_messages.cpp
+++ b/clang/test/OpenMP/cancel_messages.cpp
@@ -93,3 +93,8 @@ label1 : {
return 0;
}
+namespace GH139360 {
+void f(){
+#pragma omp cancel( // expected-error {{one of 'for', 'parallel', 'sections' or 'taskgroup' is expected}}
+}
+} // namesapce GH139360
More information about the cfe-commits
mailing list