[Flang] Fix crash in structure constructor lowering for PDT (#183543)
Fixes - [#181278](https://github.com/llvm/llvm-project/issues/181278) This patch fixes a crash in Flang when parsing array constructors like: `[ty0(2)(4)]` The current implementation parses this as a type constructor ty0(2), followed by what appears to be another call (4), instead of rejecting it as invalid syntax. The lowering of` StructureConstructor` attempts to retrieve the parent derived type using `sym->owner().derivedTypeSpec()`, which return `nullptr` for PDT cases and lead to a crash. In` flang/lib/Lower/ConvertConstant.cpp`, a safeguard is being added which ensures that we fall back to the constructor’s derived type specification when the parent type cannot be obtained, preventing the null dereference and eliminating the crash. This change addresses only the immediate crash, proper diagnostic handling for this invalid syntax is still pending and remains as TODO. --------- Co-authored-by: Jay Satish Kumar Patel <kumarpat@pe31.hpc.amslabs.hpecorp.net>
This commit is contained in:
parent
e30f9c1946
commit
874ef0073a
@ -532,6 +532,12 @@ static mlir::Value genInlinedStructureCtorLitImpl(
|
||||
for (const auto &[sym, expr] : ctor.values()) {
|
||||
const Fortran::semantics::DerivedTypeSpec *componentParentType =
|
||||
sym->owner().derivedTypeSpec();
|
||||
// TODO: This is not a complete fix. For some parameterized derived type
|
||||
// component initializations, the component symbol owner does not have a
|
||||
// derived type spec. Falling back to ctor.derivedTypeSpec() avoids the
|
||||
// crash, but may not always represent the correct parent type.
|
||||
if (!componentParentType)
|
||||
TODO(loc, "parameterized derived types");
|
||||
assert(componentParentType && "failed to retrieve component parent type");
|
||||
if (!res) {
|
||||
mlir::Type parentType = converter.genType(*componentParentType);
|
||||
|
||||
18
flang/test/Lower/pdt-struct-constructor-init.f90
Normal file
18
flang/test/Lower/pdt-struct-constructor-init.f90
Normal file
@ -0,0 +1,18 @@
|
||||
! RUN: not bbc -emit-hlfir %s 2>&1 | FileCheck %s
|
||||
|
||||
program main
|
||||
type ty0(k)
|
||||
integer,kind::k
|
||||
integer :: ii
|
||||
end type
|
||||
|
||||
type ty(k,l)
|
||||
integer,kind::k
|
||||
integer,len ::l
|
||||
type(ty0(2)) :: cmp(1) = [ty0(2)(4)]
|
||||
end type
|
||||
|
||||
type(ty(2,4)) :: obj
|
||||
end program
|
||||
|
||||
! CHECK: not yet implemented: parameterized derived types
|
||||
Loading…
x
Reference in New Issue
Block a user