diff --git a/flang/lib/Semantics/check-omp-structure.h b/flang/lib/Semantics/check-omp-structure.h --- a/flang/lib/Semantics/check-omp-structure.h +++ b/flang/lib/Semantics/check-omp-structure.h @@ -162,8 +162,9 @@ void Enter(const parser::OmpReductionClause &); void Enter(const parser::OmpScheduleClause &); -private: + void CheckObjectListStructure(const parser::OmpObjectList &objList); +private: bool HasInvalidWorksharingNesting( const parser::CharBlock &, const OmpDirectiveSet &); diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp --- a/flang/lib/Semantics/check-omp-structure.cpp +++ b/flang/lib/Semantics/check-omp-structure.cpp @@ -407,15 +407,39 @@ CheckAllowed(llvm::omp::Clause::OMPC_priority); RequiresPositiveParameter(llvm::omp::Clause::OMPC_priority, x.v); } -void OmpStructureChecker::Enter(const parser::OmpClause::Private &) { +void OmpStructureChecker::Enter(const parser::OmpClause::Private &x) { CheckAllowed(llvm::omp::Clause::OMPC_private); + CheckObjectListStructure(x.v); } void OmpStructureChecker::Enter(const parser::OmpClause::Safelen &x) { CheckAllowed(llvm::omp::Clause::OMPC_safelen); RequiresConstantPositiveParameter(llvm::omp::Clause::OMPC_safelen, x.v); } -void OmpStructureChecker::Enter(const parser::OmpClause::Shared &) { +void OmpStructureChecker::Enter(const parser::OmpClause::Shared &x) { CheckAllowed(llvm::omp::Clause::OMPC_shared); + CheckObjectListStructure(x.v); +} +void OmpStructureChecker::CheckObjectListStructure( + const parser::OmpObjectList &objList) { + + for (const auto &ompObject : objList.v) { + std::visit( + common::visitors{ + [&](const parser::Designator &designator) { + if (std::get_if(&designator.u)) { + if ((parser::Unwrap(ompObject)) || + (parser::Unwrap(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); + } } void OmpStructureChecker::Enter(const parser::OmpClause::Simdlen &x) { CheckAllowed(llvm::omp::Clause::OMPC_simdlen); diff --git a/flang/test/Semantics/omp-parallel-private.f90 b/flang/test/Semantics/omp-parallel-private.f90 new file mode 100644 --- /dev/null +++ b/flang/test/Semantics/omp-parallel-private.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 --- /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 --- /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 --- /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-shared.f90 b/flang/test/Semantics/omp-parallel-shared.f90 new file mode 100644 --- /dev/null +++ b/flang/test/Semantics/omp-parallel-shared.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 --- /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 --- /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 --- /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