diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp --- a/flang/lib/Lower/OpenMP.cpp +++ b/flang/lib/Lower/OpenMP.cpp @@ -66,7 +66,9 @@ for (const Fortran::parser::OmpObject &ompObject : ompObjectList.v) { Fortran::semantics::Symbol *sym = getOmpObjectSymbol(ompObject); // Privatization for symbols which are pre-determined (like loop index - // variables) happen separately, for everything else privatize here + // variables) happen separately, for everything else privatize here. + if (sym->test(Fortran::semantics::Symbol::Flag::OmpPreDetermined)) + continue; if constexpr (std::is_same_v) { converter.copyHostAssociateVar(*sym); } else { diff --git a/flang/test/Lower/OpenMP/omp-parallel-private-clause-fixes.f90 b/flang/test/Lower/OpenMP/omp-parallel-private-clause-fixes.f90 new file mode 100644 --- /dev/null +++ b/flang/test/Lower/OpenMP/omp-parallel-private-clause-fixes.f90 @@ -0,0 +1,77 @@ +! This test checks a few bug fixes in the PRIVATE clause lowering + +! RUN: bbc -fopenmp -emit-fir %s -o - | FileCheck %s + +! CHECK-LABEL: multiple_private_fix +! CHECK: %[[VAL_0:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFmultiple_private_fixEi"} +! CHECK: %[[VAL_1:.*]] = fir.alloca i32 {bindc_name = "j", uniq_name = "_QFmultiple_private_fixEj"} +! CHECK: %[[VAL_2:.*]] = fir.alloca i32 {bindc_name = "x", uniq_name = "_QFmultiple_private_fixEx"} +! CHECK: omp.parallel { +! CHECK: %[[PRIV_J:.*]] = fir.alloca i32 {bindc_name = "j", pinned +! CHECK: %[[PRIV_X:.*]] = fir.alloca i32 {bindc_name = "x", pinned +! CHECK: %[[PRIV_I:.*]] = fir.alloca i32 {{{.*}}, pinned +! CHECK: %[[ONE:.*]] = arith.constant 1 : i32 +! CHECK: %[[VAL_3:.*]] = fir.load %[[VAL_4:.*]] : !fir.ref +! CHECK: %[[VAL_5:.*]] = arith.constant 1 : i32 +! CHECK: omp.wsloop for (%[[VAL_6:.*]]) : i32 = (%[[ONE]]) to (%[[VAL_3]]) inclusive step (%[[VAL_5]]) { +! CHECK: fir.store %[[VAL_6]] to %[[PRIV_I]] : !fir.ref +! CHECK: %[[VAL_7:.*]] = arith.constant 1 : i32 +! CHECK: %[[VAL_8:.*]] = fir.convert %[[VAL_7]] : (i32) -> index +! CHECK: %[[VAL_9:.*]] = fir.load %[[VAL_4]] : !fir.ref +! CHECK: %[[VAL_10:.*]] = fir.convert %[[VAL_9]] : (i32) -> index +! CHECK: %[[VAL_11:.*]] = arith.constant 1 : index +! CHECK: %[[VAL_12:.*]] = fir.do_loop %[[VAL_13:.*]] = %[[VAL_8]] to %[[VAL_10]] step %[[VAL_11]] -> index { +! CHECK: %[[VAL_14:.*]] = fir.convert %[[VAL_13]] : (index) -> i32 +! CHECK: fir.store %[[VAL_14]] to %[[PRIV_J]] : !fir.ref +! CHECK: %[[LOAD:.*]] = fir.load %[[PRIV_I]] : !fir.ref +! CHECK: %[[VAL_15:.*]] = fir.load %[[PRIV_J]] : !fir.ref +! CHECK: %[[VAL_16:.*]] = arith.addi %[[LOAD]], %[[VAL_15]] : i32 +! CHECK: fir.store %[[VAL_16]] to %[[PRIV_X]] : !fir.ref +! CHECK: %[[VAL_17:.*]] = arith.addi %[[VAL_13]], %[[VAL_11]] : index +! CHECK: fir.result %[[VAL_17]] : index +! CHECK: } +! CHECK: %[[VAL_18:.*]] = fir.convert %[[VAL_19:.*]] : (index) -> i32 +! CHECK: fir.store %[[VAL_18]] to %[[PRIV_J]] : !fir.ref +! CHECK: omp.yield +! CHECK: } +! CHECK: omp.terminator +! CHECK: } +! CHECK: return +subroutine multiple_private_fix(gama) + integer :: i, j, x, gama +!$OMP PARALLEL DO PRIVATE(j,x) + do i = 1, gama + do j = 1, gama + x = i + j + end do + end do +!$OMP END PARALLEL DO +end subroutine + +! CHECK-LABEL: multiple_private_fix2 +! CHECK: %[[X1:.*]] = fir.alloca i32 {bindc_name = "x", uniq_name = "_QFmultiple_private_fix2Ex"} +! CHECK: omp.parallel { +! CHECK: %[[X2:.*]] = fir.alloca i32 {bindc_name = "x", pinned, uniq_name = "_QFmultiple_private_fix2Ex"} +! CHECK: omp.parallel { +! CHECK: %[[X3:.*]] = fir.alloca i32 {bindc_name = "x", pinned, uniq_name = "_QFmultiple_private_fix2Ex"} +! CHECK: %[[C3:.*]] = arith.constant 1 : i32 +! CHECK: fir.store %[[C3]] to %[[X3]] : !fir.ref +! CHECK: omp.terminator +! CHECK: } +! CHECK: %[[C2:.*]] = arith.constant 1 : i32 +! CHECK: fir.store %[[C2]] to %[[X2]] : !fir.ref +! CHECK: omp.terminator +! CHECK: } +! CHECK: %[[C1:.*]] = arith.constant 1 : i32 +! CHECK: fir.store %[[C1]] to %[[X1]] : !fir.ref +! CHECK: return +subroutine multiple_private_fix2() + integer :: x + !$omp parallel private(x) + !$omp parallel private(x) + x = 1 + !$omp end parallel + x = 1 + !$omp end parallel + x = 1 +end subroutine