This is an archive of the discontinued LLVM Phabricator instance.

[flang] Fix context less NULL() lowering
ClosedPublic

Authored by jeanPerier on Mar 30 2023, 8:46 AM.

Details

Summary

The current context less lowering of NULL is producing invalid code
(can lead to reading outside of allocated memory): it is casting
a simple pointer to a descriptor address.
Later, reads are made to this descriptor. It used to be "OK" when
fir.load of fir.box were no-ops, but this was incorrect, and the
fir.load codegen is known doing a copy, and read the whole descriptor
data, not only the base address.

The previous patch that allowed fir.box<None> allocation, this
code fix this by allocating an actual fir.box<None>.

Note: this is still an overkill way to lower foo(null()). HLFIR
lowering always contextualize NULL() lowering leading to much simpler
code:

%absent = fir.absent fir.box<T>
fir.call @foo(%absent)

Depends on: D147237

Diff Detail

Event Timeline

jeanPerier created this revision.Mar 30 2023, 8:46 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 30 2023, 8:46 AM
jeanPerier requested review of this revision.Mar 30 2023, 8:46 AM
vzakhari accepted this revision.Mar 30 2023, 9:11 AM

LGTM. It looks like D147237 was not pulled into the testing.

This revision is now accepted and ready to land.Mar 30 2023, 9:11 AM
This revision was automatically updated to reflect the committed changes.