[flang-commits] [flang] [Flang] Fix crash with parametrized derived types usage (PR #150289)
Carlos Seo via flang-commits
flang-commits at lists.llvm.org
Wed Jul 23 12:14:10 PDT 2025
https://github.com/ceseo created https://github.com/llvm/llvm-project/pull/150289
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
>From 6029e1697c4c6f2543eff91cc999e20eb4c3e8f1 Mon Sep 17 00:00:00 2001
From: Carlos Seo <carlos.seo at linaro.org>
Date: Wed, 23 Jul 2025 18:32:37 +0000
Subject: [PATCH] [Flang] Fix crash with parametrized derived types usage
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
---
flang/lib/Lower/Mangler.cpp | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
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);
More information about the flang-commits
mailing list