[flang] Handle optional TARGET associate in ASSOCIATED runtime
authorJean Perier <jperier@nvidia.com>
Thu, 3 Mar 2022 09:11:19 +0000 (10:11 +0100)
committerJean Perier <jperier@nvidia.com>
Thu, 3 Mar 2022 09:11:35 +0000 (10:11 +0100)
commit392cba8603efc41991613d3b3faaca21fd322500
treed760078fcde3a6d75ae9dee5d2ee368695b62016
parent013160f6e26c840140cfcf0b1e8735a2d04e379e
[flang] Handle optional TARGET associate in ASSOCIATED runtime

The TARGET argument of ASSOCIATED may be dynamically optional, in which
case ASSOCIATED(POINTER, TARGET) is equal to ASSOCIATED(TARGET).

Make the runtime argument a pointer so that it can detect and handle
arguments that are dynamically optional.

Also fix the runtime to check if TARGET base address is not null and if
its element size is not null to match the requirement of ASSOCIATED
regarding TARGET:
- if TARGET is an object: true iff [..] TARGET is not a zerosized storage sequence
- if TARGET is a POINTER: true iff [..] POINTER and TARGET are associated

Not that ASSOCIATED will also returns false if TARGET is an unallocated allocatable.
This is not described in the standard, but is a unanimous behaviour of
existing compilers.

Differential Revision: https://reviews.llvm.org/D120835
flang/include/flang/Runtime/pointer.h
flang/runtime/pointer.cpp