Skip to content

Commit 39be2d0

Browse files
authored
[flang][OpenMP][Semantics] Don't allow reduction of derived type components (#125480)
Before this patch, reduction of derived type components crashed the compiler when trying to create the omp.declare_reduction. In OpenMP 3.1 the standard says "a list item that appears in a reduction clause must be a named variable of intrinsic type" (page 106). As I understand it, a derived type component is not a variable. OpenMP 4.0 added declare reduction, partly so that users could define their own reductions on derived types. The above wording was removed from the standard but derived type components were never explicitly allowed. OpenMP 5.0 added "A variable that is part of another variable, with the exception of array elements, cannot appear in17 a reduction clause". All standard versions also require the reduction argument to be "definable", which roughly means that it is a variable. A derived type component is more like an expression. Fixes #125445
1 parent ceaec56 commit 39be2d0

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3225,9 +3225,12 @@ void OmpStructureChecker::CheckReductionObjects(
32253225
}
32263226
}
32273227

3228+
// Denied in all current versions of the standard because structure components
3229+
// are not definable (i.e. they are expressions not variables).
3230+
// Object cannot be a part of another object (except array elements).
3231+
CheckStructureComponent(objects, clauseId);
3232+
32283233
if (version >= 50) {
3229-
// Object cannot be a part of another object (except array elements)
3230-
CheckStructureComponent(objects, clauseId);
32313234
// If object is an array section or element, the base expression must be
32323235
// a language identifier.
32333236
for (const parser::OmpObject &object : objects.v) {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
! RUN: %python %S/../test_errors.py %s %flang_fc1 -fopenmp
2+
subroutine intrinsic_reduction
3+
type local
4+
integer alpha
5+
end type local
6+
type(local) a
7+
!ERROR: A variable that is part of another variable cannot appear on the REDUCTION clause
8+
!$omp parallel reduction(+:a%alpha)
9+
!$omp end parallel
10+
end subroutine intrinsic_reduction

0 commit comments

Comments
 (0)