Finalization needs to be done before the terminator. In case
of end program, this was done after it and trigger a verifier error.
This patch fixes this case.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Would it also work to make genFIR(const Fortran::parser::EndProgramStmt &) { genExitRoutine(); } a no-op and centralize dealing with exits in endNewFunction ?
That way, it seems it would not be needed to do any special case (EndSubroutineStmt and the others are all nops I think).
BTW, there is a genExitRoutine call in case of early returns (Fortran::parser::ReturnStmt) here: https://github.com/llvm/llvm-project/blob/main/flang/lib/Lower/Bridge.cpp#L3062
Does it fits with finalizations ?
Approving this fix for now since this is fixing regressions, my suggestion can be revisited/tested in another patch.
Yes it works and make things simpler. I have made a new diff here D143065.
BTW, there is a genExitRoutine call in case of early returns (Fortran::parser::ReturnStmt) here: https://github.com/llvm/llvm-project/blob/main/flang/lib/Lower/Bridge.cpp#L3062
Does it fits with finalizations ?
We need a bridge.fctCtx().finalizeAndKeep(); before generating the return. It's added to the same patch