-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[Flang] Fix crash with parametrized derived types usage #150289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@llvm/pr-subscribers-flang-fir-hlfir Author: Carlos Seo (ceseo) ChangesThe 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:
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);
|
tblah
left a comment
There was a problem hiding this 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
Done. If no one objects, I'll push it tomorrow. |
|
/cherry-pick 89e4d9f |
|
/pull-request #151937 |
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)
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