Skip to content

Commit 01ec74d

Browse files
authored
[flang][OpenMP] Fix copyprivate of procedure pointers (llvm#134292)
Just modify the assert to consider fir::BoxProcType as valid. No other changes are needed. Fixes llvm#131549
1 parent 1847b00 commit 01ec74d

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

flang/lib/Lower/OpenMP/ClauseProcessor.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -695,9 +695,10 @@ void TypeInfo::typeScan(mlir::Type ty) {
695695
} else if (auto pty = mlir::dyn_cast<fir::PointerType>(ty)) {
696696
typeScan(pty.getEleTy());
697697
} else {
698-
// The scan ends when reaching any built-in or record type.
698+
// The scan ends when reaching any built-in, record or boxproc type.
699699
assert(ty.isIntOrIndexOrFloat() || mlir::isa<mlir::ComplexType>(ty) ||
700-
mlir::isa<fir::LogicalType>(ty) || mlir::isa<fir::RecordType>(ty));
700+
mlir::isa<fir::LogicalType>(ty) || mlir::isa<fir::RecordType>(ty) ||
701+
mlir::isa<fir::BoxProcType>(ty));
701702
}
702703
}
703704

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
! Test lowering of COPYPRIVATE with procedure pointers.
2+
! RUN: %flang_fc1 -emit-hlfir -fopenmp -o - %s 2>&1 | FileCheck %s
3+
4+
!CHICK-SAME: %arg0: [[TYPE:!fir.ref<!fir.boxproc<() -> i32>>>]],
5+
6+
!CHECK-LABEL: func.func private @_copy_boxproc_i32_args(
7+
!CHECK-SAME: %arg0: [[TYPE:!fir.ref<!fir.boxproc<\(\) -> i32>>]],
8+
!CHECK-SAME: %arg1: [[TYPE]])
9+
!CHECK: %[[DST:.*]]:2 = hlfir.declare %arg0 {{.*}} : ([[TYPE]]) -> ([[TYPE]], [[TYPE]])
10+
!CHECK: %[[SRC:.*]]:2 = hlfir.declare %arg1 {{.*}} : ([[TYPE]]) -> ([[TYPE]], [[TYPE]])
11+
!CHECK: %[[TEMP:.*]] = fir.load %[[SRC]]#0 : [[TYPE]]
12+
!CHECK: fir.store %[[TEMP]] to %[[DST]]#0 : [[TYPE]]
13+
!CHECK: return
14+
15+
!CHECK-LABEL: func @_QPtest_proc_ptr
16+
!CHECK: omp.parallel
17+
!CHECK: omp.single copyprivate(%{{.*}}#0 -> @_copy_boxproc_i32_args : !fir.ref<!fir.boxproc<() -> i32>>)
18+
subroutine test_proc_ptr()
19+
interface
20+
function sub1() bind(c) result(ret)
21+
use, intrinsic :: iso_c_binding
22+
integer(c_int) :: ret
23+
end function sub1
24+
end interface
25+
26+
procedure(sub1), pointer, save, bind(c) :: ffunptr
27+
!$omp threadprivate(ffunptr)
28+
29+
!$omp parallel
30+
ffunptr => sub1
31+
!$omp single
32+
ffunptr => sub1
33+
!$omp end single copyprivate(ffunptr)
34+
if (ffunptr() /= 1) print *, 'err'
35+
!$omp end parallel
36+
end subroutine
37+
38+
function sub1() bind(c) result(ret)
39+
use, intrinsic::iso_c_binding
40+
integer(c_int) :: ret
41+
ret = 1
42+
end function sub1

0 commit comments

Comments
 (0)