Skip to content

[Flang][OpenMP] Add restriction about subobjects to firstprivate and … #89608

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions flang/lib/Semantics/check-omp-structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2471,11 +2471,11 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Ordered &x) {

void OmpStructureChecker::Enter(const parser::OmpClause::Shared &x) {
CheckAllowed(llvm::omp::Clause::OMPC_shared);
CheckIsVarPartOfAnotherVar(GetContext().clauseSource, x.v);
CheckIsVarPartOfAnotherVar(GetContext().clauseSource, x.v, "SHARED");
}
void OmpStructureChecker::Enter(const parser::OmpClause::Private &x) {
CheckAllowed(llvm::omp::Clause::OMPC_private);
CheckIsVarPartOfAnotherVar(GetContext().clauseSource, x.v);
CheckIsVarPartOfAnotherVar(GetContext().clauseSource, x.v, "PRIVATE");
CheckIntentInPointer(x.v, llvm::omp::Clause::OMPC_private);
}

Expand Down Expand Up @@ -2513,7 +2513,8 @@ bool OmpStructureChecker::IsDataRefTypeParamInquiry(
}

void OmpStructureChecker::CheckIsVarPartOfAnotherVar(
const parser::CharBlock &source, const parser::OmpObjectList &objList) {
const parser::CharBlock &source, const parser::OmpObjectList &objList,
llvm::StringRef clause) {
for (const auto &ompObject : objList.v) {
common::visit(
common::visitors{
Expand All @@ -2539,7 +2540,8 @@ void OmpStructureChecker::CheckIsVarPartOfAnotherVar(
context_.Say(source,
"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);
"%s clause"_err_en_US,
clause.data());
}
}
}
Expand All @@ -2552,6 +2554,8 @@ void OmpStructureChecker::CheckIsVarPartOfAnotherVar(

void OmpStructureChecker::Enter(const parser::OmpClause::Firstprivate &x) {
CheckAllowed(llvm::omp::Clause::OMPC_firstprivate);

CheckIsVarPartOfAnotherVar(GetContext().clauseSource, x.v, "FIRSTPRIVATE");
CheckIsLoopIvPartOfClause(llvmOmpClause::OMPC_firstprivate, x.v);

SymbolSourceMap currSymbols;
Expand Down Expand Up @@ -2888,6 +2892,8 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Copyprivate &x) {
void OmpStructureChecker::Enter(const parser::OmpClause::Lastprivate &x) {
CheckAllowed(llvm::omp::Clause::OMPC_lastprivate);

CheckIsVarPartOfAnotherVar(GetContext().clauseSource, x.v, "LASTPRIVATE");

DirectivesClauseTriple dirClauseTriple;
SymbolSourceMap currSymbols;
GetSymbolsInObjectList(x.v, currSymbols);
Expand Down
4 changes: 2 additions & 2 deletions flang/lib/Semantics/check-omp-structure.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ class OmpStructureChecker
void CheckDependArraySection(
const common::Indirection<parser::ArrayElement> &, const parser::Name &);
bool IsDataRefTypeParamInquiry(const parser::DataRef *dataRef);
void CheckIsVarPartOfAnotherVar(
const parser::CharBlock &source, const parser::OmpObjectList &objList);
void CheckIsVarPartOfAnotherVar(const parser::CharBlock &source,
const parser::OmpObjectList &objList, llvm::StringRef clause = "");
void CheckThreadprivateOrDeclareTargetVar(
const parser::OmpObjectList &objList);
void CheckSymbolNames(
Expand Down
20 changes: 20 additions & 0 deletions flang/test/Semantics/OpenMP/firstprivate02.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
! RUN: %python %S/../test_errors.py %s %flang -fopenmp
! OpenMP Version 5.2, Sections 3.2.1 & 5.3
subroutine omp_firstprivate(init)
integer :: init
integer :: a(10)
type my_type
integer :: val
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 FIRSTPRIVATE clause
!$omp parallel firstprivate(a(2))
a(2) = init
!$omp end parallel

!ERROR: A variable that is part of another variable (as an array or structure element) cannot appear in a FIRSTPRIVATE clause
!$omp parallel firstprivate(my_var%val)
my_var%val = init
!$omp end parallel
end subroutine
24 changes: 24 additions & 0 deletions flang/test/Semantics/OpenMP/lastprivate03.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
! RUN: %python %S/../test_errors.py %s %flang -fopenmp
! OpenMP Version 5.2, Sections 3.2.1 & 5.3
subroutine omp_lastprivate(init)
integer :: init
integer :: i, a(10)
type my_type
integer :: val
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 LASTPRIVATE clause
!$omp do lastprivate(a(2))
do i=1, 10
a(2) = init
end do
!$omp end do

!ERROR: A variable that is part of another variable (as an array or structure element) cannot appear in a LASTPRIVATE clause
!$omp do lastprivate(my_var%val)
do i=1, 10
my_var%val = init
end do
!$omp end do
end subroutine
2 changes: 1 addition & 1 deletion flang/test/Semantics/OpenMP/parallel-private01.f90
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ program omp_parallel_private

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
!ERROR: A variable that is part of another variable (as an array or structure element) cannot appear in a PRIVATE clause
!$omp parallel private(my_var%array)
do i = 1, 10
c(i) = a(i) + b(i) + k
Expand Down
2 changes: 1 addition & 1 deletion flang/test/Semantics/OpenMP/parallel-private02.f90
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ program omp_parallel_private
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
!ERROR: A variable that is part of another variable (as an array or structure element) cannot appear in a PRIVATE clause
!$omp parallel private(array(i))
do i = 1, 10
c(i) = a(i) + b(i) + k
Expand Down
2 changes: 1 addition & 1 deletion flang/test/Semantics/OpenMP/parallel-private03.f90
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ program omp_parallel_private
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
!ERROR: A variable that is part of another variable (as an array or structure element) cannot appear in a PRIVATE clause
!$omp parallel private(arr(i),intx)
do i = 1, 10
c(i) = a(i) + b(i) + k
Expand Down
2 changes: 1 addition & 1 deletion flang/test/Semantics/OpenMP/parallel-private04.f90
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ program omp_parallel_private
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
!ERROR: A variable that is part of another variable (as an array or structure element) cannot appear in a PRIVATE clause
!$omp parallel private(arr,intx,my_var%array(1))
do i = 1, 10
c(i) = a(i) + b(i) + k
Expand Down
8 changes: 4 additions & 4 deletions flang/test/Semantics/OpenMP/parallel-sections01.f90
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ program OmpConstructSections01
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
!ERROR: A variable that is part of another variable (as an array or structure element) cannot appear in a SHARED clause
!$omp parallel sections shared(array(i))
!$omp end parallel sections
!ERROR: A variable that is part of another variable (as an array or structure element) cannot appear in a PRIVATE or SHARED clause
!ERROR: A variable that is part of another variable (as an array or structure element) cannot appear in a SHARED clause
!$omp parallel sections shared(my_var%array)
!$omp end parallel sections

Expand All @@ -30,7 +30,7 @@ program OmpConstructSections01
if (NT) 20, 30, 40
!ERROR: invalid branch into an OpenMP structured block
goto 20
!ERROR: A variable that is part of another variable (as an array or structure element) cannot appear in a PRIVATE or SHARED clause
!ERROR: A variable that is part of another variable (as an array or structure element) cannot appear in a PRIVATE clause
!$omp parallel sections private(my_var%array)
!$omp section
print *, "This is a single statement structured block"
Expand All @@ -53,7 +53,7 @@ program OmpConstructSections01
30 print *, "Error in opening file"
!$omp end parallel sections
10 print *, 'Jump from section'
!ERROR: A variable that is part of another variable (as an array or structure element) cannot appear in a PRIVATE or SHARED clause
!ERROR: A variable that is part of another variable (as an array or structure element) cannot appear in a PRIVATE clause
!$omp parallel sections private(array(i))
!$omp section
40 print *, 'Error in opening file'
Expand Down
2 changes: 1 addition & 1 deletion flang/test/Semantics/OpenMP/parallel-shared01.f90
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ program omp_parallel_shared

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
!ERROR: A variable that is part of another variable (as an array or structure element) cannot appear in a SHARED clause
!$omp parallel shared(my_var%array)
do i = 1, 10
c(i) = a(i) + b(i) + k
Expand Down
2 changes: 1 addition & 1 deletion flang/test/Semantics/OpenMP/parallel-shared02.f90
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ program omp_parallel_shared
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
!ERROR: A variable that is part of another variable (as an array or structure element) cannot appear in a SHARED clause
!$omp parallel shared(array(i))
do i = 1, 10
c(i) = a(i) + b(i) + k
Expand Down
2 changes: 1 addition & 1 deletion flang/test/Semantics/OpenMP/parallel-shared03.f90
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ program omp_parallel_shared
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
!ERROR: A variable that is part of another variable (as an array or structure element) cannot appear in a SHARED clause
!$omp parallel shared(arr(i),intx)
do i = 1, 10
c(i) = a(i) + b(i) + k
Expand Down
2 changes: 1 addition & 1 deletion flang/test/Semantics/OpenMP/parallel-shared04.f90
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ program omp_parallel_shared
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
!ERROR: A variable that is part of another variable (as an array or structure element) cannot appear in a SHARED clause
!$omp parallel shared(arr,intx,my_var%array(1))
do i = 1, 10
c(i) = a(i) + b(i) + k
Expand Down
Loading