Skip to content

Conversation

@ceseo
Copy link
Contributor

@ceseo ceseo commented Jul 23, 2025

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

@llvmbot llvmbot added flang Flang issues not falling into any other category flang:fir-hlfir labels Jul 23, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 23, 2025

@llvm/pr-subscribers-flang-fir-hlfir

Author: Carlos Seo (ceseo)

Changes

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 --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);

@ceseo ceseo requested a review from tblah July 30, 2025 22:14
Copy link
Contributor

@tblah tblah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not expert on PDTs but in the absence of any other reviewer, adding a TODO message seems reasonable to me.

Nit: please could you add a lit test for this TODO message.

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 llvm#127424).

This is a workaround so that doesn't happen until the feature is properly
implemented.

Fixes llvm#127424
@ceseo
Copy link
Contributor Author

ceseo commented Aug 1, 2025

Nit: please could you add a lit test for this TODO message.

Done. If no one objects, I'll push it tomorrow.

@ceseo ceseo merged commit 89e4d9f into llvm:main Aug 1, 2025
9 checks passed
@tblah tblah added this to the LLVM 21.x Release milestone Aug 4, 2025
@github-project-automation github-project-automation bot moved this to Needs Triage in LLVM Release Status Aug 4, 2025
@tblah
Copy link
Contributor

tblah commented Aug 4, 2025

/cherry-pick 89e4d9f

@llvmbot
Copy link
Member

llvmbot commented Aug 4, 2025

/pull-request #151937

@llvmbot llvmbot moved this from Needs Triage to Done in LLVM Release Status Aug 4, 2025
tru pushed a commit to llvmbot/llvm-project that referenced this pull request Aug 11, 2025
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 llvm#127424).

This is a workaround so that doesn't happen until the feature is
properly implemented.

Fixes llvm#127424

(cherry picked from commit 89e4d9f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flang:fir-hlfir flang Flang issues not falling into any other category

Projects

Development

Successfully merging this pull request may close these issues.

[Flang] Compilation abnormally terminates when type-param-def-stmt is specified in syntax of a derived-type definition

3 participants