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 @@ -173,6 +173,8 @@ bool ScheduleModifierHasType(const parser::OmpScheduleClause &, const parser::OmpScheduleModifierType::ModType &); + void CheckIsVarPartOfAnotherVar(const parser::OmpObjectList &objList); + llvm::StringRef getClauseName(llvm::omp::Clause clause) override; llvm::StringRef getDirectiveName(llvm::omp::Directive directive) override; }; 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 @@ -385,8 +385,6 @@ 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) @@ -421,6 +419,37 @@ } } +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(&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); + } +} // 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/test/Semantics/omp-parallel-private01.f90 b/flang/test/Semantics/omp-parallel-private01.f90 new file mode 100644 --- /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 --- /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-shared01.f90 b/flang/test/Semantics/omp-parallel-shared01.f90 new file mode 100644 --- /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 --- /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