Skip to content

Conversation

KrxGu
Copy link
Contributor

@KrxGu KrxGu commented Sep 9, 2025

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

image

Copy link

github-actions bot commented Sep 9, 2025

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added flang Flang issues not falling into any other category flang:fir-hlfir flang:openmp labels Sep 9, 2025
@llvmbot
Copy link
Member

llvmbot commented Sep 9, 2025

@llvm/pr-subscribers-flang-fir-hlfir

@llvm/pr-subscribers-flang-openmp

Author: Krish Gupta (KrxGu)

Changes

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.
Fixes #157035.

p.s- do refer to delayed-privatization

<img width="2940" height="1912" alt="image" src="https://github.com/user-attachments/assets/5c3a0656-fe0a-4bd5-be98-b626a7a719c1" />


Full diff: https://github.com/llvm/llvm-project/pull/157760.diff

1 Files Affected:

  • (added) flang/test/Lower/OpenMP/lastprivate-alloc-scope.f90 (+22)
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(

@tblah
Copy link
Contributor

tblah commented Sep 15, 2025

Thank you for contributing this test. Please could you remove the fixes tag for the issue, as I don't think this will resolve it.

Are you sure this case isn't covered in an existing test?

@KrxGu
Copy link
Contributor Author

KrxGu commented Sep 15, 2025

Thank you for contributing this test. Please could you remove the fixes tag for the issue, as I don't think this will resolve it.

Are you sure this case isn't covered in an existing test?

Removed Fixes tag from the PR description, to the best of my knowledge i don't think this test was covered .
P.s- I am new to the org so might have missed something

Copy link
Contributor

@tblah tblah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't see something equivalent in the lowering tests either, and the test does not look like it would be burdensome to maintain. Thanks for your contribution.

Let me know if you need help merging it.

@KrxGu
Copy link
Contributor Author

KrxGu commented Sep 15, 2025

I can't see something equivalent in the lowering tests either, and the test does not look like it would be burdensome to maintain. Thanks for your contribution.

Let me know if you need help merging it.

CI all green , good to merge (i don't have merge rights)

@tblah tblah merged commit 0741209 into llvm:main Sep 15, 2025
9 checks passed
Copy link

@KrxGu Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:fir-hlfir flang:openmp flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants