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 @@ -1924,13 +1924,17 @@ switch (op) { case parser::DefinedOperator::IntrinsicOperator::Add: - case parser::DefinedOperator::IntrinsicOperator::Subtract: case parser::DefinedOperator::IntrinsicOperator::Multiply: case parser::DefinedOperator::IntrinsicOperator::AND: case parser::DefinedOperator::IntrinsicOperator::OR: case parser::DefinedOperator::IntrinsicOperator::EQV: case parser::DefinedOperator::IntrinsicOperator::NEQV: return true; + case parser::DefinedOperator::IntrinsicOperator::Subtract: + context_.Say(GetContext().clauseSource, + "The minus reduction operator is deprecated since OpenMP 5.2 and is not supported in the REDUCTION clause."_err_en_US, + ContextDirectiveAsFortran()); + break; default: context_.Say(GetContext().clauseSource, "Invalid reduction operator in REDUCTION clause."_err_en_US, diff --git a/flang/test/Lower/OpenMP/Todo/reduction-subtract.f90 b/flang/test/Lower/OpenMP/Todo/reduction-subtract.f90 deleted file mode 100644 --- a/flang/test/Lower/OpenMP/Todo/reduction-subtract.f90 +++ /dev/null @@ -1,15 +0,0 @@ -! RUN: %not_todo_cmd bbc -emit-fir -fopenmp -o - %s 2>&1 | FileCheck %s -! RUN: %not_todo_cmd %flang_fc1 -emit-fir -fopenmp -o - %s 2>&1 | FileCheck %s - -! CHECK: not yet implemented: Reduction of some intrinsic operators is not supported -subroutine reduction_subtract - integer :: x - !$omp parallel - !$omp do reduction(-:x) - do i=1, 100 - x = x - i - end do - !$omp end do - !$omp end parallel - print *, x -end subroutine diff --git a/flang/test/Semantics/OpenMP/omp-firstprivate01.f90 b/flang/test/Semantics/OpenMP/omp-firstprivate01.f90 --- a/flang/test/Semantics/OpenMP/omp-firstprivate01.f90 +++ b/flang/test/Semantics/OpenMP/omp-firstprivate01.f90 @@ -42,11 +42,11 @@ !$omp end do !$omp end parallel - !$omp parallel reduction(-:a) + !$omp parallel reduction(*:a) !ERROR: FIRSTPRIVATE variable 'a' is PRIVATE in outer context !$omp do firstprivate(a,b) do i = 1, 10 - c(i) = c(i) - a(i) * b(i) * i + c(i) = c(i) * a(i) * b(i) * i end do !$omp end do !$omp end parallel @@ -59,10 +59,10 @@ !$omp end sections !$omp end parallel - !$omp parallel reduction(-:a) + !$omp parallel reduction(*:a) !ERROR: FIRSTPRIVATE variable 'a' is PRIVATE in outer context !$omp task firstprivate(a,b) - c = c - a * b + c = c * a * b !$omp end task !$omp end parallel diff --git a/flang/test/Semantics/OpenMP/omp-reduction-subtract.f90 b/flang/test/Semantics/OpenMP/omp-reduction-subtract.f90 new file mode 100644 --- /dev/null +++ b/flang/test/Semantics/OpenMP/omp-reduction-subtract.f90 @@ -0,0 +1,13 @@ +! RUN: %python %S/../test_errors.py %s %flang_fc1 -fopenmp +! OpenMP Version 5.2 +! Minus operation is deprecated in reduction + +subroutine reduction_subtract + integer :: x + !ERROR: The minus reduction operator is deprecated since OpenMP 5.2 and is not supported in the REDUCTION clause. + !$omp do reduction(-:x) + do i=1, 100 + x = x - i + end do + !$omp end do +end subroutine diff --git a/flang/test/Semantics/OpenMP/omp-reduction02.f90 b/flang/test/Semantics/OpenMP/omp-reduction02.f90 --- a/flang/test/Semantics/OpenMP/omp-reduction02.f90 +++ b/flang/test/Semantics/OpenMP/omp-reduction02.f90 @@ -8,30 +8,36 @@ integer :: j = 10 !ERROR: 'k' appears in more than one data-sharing clause on the same OpenMP directive - !$omp parallel do reduction(+:k), reduction(-:k) + !$omp parallel do reduction(+:k), reduction(*:k) do i = 1, 10 k = k + 1 + k = k * 3 end do !$omp end parallel do !ERROR: 'k' appears in more than one data-sharing clause on the same OpenMP directive - !$omp parallel do reduction(+:k), reduction(-:j), reduction(+:k) + !$omp parallel do reduction(+:k), reduction(*:j), reduction(+:k) do i = 1, 10 k = k + 1 + j = j * 3 end do !$omp end parallel do !ERROR: 'k' appears in more than one data-sharing clause on the same OpenMP directive - !$omp parallel do reduction(+:j), reduction(-:k), reduction(+:k) + !$omp parallel do reduction(+:j), reduction(*:k), reduction(+:k) do i = 1, 10 + j = j + 1 k = k + 1 + k = k * 3 end do !$omp end parallel do !ERROR: 'k' appears in more than one data-sharing clause on the same OpenMP directive - !$omp parallel do reduction(+:j), reduction(-:k), private(k) + !$omp parallel do reduction(+:j), reduction(*:k), private(k) do i = 1, 10 + j = j + 1 k = k + 1 + k = k * 3 end do !$omp end parallel do end program omp_reduction diff --git a/flang/test/Semantics/OpenMP/omp-reduction04.f90 b/flang/test/Semantics/OpenMP/omp-reduction04.f90 --- a/flang/test/Semantics/OpenMP/omp-reduction04.f90 +++ b/flang/test/Semantics/OpenMP/omp-reduction04.f90 @@ -14,7 +14,7 @@ !$omp end parallel do !ERROR: Variable 'c' on the REDUCTION clause is not definable - !$omp parallel do reduction(-:/c/) + !$omp parallel do reduction(*:/c/) do i = 1, 10 l = k + 1 end do diff --git a/flang/test/Semantics/OpenMP/omp-reduction07.f90 b/flang/test/Semantics/OpenMP/omp-reduction07.f90 --- a/flang/test/Semantics/OpenMP/omp-reduction07.f90 +++ b/flang/test/Semantics/OpenMP/omp-reduction07.f90 @@ -3,7 +3,7 @@ ! 2.15.3.6 Reduction Clause program omp_reduction - integer :: i,j,l + integer :: a,i,j,l integer :: k = 10 !$omp parallel private(k) !ERROR: REDUCTION variable 'k' is PRIVATE in outer context must be shared in the parallel regions to which any of the worksharing regions arising from the worksharing construct bind. @@ -15,7 +15,7 @@ !$omp end parallel - !$omp parallel private(j),reduction(-:k) + !$omp parallel private(j),reduction(+:k) !ERROR: REDUCTION variable 'k' is REDUCTION in outer context must be shared in the parallel regions to which any of the worksharing regions arising from the worksharing construct bind. !$omp do reduction(+:k) do i = 1, 10 @@ -37,9 +37,10 @@ !$omp parallel private(l,j),firstprivate(k) !ERROR: REDUCTION variable 'k' is FIRSTPRIVATE in outer context must be shared in the parallel regions to which any of the worksharing regions arising from the worksharing construct bind. !ERROR: REDUCTION variable 'j' is PRIVATE in outer context must be shared in the parallel regions to which any of the worksharing regions arising from the worksharing construct bind. - !$omp sections reduction(ior:k) reduction(-:j) + !$omp sections reduction(ior:k) reduction(*:j) do i = 1, 10 - k = k + 1 + k = ior(k, 1) + j = j * 3 end do !$omp end sections !$omp end parallel @@ -69,36 +70,36 @@ !$omp parallel reduction(+:a) !ERROR: REDUCTION variable 'a' is REDUCTION in outer context must be shared in the parallel regions to which any of the worksharing regions arising from the worksharing construct bind. -!$omp sections reduction(-:a) -a = 10 +!$omp sections reduction(*:a) +a = a + 10 !$omp end sections !$omp end parallel -!$omp parallel reduction(-:a) +!$omp parallel reduction(*:a) !$omp end parallel !$omp parallel reduction(+:a) !ERROR: REDUCTION clause is not allowed on the WORKSHARE directive !ERROR: REDUCTION variable 'a' is REDUCTION in outer context must be shared in the parallel regions to which any of the worksharing regions arising from the worksharing construct bind. -!$omp workshare reduction(-:a) -a = 10 +!$omp workshare reduction(*:a) +a = a + 10 !$omp end workshare !$omp end parallel -!$omp parallel reduction(-:a) +!$omp parallel reduction(*:a) !$omp end parallel !$omp parallel reduction(+:a) !ERROR: REDUCTION clause is not allowed on the SINGLE directive !ERROR: REDUCTION variable 'a' is REDUCTION in outer context must be shared in the parallel regions to which any of the worksharing regions arising from the worksharing construct bind. -!$omp single reduction(-:a) -a = 10 +!$omp single reduction(*:a) +a = a + 10 !$omp end single !$omp end parallel -!$omp parallel reduction(-:a) +!$omp parallel reduction(+:a) !$omp end parallel @@ -106,7 +107,7 @@ !ERROR: REDUCTION clause is not allowed on the SINGLE directive !ERROR: REDUCTION variable 'a' is REDUCTION in outer context must be shared in the parallel regions to which any of the worksharing regions arising from the worksharing construct bind. !$omp single reduction(iand:a) -a = 10 +a = a + 10 !$omp end single !$omp end parallel @@ -115,8 +116,8 @@ !$omp parallel reduction(ieor:a) !ERROR: REDUCTION variable 'a' is REDUCTION in outer context must be shared in the parallel regions to which any of the worksharing regions arising from the worksharing construct bind. -!$omp sections reduction(-:a) -a = 10 +!$omp sections reduction(+:a) +a = ieor(a, 10) !$omp end sections !$omp end parallel diff --git a/flang/test/Semantics/OpenMP/omp-reduction09.f90 b/flang/test/Semantics/OpenMP/omp-reduction09.f90 --- a/flang/test/Semantics/OpenMP/omp-reduction09.f90 +++ b/flang/test/Semantics/OpenMP/omp-reduction09.f90 @@ -66,7 +66,7 @@ !$omp end do !$omp end parallel - !$omp do reduction(-:k) reduction(*:j) reduction(-:l) + !$omp do reduction(+:k) reduction(*:j) reduction(+:l) !DEF: /omp_reduction/OtherConstruct7/i (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4) do i=1,10 !DEF: /omp_reduction/OtherConstruct7/k (OmpReduction) HostAssoc INTEGER(4)