[all-commits] [llvm/llvm-project] 04a920: [flang] preserve pointer rank in polymorphic_point...
jeanPerier via All-commits
all-commits at lists.llvm.org
Mon Apr 3 00:21:20 PDT 2023
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 04a920b76acf0a52a3eb957c6331ba81a1173e2a
https://github.com/llvm/llvm-project/commit/04a920b76acf0a52a3eb957c6331ba81a1173e2a
Author: Jean Perier <jperier at nvidia.com>
Date: 2023-04-03 (Mon, 03 Apr 2023)
Changed paths:
M flang/lib/Lower/Bridge.cpp
M flang/lib/Optimizer/Builder/MutableBox.cpp
M flang/test/Lower/pointer-disassociate.f90
Log Message:
-----------
[flang] preserve pointer rank in polymorphic_pointer => NULL()
The current lowering for polymorphic pointer association was not
dealing with NULL in a "context aware" fashion: it was calling the
`PointerAssociate` runtime entry point with a fir.box<none> target.
But the fir.box<none> is a descriptor for a scalar, this lead the
runtime to set the pointer rank to zero, regardless of its actual
rank.
I do not think there is a way to expose this problem with the Fortran
code currently supported by flang, because most further manipulation of
the pointer would either set the rank correctly, or do not rely on the
rank in the runtime descriptor.
However, this is incorrect, and when assumed rank are supported, the
following would have failed:
```
subroutine check_rank(p)
class(*), pointer :: p(..)
p => null()
select rank(p)
rank (1)
print *, "OK"
rank default
print *, "FAILED"
end select
end subroutine
class(*), pointer :: p(:)
p => null()
call check_rank(p)
end
```
Instead, detect NULL() in polymorphic pointer lowering and trigger the
deallocation of the pointer.
Differential Revision: https://reviews.llvm.org/D147317
More information about the All-commits
mailing list