[all-commits] [llvm/llvm-project] 1fa4a0: [flang][hlfir] Fixed character allocatable in stru...

Slava Zakharin via All-commits all-commits at lists.llvm.org
Thu Jul 13 09:48:33 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 1fa4a0a012511643868b3ab9a4659aa6eae696ca
      https://github.com/llvm/llvm-project/commit/1fa4a0a012511643868b3ab9a4659aa6eae696ca
  Author: Slava Zakharin <szakharin at nvidia.com>
  Date:   2023-07-13 (Thu, 13 Jul 2023)

  Changed paths:
    M flang/include/flang/Optimizer/HLFIR/HLFIROps.td
    M flang/lib/Lower/ConvertExprToHLFIR.cpp
    M flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp
    M flang/lib/Optimizer/HLFIR/Transforms/ConvertToFIR.cpp
    M flang/test/HLFIR/invalid.fir
    M flang/test/Lower/HLFIR/structure-constructor.f90

  Log Message:
  -----------
  [flang][hlfir] Fixed character allocatable in structure constructor.

The problem appeared as a segfault for case like this:
```
type t
character(11), allocatable :: c
end type
character(12), alloctable :: x
type(t) y
y = t(x)
```

The frontend representes `y = t(x)` as `y=t(c=%SET_LENGTH(x,11_8))`.
When 'x' is unallocated the hlfir.set_length lowering results in
segfault. It could probably be handled in hlfir.set_length lowering
by using NULL base for the hlfir.declare depending on the allocation
status of 'x', but I am not sure if !hlfir.expr, in general, is supposed
to represent an expression created from unallocated allocatable.
I believe in Fortran that would mean referencing an unallocated
allocatable, which is not allowed.

I decided to special case `SET_LENGTH` in structure constructor,
so that we use its 'x' operand as the RHS for the assign operation
implying the isAllocatable check for cases when 'x' is allocatable.
This requires setting keep_lhs_length_if_realloc flag for the assign
operation. Note that when the component being intialized has
deferred length the frontend does not produce `SET_LENGTH`.

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




More information about the All-commits mailing list