Skip to content

[flang][OpenMP] Treat ClassType as BoxType in COPYPRIVATE #141844

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 29, 2025

Conversation

kparzysz
Copy link
Contributor

This fixes the second problem reported in
#141481

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

llvmbot commented May 28, 2025

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

@llvm/pr-subscribers-flang-openmp

Author: Krzysztof Parzyszek (kparzysz)

Changes

This fixes the second problem reported in
#141481


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

2 Files Affected:

  • (modified) flang/lib/Lower/OpenMP/ClauseProcessor.cpp (+3)
  • (added) flang/test/Lower/OpenMP/copyprivate4.f90 (+18)
diff --git a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
index 885871698c946..afbc77d48cb53 100644
--- a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
+++ b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
@@ -743,6 +743,9 @@ void TypeInfo::typeScan(mlir::Type ty) {
   } else if (auto bty = mlir::dyn_cast<fir::BoxType>(ty)) {
     inBox = true;
     typeScan(bty.getEleTy());
+  } else if (auto cty = mlir::dyn_cast<fir::ClassType>(ty)) {
+    inBox = true;
+    typeScan(cty.getEleTy());
   } else if (auto cty = mlir::dyn_cast<fir::CharacterType>(ty)) {
     charLen = cty.getLen();
   } else if (auto hty = mlir::dyn_cast<fir::HeapType>(ty)) {
diff --git a/flang/test/Lower/OpenMP/copyprivate4.f90 b/flang/test/Lower/OpenMP/copyprivate4.f90
new file mode 100644
index 0000000000000..02fdbc71edc59
--- /dev/null
+++ b/flang/test/Lower/OpenMP/copyprivate4.f90
@@ -0,0 +1,18 @@
+!RUN: %flang_fc1 -emit-hlfir -fopenmp -o - %s 2>&1 | FileCheck %s
+
+!The second testcase from https://github.com/llvm/llvm-project/issues/141481
+
+!Check that we don't crash on this.
+
+!CHECK: omp.single copyprivate(%6#0 -> @_copy_class_ptr_rec__QFf01Tt : !fir.ref<!fir.class<!fir.ptr<!fir.type<_QFf01Tt>>>>) {
+!CHECK:   omp.terminator
+!CHECK: }
+
+subroutine f01
+  type t
+  end type
+  class(t), pointer :: tt
+
+!$omp single copyprivate(tt)
+!$omp end single
+end

Copy link
Contributor

@kiranchandramohan kiranchandramohan left a comment

Choose a reason for hiding this comment

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

LG. Please wait for @luporl

Copy link
Contributor

@luporl luporl left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the fix.

@kparzysz kparzysz merged commit 4811c67 into llvm:main May 29, 2025
11 checks passed
@kparzysz kparzysz deleted the users/kparzysz/copyprivate-polymorphic branch May 29, 2025 19:32
svkeerthy pushed a commit that referenced this pull request May 29, 2025
google-yfyang pushed a commit to google-yfyang/llvm-project that referenced this pull request May 29, 2025
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Jun 3, 2025
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.

4 participants