[flang-commits] [flang] [flang][OpenMP] Perform checks on features from different versions (PR #229116)

Krzysztof Parzyszek via flang-commits flang-commits at lists.llvm.org
Tue Oct 6 04:34:43 PDT 2026


https://github.com/kparzysz updated https://github.com/llvm/llvm-project/pull/229116

>From dd9db7701a4f73b9b9913406a7ca5548ebf5e683 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek <Krzysztof.Parzyszek at amd.com>
Date: Mon, 5 Oct 2026 08:54:16 -0500
Subject: [PATCH] [flang][OpenMP] Perform checks on features from different
 versions

The check for DETACH and MERGEABLE used together was only done when
the OpenMP version was set to the versions that allow both clauses.
The use of these clauses is accepted with a warning in older versions
as well, so make sure to perform the checks for all versions.
---
 flang/lib/Semantics/check-omp-structure.cpp |  2 +-
 flang/test/Semantics/OpenMP/task-45.f90     | 14 ++++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)
 create mode 100644 flang/test/Semantics/OpenMP/task-45.f90

diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index c163005593df5..6193b297b62fb 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -3914,7 +3914,7 @@ void OmpStructureChecker::Leave(const parser::OmpClauseList &x) {
 
   if (GetContext().directive == llvm::omp::Directive::OMPD_task) {
     if (auto *detachClause{FindClause(llvm::omp::Clause::OMPC_detach)}) {
-      if (version == 50 || version == 51) {
+      if (version < 52) {
         // OpenMP 5.0: 2.10.1 Task construct restrictions
         CheckNotAllowedIfClause(llvm::omp::Clause::OMPC_detach,
             {llvm::omp::Clause::OMPC_mergeable});
diff --git a/flang/test/Semantics/OpenMP/task-45.f90 b/flang/test/Semantics/OpenMP/task-45.f90
new file mode 100644
index 0000000000000..64b7cf765f8d2
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/task-45.f90
@@ -0,0 +1,14 @@
+! REQUIRES: openmp_runtime
+! RUN: %python %S/../test_errors.py %s %flang_fc1 %openmp_flags -fopenmp-version=45
+
+! Check that we still emit diagnostics for features from future versions
+! that are allowed under a warning.
+
+subroutine f
+  use omp_lib, only: omp_event_handle_kind
+  integer(kind=omp_event_handle_kind) :: e
+  !ERROR: Clause MERGEABLE is not allowed if clause DETACH appears on the TASK directive
+  !WARNING: DETACH clause is not allowed on TASK directive in OpenMP v4.5, try -fopenmp-version=50 [-Wopenmp-future]
+  !$omp task mergeable detach(e)
+  !$omp end task
+end



More information about the flang-commits mailing list