[flang-commits] [flang] [flang][OpenMP]Fix versioning for implicit linear clause (PR #181791)

via flang-commits flang-commits at lists.llvm.org
Tue Feb 17 01:33:35 PST 2026


https://github.com/NimishMishra created https://github.com/llvm/llvm-project/pull/181791

The versioning of the implicit linear clause was set at OpenMP 4.0. However, versions v4.5, v5.0, and v5.2 also allow implicit linearisation, which was missed earlier. This PR fixes this.

OpenMP v5.0 (2.19.1.1) :  "_The loop iteration variable in the associated do-loop of a simd construct with just one
2 associated do-loop is linear with a linear-step that is the increment of the associated do-loop_."

OpenMP v5.2 (5.1.1) : "_If a simd construct has just one associated loop then its loop iteration variable may be listed in a
22 linear clause with a linear-step that is the increment of the associated loop_"

OpenMP v6.0 (7.1.1) : "_The loop-iteration variable in any affected loop of a loop or simd construct is lastprivate_."


Fixes: https://github.com/llvm/llvm-project/issues/179345

>From f0304d0f00de4a915dd01cebd63b8c6d76d0a484 Mon Sep 17 00:00:00 2001
From: potharla rupesh <rupesh.potharla at amd.com>
Date: Tue, 17 Feb 2026 13:34:54 +0530
Subject: [PATCH] Fix versioning for implicit linear clause

---
 flang/lib/Semantics/resolve-directives.cpp        |  2 +-
 flang/test/Lower/OpenMP/order-clause.f90          |  4 +++-
 flang/test/Lower/OpenMP/simd-linear.f90           |  2 +-
 flang/test/Lower/OpenMP/simd.f90                  |  7 +++++--
 .../Semantics/OpenMP/implicit_linear_symbols.f90  | 15 +++++++++++++++
 5 files changed, 25 insertions(+), 5 deletions(-)
 create mode 100644 flang/test/Semantics/OpenMP/implicit_linear_symbols.f90

diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index 1fde0d62581e8..ba645033df60f 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -2443,7 +2443,7 @@ void OmpAttributeVisitor::PrivatizeAssociatedLoopIndexAndCheckLoopLevel(
   unsigned version{context_.langOptions().OpenMPVersion};
   if (!llvm::omp::allSimdSet.test(GetContext().directive)) {
     ivDSA = Symbol::Flag::OmpPrivate;
-  } else if (level == 1 && version <= 45) {
+  } else if (level == 1 && version < 60) {
     ivDSA = Symbol::Flag::OmpLinear;
   } else {
     ivDSA = Symbol::Flag::OmpLastPrivate;
diff --git a/flang/test/Lower/OpenMP/order-clause.f90 b/flang/test/Lower/OpenMP/order-clause.f90
index d5799079b3759..e1b93a2b8f7a2 100644
--- a/flang/test/Lower/OpenMP/order-clause.f90
+++ b/flang/test/Lower/OpenMP/order-clause.f90
@@ -1,6 +1,8 @@
 ! This test checks lowering of OpenMP order clause.
 
-!RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=50 %s -o - | FileCheck %s
+! To prevent testing for unrelated clauses like implicit linear clause and focusing on the
+! clauses of interest here, the OpenMP version is 6.0
+!RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=60 %s -o - | FileCheck %s
 
 !CHECK-LABEL:   func.func @_QPsimd_order() {
 subroutine simd_order
diff --git a/flang/test/Lower/OpenMP/simd-linear.f90 b/flang/test/Lower/OpenMP/simd-linear.f90
index 6a50f1da18489..2caf1b0ad05fa 100644
--- a/flang/test/Lower/OpenMP/simd-linear.f90
+++ b/flang/test/Lower/OpenMP/simd-linear.f90
@@ -1,7 +1,7 @@
 ! This test checks lowering of OpenMP SIMD Directive
 ! with linear clause
 
-! RUN: %flang_fc1 -fopenmp -emit-hlfir -fopenmp-version=50 %s -o - 2>&1 | FileCheck %s
+! RUN: %flang_fc1 -fopenmp -emit-hlfir -fopenmp-version=60 %s -o - 2>&1 | FileCheck %s
 ! RUN: %flang_fc1 -fopenmp -emit-hlfir -fopenmp-version=45 %s -o - 2>&1 | FileCheck %s --check-prefix=IMPLICIT
 
 !CHECK: %[[X_alloca:.*]] = fir.alloca i32 {bindc_name = "x", uniq_name = "_QFsimple_linearEx"}
diff --git a/flang/test/Lower/OpenMP/simd.f90 b/flang/test/Lower/OpenMP/simd.f90
index a3af7628c29f5..ff0bd6dd0a730 100644
--- a/flang/test/Lower/OpenMP/simd.f90
+++ b/flang/test/Lower/OpenMP/simd.f90
@@ -1,8 +1,11 @@
 ! Tests for 2.9.3.1 Simd
 
 ! The "if" clause was added to the "simd" directive in OpenMP 5.0.
-! RUN: %flang_fc1 -flang-experimental-hlfir -emit-hlfir -fopenmp -fopenmp-version=50 %s -o - | FileCheck %s
-! RUN: bbc -hlfir -emit-hlfir -fopenmp -fopenmp-version=50 %s -o - | FileCheck %s
+
+! To prevent testing for unrelated clauses like implicit linear clause and focusing on the
+! clauses of interest here, the OpenMP version is 6.0
+! RUN: %flang_fc1 -flang-experimental-hlfir -emit-hlfir -fopenmp -fopenmp-version=60 %s -o - | FileCheck %s
+! RUN: bbc -hlfir -emit-hlfir -fopenmp -fopenmp-version=60 %s -o - | FileCheck %s
 
 !CHECK: omp.declare_reduction @[[REDUCER:.*]] : i32
 
diff --git a/flang/test/Semantics/OpenMP/implicit_linear_symbols.f90 b/flang/test/Semantics/OpenMP/implicit_linear_symbols.f90
new file mode 100644
index 0000000000000..e57a063d8a9d0
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/implicit_linear_symbols.f90
@@ -0,0 +1,15 @@
+!RUN: %flang_fc1 -fopenmp -fopenmp-version=52 -fdebug-dump-symbols %s 2>&1 | FileCheck %s --check-prefix=IMPLICIT
+!RUN: %flang_fc1 -fopenmp -fopenmp-version=60 -fdebug-dump-symbols %s 2>&1 | FileCheck %s --check-prefix=NOIMPLICIT
+
+
+!IMPLICIT: k2 (OmpLinear, OmpPreDetermined): {{.*}}
+!NOIMPLICIT: k2 (OmpLastPrivate, OmpPreDetermined): {{.*}}
+subroutine implicit_linear
+  integer :: k1, k2
+
+  !$omp simd
+  do k2=1,10
+  do k1=1,10
+  end do
+  end do
+end subroutine



More information about the flang-commits mailing list