[flang] Ensure pointer components are always established
authorJean Perier <jperier@nvidia.com>
Tue, 9 May 2023 16:22:55 +0000 (18:22 +0200)
committerJean Perier <jperier@nvidia.com>
Tue, 9 May 2023 16:26:21 +0000 (18:26 +0200)
commitb9031d327929c160293f38b0afbf7facec0f591c
treeaf1f6b6cab13f56e018b0f1615f68d39917d1e59
parent9dec07f44a0615ace09aabc19544d4eed0eff2c4
[flang] Ensure pointer components are always established

Follow up of https://reviews.llvm.org/D149979 for lowering.

In Fortran, it is possible to assign a pointer to another pointer
with an undefined association status.
When using the runtime do to none trivial pointer association, if the
descriptor are garbage, the runtime cannot safely detect that it has
a garbage descriptor, and it cannot safely know the descriptor size
leading to undefined behavior.
Another reason to initialize descriptor of pointers is to record any
non deferred length parameter value.
Hence, although this is not required by Fortran, f18 always initialize
pointers to NULL().
This was already done in lowering for whole pointer object, but not for
pointer components.

This patch uses the related semantics patch that updated
derivedTypeSpe::HasDefaultInitialization to ensure pointer components
of local and global object are always initialized.

It adds tests to ensure that allocation of such derived type uses the
runtime to ensure the storage is initialized, and that structure
constructors are setting the descriptor component to NULL() if no
initial target is given.

Differential Revision: https://reviews.llvm.org/D150180
flang/lib/Lower/ConvertVariable.cpp
flang/test/Lower/call-copy-in-out.f90
flang/test/Lower/pointer-default-init.f90 [new file with mode: 0644]