[flang-commits] [flang] [Flang][OpenMP] Fix crash and IR errors for user-defined reduction on allocatable variables (PR #186765)
via flang-commits
flang-commits at lists.llvm.org
Wed Jul 22 12:48:35 PDT 2026
================
@@ -0,0 +1,41 @@
+! An initializer reading omp_orig must init the allocatable private copy from the
+! original element, not a fabricated zero.
+
+! RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=45 %s -o - | FileCheck %s
+
+subroutine test_udr_orig_init()
+ implicit none
+ integer :: i
+ integer, allocatable :: a
+
+ !$omp declare reduction (myinit : integer : omp_out = omp_out + omp_in) &
+ !$omp & initializer (omp_priv = omp_orig)
+
+ allocate(a)
+ a = 7
+
+ !$omp parallel do reduction(myinit : a)
+ do i = 1, 4
+ a = a + i
+ end do
+end subroutine
+
+! CHECK-LABEL: omp.declare_reduction @{{.*}}myinit_byref_box_heap_i32 : !fir.ref<!fir.box<!fir.heap<i32>>>
+! CHECK: init {
+! CHECK: ^bb0(%[[MOLD:.*]]: !fir.ref<!fir.box<!fir.heap<i32>>>, %[[ALLOC:.*]]: !fir.ref<!fir.box<!fir.heap<i32>>>):
+! The original element is read (omp_orig), not replaced by a constant zero.
+! CHECK: %[[MBOX:.*]] = fir.load %[[MOLD]]
----------------
MattPD wrote:
Non-blocking. These init `CHECK` lines verify the mold load but not that its result reaches the private element store, so they would also pass on IR that discards the load and initializes the private to a constant zero, which is the exact regression this test guards against. Capturing the loaded value and checking the element store uses it would pin it. The `real` test has the same gap.
https://github.com/llvm/llvm-project/pull/186765
More information about the flang-commits
mailing list