[flang-commits] [flang] 0741209 - [flang][OpenMP] Guard lastprivate	scoping on DO (#157760)
    via flang-commits 
    flang-commits at lists.llvm.org
       
    Mon Sep 15 10:06:46 PDT 2025
    
    
  
Author: Krish Gupta
Date: 2025-09-15T18:06:43+01:00
New Revision: 0741209385ae62fc8c529f807c6f4f9777d94bc3
URL: https://github.com/llvm/llvm-project/commit/0741209385ae62fc8c529f807c6f4f9777d94bc3
DIFF: https://github.com/llvm/llvm-project/commit/0741209385ae62fc8c529f807c6f4f9777d94bc3.diff
LOG: [flang][OpenMP] Guard lastprivate scoping on DO  (#157760)
Add HLFIR FileCheck ensuring `lastprivate(v)` on an `omp do` is realized
as privatization on the inner wsloop and not on the enclosing `omp
parallel`.
This matches OpenMP semantics and prevents regressions.
- No `private(v)` at `omp.parallel`
- `omp.wsloop ... private(...)` present
Unable to reproduce #157035 on current main; this test documents the
expected lowering.
p.s- do refer to
[delayed-privatization](https://lists.llvm.org/pipermail/mlir-commits/2025-January/088206.html?utm_source=chatgpt.com)
<img width="2940" height="1912" alt="image"
src="https://github.com/user-attachments/assets/5c3a0656-fe0a-4bd5-be98-b626a7a719c1"
/>
Added: 
    flang/test/Lower/OpenMP/lastprivate-alloc-scope.f90
Modified: 
    
Removed: 
    
################################################################################
diff  --git a/flang/test/Lower/OpenMP/lastprivate-alloc-scope.f90 b/flang/test/Lower/OpenMP/lastprivate-alloc-scope.f90
new file mode 100644
index 0000000000000..67d885ed5fb7a
--- /dev/null
+++ b/flang/test/Lower/OpenMP/lastprivate-alloc-scope.f90
@@ -0,0 +1,22 @@
+! RUN: %flang_fc1 -fopenmp -emit-hlfir %s -o - | FileCheck %s
+
+program p
+  type y3; integer, allocatable :: x; end type
+  type(y3) :: v
+  integer :: s, n, i
+  s = 1; n = 10
+  allocate(v%x); v%x = 0
+!$omp parallel
+  if (.not. allocated(v%x)) print *, '101', allocated(v%x)
+!$omp do schedule(dynamic) lastprivate(v)
+  do i = s, n
+    v%x = i
+  end do
+!$omp end do
+!$omp end parallel
+end program
+
+! CHECK:      omp.parallel {
+! CHECK-NOT:  private(
+! CHECK:      omp.wsloop
+! CHECK-SAME: private(
        
    
    
More information about the flang-commits
mailing list