[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
Tue Aug 4 10:52:26 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]]
----------------
Ritanya-B-Bharadwaj wrote:

fixed it. 

https://github.com/llvm/llvm-project/pull/186765


More information about the flang-commits mailing list