[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:55 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-fir-hlfir
Author: jay0x (blazie2004)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/183543.diff
1 Files Affected:
- (modified) flang/lib/Lower/ConvertConstant.cpp (+2)
``````````diff
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);
``````````
</details>
https://github.com/llvm/llvm-project/pull/183543
More information about the flang-commits
mailing list