[all-commits] [llvm/llvm-project] cb3f1e: [flang] Fix context less NULL() lowering

jeanPerier via All-commits all-commits at lists.llvm.org
Fri Mar 31 00:15:29 PDT 2023

  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: cb3f1e2d12c61c650f9871198499f248a19f59d2
  Author: Jean Perier <jperier at nvidia.com>
  Date:   2023-03-31 (Fri, 31 Mar 2023)

  Changed paths:
    M flang/lib/Lower/ConvertExpr.cpp
    M flang/test/Lower/dummy-argument-optional.f90
    M flang/test/Lower/polymorphic.f90

  Log Message:
  [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
%absent = fir.absent fir.box<T>
fir.call @foo(%absent)

Differential Revision: https://reviews.llvm.org/D147239

More information about the All-commits mailing list