[flang-commits] [flang] [flang] Lower initial values via ConvertConstant instead of the legacy expression lowering (PR #210621)
Eugene Epshteyn via flang-commits
flang-commits at lists.llvm.org
Sun Jul 19 10:28:36 PDT 2026
eugeneepshteyn wrote:
Additional implementation information:
Expose ConvertConstant's folded-constant lowering as a public entry point, `genConstantExprValue`, and use it from ConvertVariable's `genInitializerExprValue`. The initializer forms the front end can deliver here are bounded (a folded Constant<T>, possibly parenthesized, or a constant StructureConstructor):
- Per-kind constant lowering uses evaluate::UnwrapConstantValue<T>, which looks through Parentheses<T>, so a parenthesized scalar constant such as "integer :: i = (42)" is lowered to a plain constant rather than wrapped in a fir.no_reassoc.
- The derived-type overload additionally unwraps `Parentheses<SomeDerived>` and recurses, since a parenthesized structure constructor "(t(7))" is not a `Constant<SomeDerived>` and UnwrapConstantValue cannot see through it.
- The two `emitFatalError` backstops include the offending expression and "in initializer" context.
Because `genConstantExprValue` takes no StatementContext, the now-dead context plumbing is removed from the `genInitializerExprValue` / `genComponentDefaultInit` / `genDefaultInitializerValue` / `genScalarDefaultInitializerValue` chain and its call sites (the cleanupProhibited=true contexts guarded against cleanups that can no longer be attached).
https://github.com/llvm/llvm-project/pull/210621
More information about the flang-commits
mailing list