[flang-commits] [flang] [Flang][OpenMP]add semantic check for linear clause with statement function variables (PR #199743)
via flang-commits
flang-commits at lists.llvm.org
Tue May 26 11:49:22 PDT 2026
https://github.com/blazie2004 created https://github.com/llvm/llvm-project/pull/199743
### **Description**
1. This patch adds a missing semantic check for the LINEAR clause.
2. OpenMP treats LINEAR variables similarly to PRIVATE variables. Variables used inside statement function expressions are not allowed to be privatized, but Flang was not checking this for LINEAR.
3. The existing privatization check already handled PRIVATE, FIRSTPRIVATE, and LASTPRIVATE. This patch extends the same check to LINEAR.
Fixes : [199660](https://github.com/llvm/llvm-project/issues/199660)
### **Reproducer**
```
subroutine test()
integer :: pi, r, f, x
f(r) = pi * r + x
!$omp parallel do linear(x)
do r = 1, 10
pi = f(r)
end do
!$omp end parallel do
end subroutine
```
when compiled with : `-fopenmp -fopenmp-version=45 -c`
**Observed Behavior**
` No diagnostic emitted
`
**Expected Behavior**
```
error: Variable 'x' in statement function expression cannot be in a LINEAR clause
!$omp parallel do linear(x)
```
>From ecb2d7b7afaa68bcf4889ba3671e9eaeed19f6e7 Mon Sep 17 00:00:00 2001
From: Jay Satish Kumar Patel <kumarpat at pe31.hpc.amslabs.hpecorp.net>
Date: Tue, 26 May 2026 12:32:30 -0500
Subject: [PATCH] add semantic check for linear clause with statement function
variables
---
flang/lib/Semantics/resolve-directives.cpp | 5 ++++-
flang/test/Semantics/OpenMP/private03.f90 | 10 +++++++++-
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index b97f7ce58a1c0..fa84c35424108 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -1064,7 +1064,8 @@ class OmpAttributeVisitor : DirectiveAttributeVisitor<llvm::omp::Directive> {
Symbol::Flag::OmpIsDevicePtr, Symbol::Flag::OmpHasDeviceAddr};
Symbol::Flags privateDataSharingAttributeFlags{Symbol::Flag::OmpPrivate,
- Symbol::Flag::OmpFirstPrivate, Symbol::Flag::OmpLastPrivate};
+ Symbol::Flag::OmpFirstPrivate, Symbol::Flag::OmpLastPrivate,
+ Symbol::Flag::OmpLinear};
Symbol::Flags ompFlagsRequireNewSymbol{Symbol::Flag::OmpPrivate,
Symbol::Flag::OmpLinear, Symbol::Flag::OmpFirstPrivate,
@@ -3263,6 +3264,8 @@ void OmpAttributeVisitor::CheckObjectIsPrivatizable(
clauseName = "FIRSTPRIVATE";
} else if (ompFlag == Symbol::Flag::OmpLastPrivate) {
clauseName = "LASTPRIVATE";
+ } else if (ompFlag == Symbol::Flag::OmpLinear) {
+ clauseName = "LINEAR";
}
if (SymbolOrEquivalentIsInNamelist(symbol)) {
diff --git a/flang/test/Semantics/OpenMP/private03.f90 b/flang/test/Semantics/OpenMP/private03.f90
index 61f790fbb38b2..e921d8a58fdba 100644
--- a/flang/test/Semantics/OpenMP/private03.f90
+++ b/flang/test/Semantics/OpenMP/private03.f90
@@ -1,7 +1,7 @@
! RUN: %python %S/../test_errors.py %s %flang -fopenmp
! OpenMP Version 4.5
! Variables that appear in expressions for statement function definitions
-! may not appear in private, firstprivate or lastprivate clauses.
+! may not appear in private, firstprivate, lastprivate or linear clauses.
subroutine stmt_function(temp)
@@ -34,6 +34,14 @@ subroutine stmt_function(temp)
end do
!$omp end parallel do
+ !ERROR: Variable 'p' in statement function expression cannot be in a LINEAR clause
+ !$omp parallel do simd linear(p)
+ do i = 1, 10
+ t(i) = v(temp) + i
+ p = p + 1
+ end do
+ !$omp end parallel do simd
+
print *, t
end subroutine stmt_function
More information about the flang-commits
mailing list