Skip to content

Commit 5130a4e

Browse files
authored
[flang][OpenMP] Handle pointers and allocatables in clone init (#121824)
InitializeClone(), implemented in #120295, was not handling top level pointers and allocatables correctly. Pointers and unallocated variables must be skipped. This caused some regressions in the Fujitsu testsuite: https://linaro.atlassian.net/browse/LLVM-1488
1 parent 0a58a1c commit 5130a4e

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

flang/lib/Lower/OpenMP/DataSharingProcessor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ void DataSharingProcessor::cloneSymbol(const semantics::Symbol *sym) {
126126
assert(sb);
127127
mlir::Value addr = sb.getAddr();
128128
assert(addr);
129-
return hlfir::mayHaveAllocatableComponent(addr.getType());
129+
return !fir::isPointerType(addr.getType()) &&
130+
hlfir::mayHaveAllocatableComponent(addr.getType());
130131
};
131132

132133
if (needInitClone()) {

flang/runtime/derived.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ RT_API_ATTRS int InitializeClone(const Descriptor &clone,
129129
std::size_t elements{orig.Elements()};
130130
int stat{StatOk};
131131

132+
// Skip pointers and unallocated variables.
133+
if (orig.IsPointer() || !orig.IsAllocated()) {
134+
return stat;
135+
}
132136
// Initialize each data component.
133137
std::size_t components{componentDesc.Elements()};
134138
for (std::size_t i{0}; i < components; ++i) {

flang/test/Lower/OpenMP/derived-type-allocatable.f90

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ module m1
1313

1414
contains
1515

16+
!CHECK-LABEL: omp.private {type = private} @_QMm1Ftest_pointer
17+
!CHECK-NOT: fir.call @_FortranAInitializeClone
18+
!CHECK: omp.yield
19+
1620
!CHECK-LABEL: omp.private {type = private} @_QMm1Ftest_nested
1721
!CHECK: fir.call @_FortranAInitializeClone
1822
!CHECK-NEXT: omp.yield
@@ -91,4 +95,11 @@ subroutine test_nested()
9195
!$omp parallel private(d2)
9296
!$omp end parallel
9397
end subroutine
98+
99+
subroutine test_pointer()
100+
type(x), pointer :: ptr
101+
102+
!$omp parallel private(ptr)
103+
!$omp end parallel
104+
end subroutine
94105
end module

0 commit comments

Comments
 (0)