[flang-commits] [flang] [Flang] Fix crash in structure constructor lowering for PDT (PR #183543)
via flang-commits
flang-commits at lists.llvm.org
Thu Feb 26 07:02:15 PST 2026
https://github.com/blazie2004 created https://github.com/llvm/llvm-project/pull/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.
>From 149d33cb9c337e39c18b0b875a99d14a81e85d2a Mon Sep 17 00:00:00 2001
From: Jay Satish Kumar Patel <kumarpat at pe31.hpc.amslabs.hpecorp.net>
Date: Thu, 26 Feb 2026 08:54:37 -0600
Subject: [PATCH] [Flang] Fix crash in structure constructor lowering for PDT
---
flang/lib/Lower/ConvertConstant.cpp | 2 ++
1 file changed, 2 insertions(+)
diff --git a/flang/lib/Lower/ConvertConstant.cpp b/flang/lib/Lower/ConvertConstant.cpp
index c44b9e8a3796b..edb0684ff7f9b 100644
--- a/flang/lib/Lower/ConvertConstant.cpp
+++ b/flang/lib/Lower/ConvertConstant.cpp
@@ -532,6 +532,8 @@ static mlir::Value genInlinedStructureCtorLitImpl(
for (const auto &[sym, expr] : ctor.values()) {
const Fortran::semantics::DerivedTypeSpec *componentParentType =
sym->owner().derivedTypeSpec();
+ if (!componentParentType)
+ componentParentType = &ctor.derivedTypeSpec();
assert(componentParentType && "failed to retrieve component parent type");
if (!res) {
mlir::Type parentType = converter.genType(*componentParentType);
More information about the flang-commits
mailing list