[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
This commit is contained in:
Leandro Lupori
2025-01-07 14:00:39 -03:00
committed by GitHub
parent 0a58a1c9a2
commit 5130a4ea12
3 changed files with 17 additions and 1 deletions

View File

@@ -126,7 +126,8 @@ void DataSharingProcessor::cloneSymbol(const semantics::Symbol *sym) {
assert(sb);
mlir::Value addr = sb.getAddr();
assert(addr);
return hlfir::mayHaveAllocatableComponent(addr.getType());
return !fir::isPointerType(addr.getType()) &&
hlfir::mayHaveAllocatableComponent(addr.getType());
};
if (needInitClone()) {

View File

@@ -129,6 +129,10 @@ RT_API_ATTRS int InitializeClone(const Descriptor &clone,
std::size_t elements{orig.Elements()};
int stat{StatOk};
// Skip pointers and unallocated variables.
if (orig.IsPointer() || !orig.IsAllocated()) {
return stat;
}
// Initialize each data component.
std::size_t components{componentDesc.Elements()};
for (std::size_t i{0}; i < components; ++i) {

View File

@@ -13,6 +13,10 @@ module m1
contains
!CHECK-LABEL: omp.private {type = private} @_QMm1Ftest_pointer
!CHECK-NOT: fir.call @_FortranAInitializeClone
!CHECK: omp.yield
!CHECK-LABEL: omp.private {type = private} @_QMm1Ftest_nested
!CHECK: fir.call @_FortranAInitializeClone
!CHECK-NEXT: omp.yield
@@ -91,4 +95,11 @@ contains
!$omp parallel private(d2)
!$omp end parallel
end subroutine
subroutine test_pointer()
type(x), pointer :: ptr
!$omp parallel private(ptr)
!$omp end parallel
end subroutine
end module