Skip to content

Commit 02db35a

Browse files
authored
[flang][OpenMP] Implement CheckReductionObjects for all reduction c… (#118689)
…lauses Currently we only do semantic checks for REDUCTION. There are two other clauses, IN_REDUCTION, and TASK_REDUCTION which will also need those checks. Implement a function that checks the common list-item requirements for all those clauses.
1 parent 7f4414b commit 02db35a

File tree

11 files changed

+237
-104
lines changed

11 files changed

+237
-104
lines changed

flang/lib/Semantics/check-omp-structure.cpp

Lines changed: 172 additions & 88 deletions
Large diffs are not rendered by default.

flang/lib/Semantics/check-omp-structure.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,14 @@ class OmpStructureChecker
146146
bool CheckAllowedClause(llvmOmpClause clause);
147147
bool IsVariableListItem(const Symbol &sym);
148148
bool IsExtendedListItem(const Symbol &sym);
149+
bool IsCommonBlock(const Symbol &sym);
149150
std::optional<bool> IsContiguous(const parser::OmpObject &object);
150151
void CheckMultipleOccurrence(semantics::UnorderedSymbolSet &listVars,
151152
const std::list<parser::Name> &nameList, const parser::CharBlock &item,
152153
const std::string &clauseName);
153154
void CheckMultListItems();
154-
void CheckStructureElement(const parser::OmpObjectList &ompObjectList,
155-
const llvm::omp::Clause clause);
155+
void CheckStructureComponent(
156+
const parser::OmpObjectList &objects, llvm::omp::Clause clauseId);
156157
bool HasInvalidWorksharingNesting(
157158
const parser::CharBlock &, const OmpDirectiveSet &);
158159
bool IsCloselyNestedRegion(const OmpDirectiveSet &set);
@@ -171,6 +172,9 @@ class OmpStructureChecker
171172
typename IterTy = decltype(std::declval<RangeTy>().begin())>
172173
std::optional<IterTy> FindDuplicate(RangeTy &&);
173174

175+
const Symbol *GetObjectSymbol(const parser::OmpObject &object);
176+
std::optional<parser::CharBlock> GetObjectSource(
177+
const parser::OmpObject &object);
174178
void CheckDependList(const parser::DataRef &);
175179
void CheckDependArraySection(
176180
const common::Indirection<parser::ArrayElement> &, const parser::Name &);
@@ -182,8 +186,8 @@ class OmpStructureChecker
182186
const parser::OmpObjectList &objList);
183187
void CheckSymbolNames(
184188
const parser::CharBlock &source, const parser::OmpObjectList &objList);
185-
void CheckIntentInPointer(
186-
const parser::OmpObjectList &, const llvm::omp::Clause);
189+
void CheckIntentInPointer(SymbolSourceMap &, const llvm::omp::Clause);
190+
void CheckProcedurePointer(SymbolSourceMap &, const llvm::omp::Clause);
187191
void GetSymbolsInObjectList(const parser::OmpObjectList &, SymbolSourceMap &);
188192
void CheckDefinableObjects(SymbolSourceMap &, const llvm::omp::Clause);
189193
void CheckCopyingPolymorphicAllocatable(
@@ -220,6 +224,8 @@ class OmpStructureChecker
220224
void CheckCancellationNest(
221225
const parser::CharBlock &source, const parser::OmpCancelType::Type &type);
222226
std::int64_t GetOrdCollapseLevel(const parser::OpenMPLoopConstruct &x);
227+
void CheckReductionObjects(
228+
const parser::OmpObjectList &objects, llvm::omp::Clause clauseId);
223229
bool CheckReductionOperators(const parser::OmpClause::Reduction &);
224230
bool CheckIntrinsicOperator(
225231
const parser::DefinedOperator::IntrinsicOperator &);
@@ -232,8 +238,6 @@ class OmpStructureChecker
232238
void ChecksOnOrderedAsStandalone();
233239
void CheckOrderedDependClause(std::optional<std::int64_t> orderedValue);
234240
void CheckReductionArraySection(const parser::OmpObjectList &ompObjectList);
235-
void CheckIntentInPointerAndDefinable(
236-
const parser::OmpObjectList &, const llvm::omp::Clause);
237241
void CheckArraySection(const parser::ArrayElement &arrayElement,
238242
const parser::Name &name, const llvm::omp::Clause clause);
239243
void CheckSharedBindingInOuterContext(

flang/test/Semantics/OpenMP/from-clause-v45.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
subroutine f00(x)
44
integer :: x(10)
5-
!ERROR: Reference to x must be a contiguous object
5+
!ERROR: Reference to 'x' must be a contiguous object
66
!$omp target update from(x(1:10:2))
77
end
88

flang/test/Semantics/OpenMP/reduction04.f90

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ program omp_Reduction
1414
end do
1515
!$omp end parallel do
1616

17-
!ERROR: Variable 'c' on the REDUCTION clause is not definable
18-
!BECAUSE: 'c' is not a variable
17+
!ERROR: Common block names are not allowed in REDUCTION clause
1918
!$omp parallel do reduction(*:/c/)
2019
do i = 1, 10
2120
l = k + 1

flang/test/Semantics/OpenMP/reduction06.f90

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@ program omp_reduction
88
integer :: k = 10
99
integer :: a(10), b(10,10,10)
1010

11-
!ERROR: A list item that appears in a REDUCTION clause should have a contiguous storage array section.
11+
!ERROR: Reference to 'a' must be a contiguous object
1212
!$omp parallel do reduction(+:a(1:10:3))
1313
do i = 1, 10
1414
k = k + 1
1515
end do
1616
!$omp end parallel do
1717

18-
!ERROR: A list item that appears in a REDUCTION clause should have a contiguous storage array section.
18+
!ERROR: Reference to 'b' must be a contiguous object
1919
!$omp parallel do reduction(+:b(1:10:3,1:8:1,1:5:1))
2020
do i = 1, 10
2121
k = k + 1
2222
end do
2323
!$omp end parallel do
2424

25-
!ERROR: A list item that appears in a REDUCTION clause should have a contiguous storage array section.
25+
!ERROR: Reference to 'b' must be a contiguous object
2626
!$omp parallel do reduction(+:b(1:10:1,1:8:2,1:5:1))
2727
do i = 1, 10
2828
k = k + 1

flang/test/Semantics/OpenMP/reduction12.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
procedure(foo), pointer :: ptr
77
integer :: i
88
ptr => foo
9-
!ERROR: A procedure pointer 'ptr' must not appear in a REDUCTION clause.
9+
!ERROR: Procedure pointer 'ptr' may not appear in a REDUCTION clause
1010
!$omp do reduction (+ : ptr)
1111
do i = 1, 10
1212
end do
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
!RUN: %python %S/../test_errors.py %s %flang_fc1 -fopenmp -fopenmp-version=50
2+
3+
!Ref: [5.0:297:28-29]
4+
! If a list item is an array section or an array element, its base expression
5+
! must be a base language identifier.
6+
7+
module m
8+
type t
9+
integer :: a(10)
10+
end type
11+
12+
contains
13+
14+
subroutine f00
15+
type(t) :: x
16+
!ERROR: The base expression of an array element or section in REDUCTION clause must be an identifier
17+
!$omp do reduction (+ : x%a(2))
18+
do i = 1, 10
19+
end do
20+
!$omp end do
21+
end subroutine
22+
23+
subroutine f01
24+
type(t) :: x
25+
!ERROR: The base expression of an array element or section in REDUCTION clause must be an identifier
26+
!$omp do reduction (+ : x%a(1:10))
27+
do i = 1, 10
28+
end do
29+
!$omp end do
30+
end subroutine
31+
end
32+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
!RUN: %python %S/../test_errors.py %s %flang_fc1 -fopenmp -fopenmp-version=50
2+
3+
!Ref: [5.0:298:19]
4+
! A type parameter inquiry cannot appear in a reduction clause.
5+
6+
subroutine f00
7+
integer :: x
8+
!ERROR: Type parameter inquiry is not permitted in REDUCTION clause
9+
!$omp do reduction (+ : x%kind)
10+
do i = 1, 10
11+
end do
12+
!$omp end do
13+
end subroutine
14+

flang/test/Semantics/OpenMP/to-clause-v45.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
subroutine f00(x)
44
integer :: x(10)
5-
!ERROR: Reference to x must be a contiguous object
5+
!ERROR: Reference to 'x' must be a contiguous object
66
!$omp target update to(x(1:10:2))
77
end
88

flang/test/Semantics/OpenMP/use_device_addr1.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ subroutine omp_target_data
1515
type(my_type) :: my_var
1616
a = 1
1717

18-
!ERROR: A variable that is part of another variable (structure element) cannot appear on the TARGET DATA USE_DEVICE_ADDR clause
18+
!ERROR: A variable that is part of another variable cannot appear on the USE_DEVICE_ADDR clause
1919
!$omp target data map(tofrom: a) use_device_addr(my_var%my_b)
2020
my_var%my_b = a
2121
!$omp end target data

flang/test/Semantics/OpenMP/use_device_ptr1.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ subroutine omp_target_data
2020
type(my_type) :: my_var
2121
a = 1
2222

23-
!ERROR: A variable that is part of another variable (structure element) cannot appear on the TARGET DATA USE_DEVICE_PTR clause
23+
!ERROR: A variable that is part of another variable cannot appear on the USE_DEVICE_PTR clause
2424
!$omp target data map(tofrom: a, arrayB) use_device_ptr(my_var%my_cptr)
2525
allocate(arrayB)
2626
call c_f_pointer(my_var%my_cptr, arrayB)

0 commit comments

Comments
 (0)