[flang-commits] [flang] [Flang] Fix crash with parametrized derived types usage (PR #150289)
via flang-commits
flang-commits at lists.llvm.org
Wed Jul 23 12:14:54 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-fir-hlfir
Author: Carlos Seo (ceseo)
<details>
<summary>Changes</summary>
The current mangleName implementation doesn't take a FoldingContext, which prevents the proper evaluation of expressions containing parameter references to an integer constant. Since parametrized derived types are not yet implemented, the compiler will crash there in some cases (see example in issue #<!-- -->127424).
This is a workaround so that doesn't happen until the feature is properly implemented.
Fixes #<!-- -->127424
---
Full diff: https://github.com/llvm/llvm-project/pull/150289.diff
1 Files Affected:
- (modified) flang/lib/Lower/Mangler.cpp (+12-2)
``````````diff
diff --git a/flang/lib/Lower/Mangler.cpp b/flang/lib/Lower/Mangler.cpp
index 1333e3fe349d1..e1ae86a1b5bb2 100644
--- a/flang/lib/Lower/Mangler.cpp
+++ b/flang/lib/Lower/Mangler.cpp
@@ -224,8 +224,18 @@ std::string Fortran::lower::mangle::mangleName(
assert(paramExpr && "derived type kind param not explicit");
std::optional<int64_t> init =
Fortran::evaluate::ToInt64(paramValue->GetExplicit());
- assert(init && "derived type kind param is not constant");
- kinds.emplace_back(*init);
+ // TODO: put the assertion check back when parametrized derived types
+ // are supported:
+ // assert(init && "derived type kind param is not constant");
+ //
+ // The init parameter above will require a FoldingContext for proper
+ // expression evaluation to an integer constant, otherwise the
+ // compiler may crash here (see example in issue #127424).
+ if (!init) {
+ TODO_NOLOC("parameterized derived types");
+ } else {
+ kinds.emplace_back(*init);
+ }
}
}
return fir::NameUniquer::doType(modules, procs, blockId, symbolName, kinds);
``````````
</details>
https://github.com/llvm/llvm-project/pull/150289
More information about the flang-commits
mailing list