[flang] Fix context less NULL() lowering
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) ``` Differential Revision: https://reviews.llvm.org/D147239
Loading
Please sign in to comment