[flang-commits] [flang] [flang][OpenMP] fix diagnostic for bad cancel type (PR #140798)

Tom Eccles via flang-commits flang-commits at lists.llvm.org
Tue May 20 13:45:23 PDT 2025


https://github.com/tblah created https://github.com/llvm/llvm-project/pull/140798

Fixes #133685

>From cdb3f7e02603da24e537af83af4b83e8b30e46dc Mon Sep 17 00:00:00 2001
From: Tom Eccles <tom.eccles at arm.com>
Date: Tue, 20 May 2025 20:43:29 +0000
Subject: [PATCH] [flang][OpenMP] fix diagnostic for bad cancel type

Fixes #133685
---
 flang/lib/Semantics/check-omp-structure.cpp            | 8 ++++----
 flang/test/Semantics/OpenMP/cancel-bad-cancel-type.f90 | 6 ++++++
 2 files changed, 10 insertions(+), 4 deletions(-)
 create mode 100644 flang/test/Semantics/OpenMP/cancel-bad-cancel-type.f90

diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index c6c4fdf8a8198..606014276e7ca 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -2575,8 +2575,8 @@ void OmpStructureChecker::CheckCancellationNest(
       }
       break;
     default:
-      // This should have been diagnosed by this point.
-      llvm_unreachable("Unexpected directive");
+      // This is diagnosed later.
+      return;
     }
     if (!eligibleCancellation) {
       context_.Say(source,
@@ -2614,8 +2614,8 @@ void OmpStructureChecker::CheckCancellationNest(
           parser::ToUpperCaseLetters(typeName.str()));
       break;
     default:
-      // This should have been diagnosed by this point.
-      llvm_unreachable("Unexpected directive");
+      // This is diagnosed later.
+      return;
     }
   }
 }
diff --git a/flang/test/Semantics/OpenMP/cancel-bad-cancel-type.f90 b/flang/test/Semantics/OpenMP/cancel-bad-cancel-type.f90
new file mode 100644
index 0000000000000..ea5e7be23e2f9
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/cancel-bad-cancel-type.f90
@@ -0,0 +1,6 @@
+!RUN: %python %S/../test_errors.py %s %flang_fc1 %openmp_flags
+
+program test
+!ERROR: PARALLEL DO is not a cancellable construct
+!$omp cancel parallel do
+end



More information about the flang-commits mailing list