[flang-commits] [flang] [flang][OpenMP] Fix copyprivate of procedure pointers (PR #134292)
Leandro Lupori via flang-commits
flang-commits at lists.llvm.org
Thu Apr 3 11:39:59 PDT 2025
https://github.com/luporl created https://github.com/llvm/llvm-project/pull/134292
Just modify the assert to consider fir::BoxProcType as valid. No
other changes are needed.
Fixes #131549
>From de586596a3f6891e4199316ad4d5c5e80a945acf Mon Sep 17 00:00:00 2001
From: Leandro Lupori <leandro.lupori at linaro.org>
Date: Thu, 3 Apr 2025 15:34:56 -0300
Subject: [PATCH] [flang][OpenMP] Fix copyprivate of procedure pointers
Just modify the assert to consider fir::BoxProcType as valid. No
other changes are needed.
Fixes #131549
---
flang/lib/Lower/OpenMP/ClauseProcessor.cpp | 5 +--
flang/test/Lower/OpenMP/copyprivate3.f90 | 42 ++++++++++++++++++++++
2 files changed, 45 insertions(+), 2 deletions(-)
create mode 100644 flang/test/Lower/OpenMP/copyprivate3.f90
diff --git a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
index 12ac6b3285575..46febd33f0ce8 100644
--- a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
+++ b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
@@ -695,9 +695,10 @@ void TypeInfo::typeScan(mlir::Type ty) {
} else if (auto pty = mlir::dyn_cast<fir::PointerType>(ty)) {
typeScan(pty.getEleTy());
} else {
- // The scan ends when reaching any built-in or record type.
+ // The scan ends when reaching any built-in, record or boxproc type.
assert(ty.isIntOrIndexOrFloat() || mlir::isa<mlir::ComplexType>(ty) ||
- mlir::isa<fir::LogicalType>(ty) || mlir::isa<fir::RecordType>(ty));
+ mlir::isa<fir::LogicalType>(ty) || mlir::isa<fir::RecordType>(ty) ||
+ mlir::isa<fir::BoxProcType>(ty));
}
}
diff --git a/flang/test/Lower/OpenMP/copyprivate3.f90 b/flang/test/Lower/OpenMP/copyprivate3.f90
new file mode 100644
index 0000000000000..13926e45f1948
--- /dev/null
+++ b/flang/test/Lower/OpenMP/copyprivate3.f90
@@ -0,0 +1,42 @@
+! Test lowering of COPYPRIVATE with procedure pointers.
+! RUN: %flang_fc1 -emit-hlfir -fopenmp -o - %s 2>&1 | FileCheck %s
+
+!CHICK-SAME: %arg0: [[TYPE:!fir.ref<!fir.boxproc<() -> i32>>>]],
+
+!CHECK-LABEL: func.func private @_copy_boxproc_i32_args(
+!CHECK-SAME: %arg0: [[TYPE:!fir.ref<!fir.boxproc<\(\) -> i32>>]],
+!CHECK-SAME: %arg1: [[TYPE]])
+!CHECK: %[[DST:.*]]:2 = hlfir.declare %arg0 {{.*}} : ([[TYPE]]) -> ([[TYPE]], [[TYPE]])
+!CHECK: %[[SRC:.*]]:2 = hlfir.declare %arg1 {{.*}} : ([[TYPE]]) -> ([[TYPE]], [[TYPE]])
+!CHECK: %[[TEMP:.*]] = fir.load %[[SRC]]#0 : [[TYPE]]
+!CHECK: fir.store %[[TEMP]] to %[[DST]]#0 : [[TYPE]]
+!CHECK: return
+
+!CHECK-LABEL: func @_QPtest_proc_ptr
+!CHECK: omp.parallel
+!CHECK: omp.single copyprivate(%{{.*}}#0 -> @_copy_boxproc_i32_args : !fir.ref<!fir.boxproc<() -> i32>>)
+subroutine test_proc_ptr()
+ interface
+ function sub1() bind(c) result(ret)
+ use, intrinsic :: iso_c_binding
+ integer(c_int) :: ret
+ end function sub1
+ end interface
+
+ procedure(sub1), pointer, save, bind(c) :: ffunptr
+ !$omp threadprivate(ffunptr)
+
+ !$omp parallel
+ ffunptr => sub1
+ !$omp single
+ ffunptr => sub1
+ !$omp end single copyprivate(ffunptr)
+ if (ffunptr() /= 1) print *, 'err'
+ !$omp end parallel
+end subroutine
+
+function sub1() bind(c) result(ret)
+ use, intrinsic::iso_c_binding
+ integer(c_int) :: ret
+ ret = 1
+end function sub1
More information about the flang-commits
mailing list