[flang-commits] [flang] [flang][OpenMP] Fix verification of REF modifier on LINEAR clause (PR #232367)
Krzysztof Parzyszek via flang-commits
flang-commits at lists.llvm.org
Thu Oct 15 09:49:30 PDT 2026
https://github.com/kparzysz updated https://github.com/llvm/llvm-project/pull/232367
>From 4bf7ca1f08d132537c2b80de56fa35e57646bd80 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek <Krzysztof.Parzyszek at amd.com>
Date: Thu, 15 Oct 2026 10:30:45 -0500
Subject: [PATCH 1/5] [flang][OpenMP] Fix verification of REF modifier on
LINEAR clause
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The OpenMP spec has a bug: the restriction should read
> If linear-modifier is ref, list items must not be polymorphic variables,
> assumed-shape arrays, or variables with the ALLOCATABLE attribute.
Co-authored-by: Markus Mützel
---
flang/lib/Semantics/check-omp-loop.cpp | 6 ++---
flang/test/Lower/OpenMP/declare-simd.f90 | 8 +++----
.../test/Parser/OpenMP/linear-clause-v45.f90 | 4 ++--
.../test/Semantics/OpenMP/linear-clause01.f90 | 22 ++++++++++++++++++-
.../test/Semantics/OpenMP/linear-clause03.f90 | 2 +-
.../Semantics/OpenMP/simd-linear-array.f90 | 4 ++--
6 files changed, 33 insertions(+), 13 deletions(-)
diff --git a/flang/lib/Semantics/check-omp-loop.cpp b/flang/lib/Semantics/check-omp-loop.cpp
index 5165ca5f70d078..2b2120075d97ec 100644
--- a/flang/lib/Semantics/check-omp-loop.cpp
+++ b/flang/lib/Semantics/check-omp-loop.cpp
@@ -931,10 +931,10 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Linear &x) {
if (linearMod->v != parser::OmpLinearModifier::Value::Ref) {
CheckIntegerNoRef(symbol, source);
} else {
- if (!IsAllocatable(*symbol) && !IsAssumedShape(*symbol) &&
- !IsPolymorphic(*symbol)) {
+ if (IsAllocatable(*symbol) || IsAssumedShape(*symbol) ||
+ IsPolymorphic(*symbol)) {
context_.Say(source,
- "The list item `%s` specified with the REF '%s' must be polymorphic variable, assumed-shape array, or a variable with the `ALLOCATABLE` attribute"_err_en_US,
+ "The list item `%s` specified with the REF '%s' must not be polymorphic variable, assumed-shape array, or a variable with the `ALLOCATABLE` attribute"_err_en_US,
symbol->name(), desc.getName());
}
}
diff --git a/flang/test/Lower/OpenMP/declare-simd.f90 b/flang/test/Lower/OpenMP/declare-simd.f90
index 22b80bdebf0fad..9f75f2b34d12ae 100644
--- a/flang/test/Lower/OpenMP/declare-simd.f90
+++ b/flang/test/Lower/OpenMP/declare-simd.f90
@@ -190,15 +190,15 @@ subroutine declare_simd_linear_ref(x)
#else
!$omp declare simd linear(x : ref, step(4))
#endif
- integer, allocatable, intent(inout) :: x
+ integer, intent(inout) :: x
end subroutine declare_simd_linear_ref
! CHECK-LABEL: func.func @_QPdeclare_simd_linear_ref(
! CHECK: %[[SCOPE:.*]] = fir.dummy_scope : !fir.dscope
-! CHECK: %[[X:.*]]:2 = hlfir.declare %{{.*}} dummy_scope %[[SCOPE]] arg 1 {{.*}} : (!fir.ref<!fir.box<!fir.heap<i32>>>, !fir.dscope) -> (!fir.ref<!fir.box<!fir.heap<i32>>>, !fir.ref<!fir.box<!fir.heap<i32>>>)
+! CHECK: %[[X:.*]]:2 = hlfir.declare %{{.*}} dummy_scope %[[SCOPE]] arg 1 {{.*}} : (!fir.ref<i32>, !fir.dscope) -> (!fir.ref<i32>, !fir.ref<i32>)
! CHECK: %[[C4:.*]] = arith.constant 4 : i32
-! CHECK: omp.declare_simd linear(ref(%[[X]]#0 : !fir.ref<!fir.box<!fir.heap<i32>>> = %[[C4]] : i32))
-! CHECK-SAME: linear_var_types([!fir.box<!fir.heap<i32>>]){{$}}
+! CHECK: omp.declare_simd linear(ref(%[[X]]#0 : !fir.ref<i32> = %[[C4]] : i32))
+! CHECK-SAME: linear_var_types([i32]){{$}}
! CHECK: return
subroutine declare_simd_linear_uval(y)
diff --git a/flang/test/Parser/OpenMP/linear-clause-v45.f90 b/flang/test/Parser/OpenMP/linear-clause-v45.f90
index 1edf1d04a4a3cc..83de77530f6079 100644
--- a/flang/test/Parser/OpenMP/linear-clause-v45.f90
+++ b/flang/test/Parser/OpenMP/linear-clause-v45.f90
@@ -55,12 +55,12 @@ subroutine f01(x)
!PARSE-TREE: DoConstruct
subroutine f02(x)
- integer, allocatable :: x
+ integer :: x
!$omp declare simd linear(ref(x) : 2)
end
!UNPARSE: SUBROUTINE f02 (x)
-!UNPARSE: INTEGER, ALLOCATABLE :: x
+!UNPARSE: INTEGER x
!UNPARSE: !$OMP DECLARE SIMD LINEAR(REF(x): 2_4)
!UNPARSE: END SUBROUTINE
diff --git a/flang/test/Semantics/OpenMP/linear-clause01.f90 b/flang/test/Semantics/OpenMP/linear-clause01.f90
index bd7783e7c24217..d6d5162e4da1a0 100644
--- a/flang/test/Semantics/OpenMP/linear-clause01.f90
+++ b/flang/test/Semantics/OpenMP/linear-clause01.f90
@@ -40,7 +40,6 @@ end subroutine linear_clause_02
! Case 3
subroutine linear_clause_03(arg)
integer, intent(in) :: arg
- !ERROR: The list item `arg` specified with the REF 'linear-modifier' must be polymorphic variable, assumed-shape array, or a variable with the `ALLOCATABLE` attribute
!ERROR: List item 'arg' present at multiple LINEAR clauses
!ERROR: 'arg' appears in more than one data-sharing clause on the same OpenMP directive
!WARNING: The 'modifier(<list>)' syntax is deprecated in OpenMP v5.2, use '<list> : modifier' instead
@@ -68,3 +67,24 @@ subroutine linear_clause_04(x)
end do
!$omp end simd
end subroutine linear_clause_04
+
+! Case 5
+subroutine linear_clause_05(x)
+ integer :: x(:)
+ !ERROR: The list item `x` specified with the REF 'linear-modifier' must not be polymorphic variable, assumed-shape array, or a variable with the `ALLOCATABLE` attribute
+ !$omp declare simd linear(x : ref)
+end subroutine linear_clause_05
+
+! Case 6
+subroutine linear_clause_06(x)
+ integer, allocatable :: x(:)
+ !ERROR: The list item `x` specified with the REF 'linear-modifier' must not be polymorphic variable, assumed-shape array, or a variable with the `ALLOCATABLE` attribute
+ !$omp declare simd linear(x : ref)
+end subroutine linear_clause_06
+
+! Case 7
+subroutine linear_clause_07(x)
+ type(*) :: x(:)
+ !ERROR: The list item `x` specified with the REF 'linear-modifier' must not be polymorphic variable, assumed-shape array, or a variable with the `ALLOCATABLE` attribute
+ !$omp declare simd linear(x : ref)
+end subroutine linear_clause_07
diff --git a/flang/test/Semantics/OpenMP/linear-clause03.f90 b/flang/test/Semantics/OpenMP/linear-clause03.f90
index df74c906c2b2f0..dafc2e929801c8 100644
--- a/flang/test/Semantics/OpenMP/linear-clause03.f90
+++ b/flang/test/Semantics/OpenMP/linear-clause03.f90
@@ -4,7 +4,7 @@ module m
interface
subroutine f(x, y)
- integer, allocatable :: x
+ integer :: x
integer :: y
!WARNING: 'DECLARE SIMD' directive in an interface body has no effect [-Wopenmp-usage]
!$omp declare simd(f) linear(ref(x) : 1) linear(uval(y))
diff --git a/flang/test/Semantics/OpenMP/simd-linear-array.f90 b/flang/test/Semantics/OpenMP/simd-linear-array.f90
index 94c1fe43f8f81b..cfebace48ee597 100644
--- a/flang/test/Semantics/OpenMP/simd-linear-array.f90
+++ b/flang/test/Semantics/OpenMP/simd-linear-array.f90
@@ -73,9 +73,9 @@ subroutine test_multiple_scalars_valid()
! Valid case - declare simd with REF modifier allows arrays
subroutine test_declare_simd_ref_array_valid(arr)
implicit none
- integer, intent(in) :: arr(:)
+ integer, intent(in) :: arr(10)
!WARNING: The 'modifier(<list>)' syntax is deprecated in OpenMP v5.2, use '<list> : modifier' instead
!$omp declare simd linear(ref(arr))
- ! No error expected - REF modifier allows assumed-shape arrays
+ ! No error expected - REF modifier allows arrays
end subroutine
>From cc9d1af9a3b32e02def840dc314914f174e6d97e Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek <Krzysztof.Parzyszek at amd.com>
Date: Thu, 15 Oct 2026 10:59:28 -0500
Subject: [PATCH 2/5] Update flang/test/Semantics/OpenMP/linear-clause01.f90
---
flang/test/Semantics/OpenMP/linear-clause01.f90 | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/flang/test/Semantics/OpenMP/linear-clause01.f90 b/flang/test/Semantics/OpenMP/linear-clause01.f90
index d6d5162e4da1a0..7027898833003e 100644
--- a/flang/test/Semantics/OpenMP/linear-clause01.f90
+++ b/flang/test/Semantics/OpenMP/linear-clause01.f90
@@ -71,7 +71,7 @@ end subroutine linear_clause_04
! Case 5
subroutine linear_clause_05(x)
integer :: x(:)
- !ERROR: The list item `x` specified with the REF 'linear-modifier' must not be polymorphic variable, assumed-shape array, or a variable with the `ALLOCATABLE` attribute
+ !ERROR: The list item `x` specified with the REF 'linear-modifier' must not be a polymorphic variable, an assumed-shape array, or a variable with the `ALLOCATABLE` attribute
!$omp declare simd linear(x : ref)
end subroutine linear_clause_05
>From 29f842e8f13667b76aa3585365589ec2c5d9f05a Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek <Krzysztof.Parzyszek at amd.com>
Date: Thu, 15 Oct 2026 10:59:46 -0500
Subject: [PATCH 3/5] Update flang/lib/Semantics/check-omp-loop.cpp
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Co-authored-by: Markus Mützel <markus.muetzel at gmx.de>
---
flang/lib/Semantics/check-omp-loop.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/flang/lib/Semantics/check-omp-loop.cpp b/flang/lib/Semantics/check-omp-loop.cpp
index 2b2120075d97ec..514cc6feb26e5e 100644
--- a/flang/lib/Semantics/check-omp-loop.cpp
+++ b/flang/lib/Semantics/check-omp-loop.cpp
@@ -934,7 +934,7 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Linear &x) {
if (IsAllocatable(*symbol) || IsAssumedShape(*symbol) ||
IsPolymorphic(*symbol)) {
context_.Say(source,
- "The list item `%s` specified with the REF '%s' must not be polymorphic variable, assumed-shape array, or a variable with the `ALLOCATABLE` attribute"_err_en_US,
+ "The list item `%s` specified with the REF '%s' must not be a polymorphic variable, an assumed-shape array, or a variable with the `ALLOCATABLE` attribute"_err_en_US,
symbol->name(), desc.getName());
}
}
>From 921a614aecfd761719502be669199141784a52b0 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek <Krzysztof.Parzyszek at amd.com>
Date: Thu, 15 Oct 2026 11:00:02 -0500
Subject: [PATCH 4/5] Update flang/test/Semantics/OpenMP/linear-clause01.f90
---
flang/test/Semantics/OpenMP/linear-clause01.f90 | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/flang/test/Semantics/OpenMP/linear-clause01.f90 b/flang/test/Semantics/OpenMP/linear-clause01.f90
index 7027898833003e..3026f0a383cde9 100644
--- a/flang/test/Semantics/OpenMP/linear-clause01.f90
+++ b/flang/test/Semantics/OpenMP/linear-clause01.f90
@@ -78,7 +78,7 @@ end subroutine linear_clause_05
! Case 6
subroutine linear_clause_06(x)
integer, allocatable :: x(:)
- !ERROR: The list item `x` specified with the REF 'linear-modifier' must not be polymorphic variable, assumed-shape array, or a variable with the `ALLOCATABLE` attribute
+ !ERROR: The list item `x` specified with the REF 'linear-modifier' must not be a polymorphic variable, an assumed-shape array, or a variable with the `ALLOCATABLE` attribute
!$omp declare simd linear(x : ref)
end subroutine linear_clause_06
>From 463dbe921cc984742bdcd09106ee204de3cacb53 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek <Krzysztof.Parzyszek at amd.com>
Date: Thu, 15 Oct 2026 11:00:19 -0500
Subject: [PATCH 5/5] Update flang/test/Semantics/OpenMP/linear-clause01.f90
---
flang/test/Semantics/OpenMP/linear-clause01.f90 | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/flang/test/Semantics/OpenMP/linear-clause01.f90 b/flang/test/Semantics/OpenMP/linear-clause01.f90
index 3026f0a383cde9..dd10ceaf669ff4 100644
--- a/flang/test/Semantics/OpenMP/linear-clause01.f90
+++ b/flang/test/Semantics/OpenMP/linear-clause01.f90
@@ -85,6 +85,6 @@ end subroutine linear_clause_06
! Case 7
subroutine linear_clause_07(x)
type(*) :: x(:)
- !ERROR: The list item `x` specified with the REF 'linear-modifier' must not be polymorphic variable, assumed-shape array, or a variable with the `ALLOCATABLE` attribute
+ !ERROR: The list item `x` specified with the REF 'linear-modifier' must not be a polymorphic variable, an assumed-shape array, or a variable with the `ALLOCATABLE` attribute
!$omp declare simd linear(x : ref)
end subroutine linear_clause_07
More information about the flang-commits
mailing list