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

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


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-openmp

Author: Tom Eccles (tblah)

<details>
<summary>Changes</summary>

Fixes #<!-- -->133685

---
Full diff: https://github.com/llvm/llvm-project/pull/140798.diff


2 Files Affected:

- (modified) flang/lib/Semantics/check-omp-structure.cpp (+4-4) 
- (added) flang/test/Semantics/OpenMP/cancel-bad-cancel-type.f90 (+6) 


``````````diff
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

``````````

</details>


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


More information about the flang-commits mailing list