[flang-commits] [flang] 6ab6b80 - [Flang][OpenMP]add semantic check for linear clause with statement function variables (#199743)
via flang-commits
flang-commits at lists.llvm.org
Fri Jun 5 01:40:28 PDT 2026
Author: jay0x
Date: 2026-06-05T14:10:23+05:30
New Revision: 6ab6b803f552d909341e3c561e84ef9bc6beefe0
URL: https://github.com/llvm/llvm-project/commit/6ab6b803f552d909341e3c561e84ef9bc6beefe0
DIFF: https://github.com/llvm/llvm-project/commit/6ab6b803f552d909341e3c561e84ef9bc6beefe0.diff
LOG: [Flang][OpenMP]add semantic check for linear clause with statement function variables (#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)
```
Co-authored-by: Jay Satish Kumar Patel <kumarpat at pe31.hpc.amslabs.hpecorp.net>
Added:
Modified:
flang/lib/Semantics/resolve-directives.cpp
flang/test/Semantics/OpenMP/private03.f90
Removed:
################################################################################
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index 821724fedc7d4..cf8e552c032c3 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -990,7 +990,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,
@@ -3262,6 +3263,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