[flang-commits] [flang] [Flang][Semantics] Add a semantic check for simd construct (PR #109089)
Thirumalai Shaktivel via flang-commits
flang-commits at lists.llvm.org
Tue Sep 17 23:18:45 PDT 2024
https://github.com/Thirumalai-Shaktivel created https://github.com/llvm/llvm-project/pull/109089
Add:
- Missing semantic check for the SAFELEN clause in the SIMD Order construct
- Missing tests
>From e781e10e746825a6595fe984cfc3d1489a1d3a85 Mon Sep 17 00:00:00 2001
From: Thirumalai Shaktivel C <tshaktiv at amd.com>
Date: Wed, 18 Sep 2024 06:08:08 +0000
Subject: [PATCH 1/2] [Flang][OpenMP][Semantics] Add a semantic check for simd
construct,
Fix: Add a missing semantic check for the SAFELEN clause in the SIMD Order construct
---
flang/lib/Semantics/check-omp-structure.cpp | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index 643b713b32e29d..eac856f56fe8fd 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -2156,6 +2156,16 @@ void OmpStructureChecker::Leave(const parser::OmpClauseList &) {
}
}
}
+
+ // 2.11.5 Simd construct restriction (OpenMP 5.1)
+ if ( auto *clause{FindClause(llvm::omp::Clause::OMPC_safelen)} ) {
+ if ( FindClause(llvm::omp::Clause::OMPC_order) ) {
+ context_.Say(clause->source,
+ "The `SAFELEN` clause cannot appear in the `SIMD` directive "
+ "with `ORDER(CONCURRENT)` clause"_err_en_US);
+ }
+ }
+
// Sema checks related to presence of multiple list items within the same
// clause
CheckMultListItems();
>From ec8fcc6711b2db468657d91d5dfeba985c308beb Mon Sep 17 00:00:00 2001
From: Thirumalai Shaktivel C <tshaktiv at amd.com>
Date: Wed, 18 Sep 2024 06:09:19 +0000
Subject: [PATCH 2/2] [Test] Add some missing tests, - At most one Collapse
clause in SIMD construct - A DO loop must follow the SIMD directive
---
flang/test/Semantics/OpenMP/clause-validity01.f90 | 6 ++++++
flang/test/Semantics/OpenMP/do-collapse.f90 | 8 +++++++-
flang/test/Semantics/OpenMP/loop-association.f90 | 6 ++++++
3 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/flang/test/Semantics/OpenMP/clause-validity01.f90 b/flang/test/Semantics/OpenMP/clause-validity01.f90
index 020d63f735596d..9344258b9c1522 100644
--- a/flang/test/Semantics/OpenMP/clause-validity01.f90
+++ b/flang/test/Semantics/OpenMP/clause-validity01.f90
@@ -390,6 +390,12 @@
enddo
!$omp end parallel
+ !ERROR: The `SAFELEN` clause cannot appear in the `SIMD` directive with `ORDER(CONCURRENT)` clause
+ !$omp simd order(concurrent) safelen(1+2)
+ do i = 1, N
+ a = 3.14
+ enddo
+
! 2.11.1 parallel-do-clause -> parallel-clause |
! do-clause
diff --git a/flang/test/Semantics/OpenMP/do-collapse.f90 b/flang/test/Semantics/OpenMP/do-collapse.f90
index 4f2512937ace4e..480bd45b79b839 100644
--- a/flang/test/Semantics/OpenMP/do-collapse.f90
+++ b/flang/test/Semantics/OpenMP/do-collapse.f90
@@ -30,5 +30,11 @@ program omp_doCollapse
do
end do
end do
-end program omp_doCollapse
+ !ERROR: At most one COLLAPSE clause can appear on the SIMD directive
+ !$omp simd collapse(2) collapse(1)
+ do i = 1, 4
+ j = j + i + 1
+ end do
+ !$omp end simd
+end program omp_doCollapse
diff --git a/flang/test/Semantics/OpenMP/loop-association.f90 b/flang/test/Semantics/OpenMP/loop-association.f90
index d2167663c5ddea..9fac508e6128a7 100644
--- a/flang/test/Semantics/OpenMP/loop-association.f90
+++ b/flang/test/Semantics/OpenMP/loop-association.f90
@@ -131,4 +131,10 @@
!$omp end parallel do simd
!ERROR: The END PARALLEL DO SIMD directive must follow the DO loop associated with the loop construct
!$omp end parallel do simd
+
+ !ERROR: A DO loop must follow the SIMD directive
+ !$omp simd
+ a = i + 1
+ !ERROR: The END SIMD directive must follow the DO loop associated with the loop construct
+ !$omp end simd
end
More information about the flang-commits
mailing list