This is an archive of the discontinued LLVM Phabricator instance.

[flang] move ASSOCIATED intrinsic optional TARGET handling
ClosedPublic

Authored by jeanPerier on Mar 30 2023, 5:45 AM.

Details

Summary

ASSOCIATED intrinsic TARGET handling is weird for OPTIONAL, because as
opposed to other intrinsic arguments, OPTIONAL allocatable and pointers
may be absent when passed to it, and a diassociated pointer TARGET is not
the same as when TARGET is not provided. Hence, it needs custom
handling in lowering.

The handling was done late (in genIntrinsicCall, without the semantic
context), and assumed it would be possible to retrieve the optionality
aspects, but this is brittle, and hard to share with HLFIR.
Move it in CustomIntrinsicCall that is intended to deal with these
corner case.

Also avoid using fir.box<None> as the related fir.if result, and used
the correct fir.box/fir.class type for the target: using a fir.box<None>
here is risky since fir.box<None> are now meant for scalar TYPE(*), and
the TARGET may be ranked.

Move the introduction of the fir.box<None> around the runtime (when
assumed rank are supported, these will become !fir.box<!fir.array<..xNone>>).

Diff Detail

Event Timeline

jeanPerier created this revision.Mar 30 2023, 5:45 AM
jeanPerier requested review of this revision.Mar 30 2023, 5:45 AM
vzakhari accepted this revision.Mar 30 2023, 7:44 PM

LGTM

flang/lib/Lower/CustomIntrinsicCall.cpp
281

nit: usually, it would look like /*loadOperand=*/false (with = and without a space before false).

This revision is now accepted and ready to land.Mar 30 2023, 7:44 PM