From da9f890d09e78614da86ce2a14e2e92786038497 Mon Sep 17 00:00:00 2001 From: Kavitha Natarajan Date: Wed, 29 Mar 2023 21:05:42 +0530 Subject: [PATCH] [Flang][OpenMP] Fix crash in MAX intrinsic reduction This patch fixes a crash that appear in an OpenMP MAX intrinsic reduction when the reduction is not expressed using MAX intrinsic function. Updated flang/test/Lower/OpenMP/wsloop-reduction-max.f90 test case with additional way of expressing MAX reduction. Reviewed By: kiranchandramohan Differential Revision: https://reviews.llvm.org/D146967 --- flang/lib/Lower/OpenMP.cpp | 1 + flang/test/Lower/OpenMP/wsloop-reduction-max.f90 | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp index e3b4fb8..5feff7f 100644 --- a/flang/lib/Lower/OpenMP.cpp +++ b/flang/lib/Lower/OpenMP.cpp @@ -2324,6 +2324,7 @@ void Fortran::lower::genOpenMPReduction( // Match the pattern here. mlir::Operation *reductionOp = findReductionChain(loadVal, &reductionVal); + if (reductionOp == nullptr) continue; assert(mlir::isa(reductionOp) && "Selection Op not found in reduction intrinsic"); mlir::Operation *compareOp = diff --git a/flang/test/Lower/OpenMP/wsloop-reduction-max.f90 b/flang/test/Lower/OpenMP/wsloop-reduction-max.f90 index 0db5b7f..44ea054 100644 --- a/flang/test/Lower/OpenMP/wsloop-reduction-max.f90 +++ b/flang/test/Lower/OpenMP/wsloop-reduction-max.f90 @@ -63,4 +63,13 @@ subroutine reduction_max_real(y) !$omp end do !$omp end parallel print *, x + + !$omp parallel + !$omp do reduction(max:x) + do i=1, 100 + if (y(i) .gt. x) x = y(i) + end do + !$omp end do + !$omp end parallel + print *, x end subroutine -- 2.7.4