[flang-commits] [flang] [flang] Add structure constructor with allocatable component (PR #77845)
via flang-commits
flang-commits at lists.llvm.org
Mon Jan 15 01:37:57 PST 2024
================
@@ -362,8 +363,18 @@ static mlir::Value genStructureComponentInit(
loc, fieldTy, name, recTy,
/*typeParams=*/mlir::ValueRange{} /*TODO*/);
- if (Fortran::semantics::IsAllocatable(sym))
- TODO(loc, "allocatable component in structure constructor");
+ if (Fortran::semantics::IsAllocatable(sym)) {
+ if (Fortran::evaluate::UnwrapExpr<Fortran::evaluate::NullPointer>(expr)) {
----------------
jeanPerier wrote:
Can you turn the logic into
```
if (!Fortran::evaluate::IsNullPointer(expr))
fir::emitFatalError(loc, "constant structure constructor with an allocatable component value that is not NULL");
...
```
here to make it clear that the else case is never supposed to be reached.
Using Fortran::evaluate::IsNullPointer is required here to deal with the NULL(MOLD) case I think since there is not special handling for it (NULL(MOLD) is represented as a typed intrinsic call in evaluate::Expr<T>, and not the untyped Fortran::evaluate::NullPointer node).
```
type t
real, allocatable :: x(:)
end type
real, pointer :: x(:)
type(t) :: some_t = t(null(x))
end
```
https://github.com/llvm/llvm-project/pull/77845
More information about the flang-commits
mailing list