[flang-commits] [flang] 3ee08e3 - Add Semantic check for Flang OpenMP 4.5 - 2.15.3.2 and 2.15.3.3 shared and private clause
via flang-commits
flang-commits at lists.llvm.org
Sat Nov 21 23:28:33 PST 2020
Author: Yashaswini
Date: 2020-11-22T12:50:17+05:30
New Revision: 3ee08e38194ac05e42f8c5a633dc1aa8e41139f4
URL: https://github.com/llvm/llvm-project/commit/3ee08e38194ac05e42f8c5a633dc1aa8e41139f4
DIFF: https://github.com/llvm/llvm-project/commit/3ee08e38194ac05e42f8c5a633dc1aa8e41139f4.diff
LOG: Add Semantic check for Flang OpenMP 4.5 - 2.15.3.2 and 2.15.3.3 shared and private clause
Semantic check to restrict the appearance of a variable that is part of another variable
(as an array or structure element) in a PRIVATE or SHARED clause.
Test Cases:
omp-parallel-private01.f90
omp-parallel-private02.f90
omp-parallel-private03.f90
omp-parallel-private04.f90
omp-parallel-shared01.f90
omp-parallel-shared02.f90
omp-parallel-shared03.f90
omp-parallel-shared04.f90
Reviewed by: Kiran Chandramohan @kiranchandramohan , Valentin Clement @clementval
Differential Revision: https://reviews.llvm.org/D89395
Added:
flang/test/Semantics/omp-parallel-private01.f90
flang/test/Semantics/omp-parallel-private02.f90
flang/test/Semantics/omp-parallel-private03.f90
flang/test/Semantics/omp-parallel-private04.f90
flang/test/Semantics/omp-parallel-shared01.f90
flang/test/Semantics/omp-parallel-shared02.f90
flang/test/Semantics/omp-parallel-shared03.f90
flang/test/Semantics/omp-parallel-shared04.f90
Modified:
flang/lib/Semantics/check-omp-structure.cpp
flang/lib/Semantics/check-omp-structure.h
Removed:
################################################################################
diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index d3430d724651..636471da78d1 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -372,8 +372,6 @@ CHECK_SIMPLE_CLAUSE(Link, OMPC_link)
CHECK_SIMPLE_CLAUSE(Mergeable, OMPC_mergeable)
CHECK_SIMPLE_CLAUSE(Nogroup, OMPC_nogroup)
CHECK_SIMPLE_CLAUSE(Notinbranch, OMPC_notinbranch)
-CHECK_SIMPLE_CLAUSE(Private, OMPC_private)
-CHECK_SIMPLE_CLAUSE(Shared, OMPC_shared)
CHECK_SIMPLE_CLAUSE(To, OMPC_to)
CHECK_SIMPLE_CLAUSE(Uniform, OMPC_uniform)
CHECK_SIMPLE_CLAUSE(Untied, OMPC_untied)
@@ -412,6 +410,37 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Ordered &x) {
}
}
+void OmpStructureChecker::Enter(const parser::OmpClause::Shared &x) {
+ CheckAllowed(llvm::omp::Clause::OMPC_shared);
+ CheckIsVarPartOfAnotherVar(x.v);
+}
+void OmpStructureChecker::Enter(const parser::OmpClause::Private &x) {
+ CheckAllowed(llvm::omp::Clause::OMPC_private);
+ CheckIsVarPartOfAnotherVar(x.v);
+}
+
+void OmpStructureChecker::CheckIsVarPartOfAnotherVar(
+ const parser::OmpObjectList &objList) {
+
+ for (const auto &ompObject : objList.v) {
+ std::visit(
+ common::visitors{
+ [&](const parser::Designator &designator) {
+ if (std::get_if<parser::DataRef>(&designator.u)) {
+ if ((parser::Unwrap<parser::StructureComponent>(ompObject)) ||
+ (parser::Unwrap<parser::ArrayElement>(ompObject))) {
+ context_.Say(GetContext().clauseSource,
+ "A variable that is part of another variable (as an "
+ "array or structure element)"
+ " cannot appear in a PRIVATE or SHARED clause."_err_en_US);
+ }
+ }
+ },
+ [&](const parser::Name &name) {},
+ },
+ ompObject.u);
+ }
+}
// Following clauses have a seperate node in parse-tree.h.
CHECK_SIMPLE_PARSER_CLAUSE(OmpAllocateClause, OMPC_allocate)
CHECK_SIMPLE_PARSER_CLAUSE(OmpDefaultClause, OMPC_default)
diff --git a/flang/lib/Semantics/check-omp-structure.h b/flang/lib/Semantics/check-omp-structure.h
index 8384efecb840..5539ca2566f2 100644
--- a/flang/lib/Semantics/check-omp-structure.h
+++ b/flang/lib/Semantics/check-omp-structure.h
@@ -185,6 +185,8 @@ class OmpStructureChecker
void CheckDependList(const parser::DataRef &);
void CheckDependArraySection(
const common::Indirection<parser::ArrayElement> &, const parser::Name &);
+
+ void CheckIsVarPartOfAnotherVar(const parser::OmpObjectList &objList);
};
} // namespace Fortran::semantics
#endif // FORTRAN_SEMANTICS_CHECK_OMP_STRUCTURE_H_
diff --git a/flang/test/Semantics/omp-parallel-private01.f90 b/flang/test/Semantics/omp-parallel-private01.f90
new file mode 100644
index 000000000000..029c36ffeeb5
--- /dev/null
+++ b/flang/test/Semantics/omp-parallel-private01.f90
@@ -0,0 +1,20 @@
+!RUN: %S/test_errors.sh %s %t %f18 -fopenmp
+! OpenMP Version 4.5
+! 2.15.3.3 parallel private Clause
+program omp_parallel_private
+ integer :: i, j, a(10), b(10), c(10)
+ integer :: k = 10
+ type my_type
+ integer :: array(10)
+ end type my_type
+
+ type(my_type) :: my_var
+
+ !ERROR: A variable that is part of another variable (as an array or structure element) cannot appear in a PRIVATE or SHARED clause.
+ !$omp parallel private(my_var%array)
+ do i = 1, 10
+ c(i) = a(i) + b(i) + k
+ my_var%array(i) = k
+ end do
+ !$omp end parallel
+end program omp_parallel_private
diff --git a/flang/test/Semantics/omp-parallel-private02.f90 b/flang/test/Semantics/omp-parallel-private02.f90
new file mode 100644
index 000000000000..b452b0eb7501
--- /dev/null
+++ b/flang/test/Semantics/omp-parallel-private02.f90
@@ -0,0 +1,20 @@
+!RUN: %S/test_errors.sh %s %t %f18 -fopenmp
+! OpenMP Version 4.5
+! 2.15.3.3 parallel private Clause
+program omp_parallel_private
+ integer :: i, j, a(10), b(10), c(10)
+ integer :: k = 10
+ integer :: array(10)
+
+ do i = 1, 10
+ array(i) = i
+ end do
+
+ !ERROR: A variable that is part of another variable (as an array or structure element) cannot appear in a PRIVATE or SHARED clause.
+ !$omp parallel private(array(i))
+ do i = 1, 10
+ c(i) = a(i) + b(i) + k
+ array(i) = k
+ end do
+ !$omp end parallel
+end program omp_parallel_private
diff --git a/flang/test/Semantics/omp-parallel-private03.f90 b/flang/test/Semantics/omp-parallel-private03.f90
new file mode 100644
index 000000000000..18d5bc171027
--- /dev/null
+++ b/flang/test/Semantics/omp-parallel-private03.f90
@@ -0,0 +1,28 @@
+!RUN: %S/test_errors.sh %s %t %f18 -fopenmp
+! OpenMP Version 4.5
+! 2.15.3.3 parallel private Clause
+program omp_parallel_private
+ integer :: i, j, a(10), b(10), c(10)
+ integer :: k = 10
+ type my_type
+ integer :: array(10)
+ end type my_type
+
+ type(my_type) :: my_var
+
+ real :: arr(10)
+ integer :: intx = 10
+
+ do i = 1, 10
+ arr(i) = 0.0
+ end do
+
+ !ERROR: A variable that is part of another variable (as an array or structure element) cannot appear in a PRIVATE or SHARED clause.
+ !$omp parallel private(arr(i),intx)
+ do i = 1, 10
+ c(i) = a(i) + b(i) + k
+ my_var%array(i) = k+intx
+ arr(i) = k
+ end do
+ !$omp end parallel
+end program omp_parallel_private
diff --git a/flang/test/Semantics/omp-parallel-private04.f90 b/flang/test/Semantics/omp-parallel-private04.f90
new file mode 100644
index 000000000000..9a8765b12635
--- /dev/null
+++ b/flang/test/Semantics/omp-parallel-private04.f90
@@ -0,0 +1,28 @@
+!RUN: %S/test_errors.sh %s %t %f18 -fopenmp
+! OpenMP Version 4.5
+! 2.15.3.3 parallel private Clause
+program omp_parallel_private
+ integer :: i, j, a(10), b(10), c(10)
+ integer :: k = 10
+ type my_type
+ integer :: array(10)
+ end type my_type
+
+ type(my_type) :: my_var
+
+ real :: arr(10)
+ integer :: intx = 10
+
+ do i = 1, 10
+ arr(i) = 0.0
+ end do
+
+ !ERROR: A variable that is part of another variable (as an array or structure element) cannot appear in a PRIVATE or SHARED clause.
+ !$omp parallel private(arr,intx,my_var%array(1))
+ do i = 1, 10
+ c(i) = a(i) + b(i) + k
+ my_var%array(i) = k+intx
+ arr(i) = k
+ end do
+ !$omp end parallel
+end program omp_parallel_private
diff --git a/flang/test/Semantics/omp-parallel-shared01.f90 b/flang/test/Semantics/omp-parallel-shared01.f90
new file mode 100644
index 000000000000..7dda194d0e29
--- /dev/null
+++ b/flang/test/Semantics/omp-parallel-shared01.f90
@@ -0,0 +1,20 @@
+!RUN: %S/test_errors.sh %s %t %f18 -fopenmp
+! OpenMP Version 4.5
+! 2.15.3.2 parallel shared Clause
+program omp_parallel_shared
+ integer :: i, j, a(10), b(10), c(10)
+ integer :: k = 10
+ type my_type
+ integer :: array(10)
+ end type my_type
+
+ type(my_type) :: my_var
+
+ !ERROR: A variable that is part of another variable (as an array or structure element) cannot appear in a PRIVATE or SHARED clause.
+ !$omp parallel shared(my_var%array)
+ do i = 1, 10
+ c(i) = a(i) + b(i) + k
+ my_var%array(i) = k
+ end do
+ !$omp end parallel
+end program omp_parallel_shared
diff --git a/flang/test/Semantics/omp-parallel-shared02.f90 b/flang/test/Semantics/omp-parallel-shared02.f90
new file mode 100644
index 000000000000..50b2ece0c058
--- /dev/null
+++ b/flang/test/Semantics/omp-parallel-shared02.f90
@@ -0,0 +1,20 @@
+!RUN: %S/test_errors.sh %s %t %f18 -fopenmp
+! OpenMP Version 4.5
+! 2.15.3.2 parallel shared Clause
+program omp_parallel_shared
+ integer :: i, j, a(10), b(10), c(10)
+ integer :: k = 10
+ integer :: array(10)
+
+ do i = 1, 10
+ array(i) = i
+ end do
+
+ !ERROR: A variable that is part of another variable (as an array or structure element) cannot appear in a PRIVATE or SHARED clause.
+ !$omp parallel shared(array(i))
+ do i = 1, 10
+ c(i) = a(i) + b(i) + k
+ array(i) = k
+ end do
+ !$omp end parallel
+end program omp_parallel_shared
diff --git a/flang/test/Semantics/omp-parallel-shared03.f90 b/flang/test/Semantics/omp-parallel-shared03.f90
new file mode 100644
index 000000000000..386023e452f9
--- /dev/null
+++ b/flang/test/Semantics/omp-parallel-shared03.f90
@@ -0,0 +1,28 @@
+!RUN: %S/test_errors.sh %s %t %f18 -fopenmp
+! OpenMP Version 4.5
+! 2.15.3.2 parallel shared Clause
+program omp_parallel_shared
+ integer :: i, j, a(10), b(10), c(10)
+ integer :: k = 10
+ type my_type
+ integer :: array(10)
+ end type my_type
+
+ type(my_type) :: my_var
+
+ real :: arr(10)
+ integer :: intx = 10
+
+ do i = 1, 10
+ arr(i) = 0.0
+ end do
+
+ !ERROR: A variable that is part of another variable (as an array or structure element) cannot appear in a PRIVATE or SHARED clause.
+ !$omp parallel shared(arr(i),intx)
+ do i = 1, 10
+ c(i) = a(i) + b(i) + k
+ my_var%array(i) = k+intx
+ arr(i) = k
+ end do
+ !$omp end parallel
+end program omp_parallel_shared
diff --git a/flang/test/Semantics/omp-parallel-shared04.f90 b/flang/test/Semantics/omp-parallel-shared04.f90
new file mode 100644
index 000000000000..3a7c3f940e2a
--- /dev/null
+++ b/flang/test/Semantics/omp-parallel-shared04.f90
@@ -0,0 +1,28 @@
+!RUN: %S/test_errors.sh %s %t %f18 -fopenmp
+! OpenMP Version 4.5
+! 2.15.3.2 parallel shared Clause
+program omp_parallel_shared
+ integer :: i, j, a(10), b(10), c(10)
+ integer :: k = 10
+ type my_type
+ integer :: array(10)
+ end type my_type
+
+ type(my_type) :: my_var
+
+ real :: arr(10)
+ integer :: intx = 10
+
+ do i = 1, 10
+ arr(i) = 0.0
+ end do
+
+ !ERROR: A variable that is part of another variable (as an array or structure element) cannot appear in a PRIVATE or SHARED clause.
+ !$omp parallel shared(arr,intx,my_var%array(1))
+ do i = 1, 10
+ c(i) = a(i) + b(i) + k
+ my_var%array(i) = k+intx
+ arr(i) = k
+ end do
+ !$omp end parallel
+end program omp_parallel_shared
More information about the flang-commits
mailing list